JAVA Program Job Tracking System Your assignment is to track the corporate caree
ID: 3559728 • Letter: J
Question
JAVA Program
Job Tracking System
Your assignment is to track the corporate careers of some up-and-coming executives who are
busily changing jobs, and, of course, getting paid.
In this version of the corporate world, people wither belong to a company or are unemployed.
The list of people the program must deal with is not fixed: initially there are none, and new
people may be introduced by the JOIN command. (see below).
An employee's salary is $10000. Unemployment people draw $700 in unemployment
compensation.
Input
1.
From file "company.txt": The company names are listed one per line. There are
at most 20 companies. Company names are at most 10 characters and do not
contain embedded blanks.
2.
From the keyboard: Commands, as listed below. <Person> and <Company> names
are at most 10 characters and do not contain embedded blanks.
JOIN <person> <company>
<person> joins the specified <company>. This may be the first reference
to this person, or he or she may be unemployed. The person does not
currently belong to another company. Remember that when a person joins
a company.
CHANGE <person> <company>
<person> quits his or her job and joins the specified new <company>. You
may assume that the person is currently employed. This command does not
tell you the person's current employer; you have to search the data
structure to find the person.
QUIT <person>
<person> quits his or her job and becomes unemployed. You may assume
that the person is currently employed.
PAYDAY
Each person is paid his or her salary ($5000). (You must keep track of
the amount each person has earned from the start of the program).
EMPLOYEES <company>
The current list of employees should be printed for the specified
<company>. The employees must be printed in order of their name.
UNEMPLOYED
The list of unemployed people should be printed.
DUMP
Print the employees in each company, as specified under the EMPLOYEES
command above, then print the unemployed people. Label the output
appropriately.
END
Stop accepting commands.
----------------------------------------------------------------------------------------------------------------------------
Ouput
After all the commands have been processed, write a list of employees to a file "employee.txt".
The list consists of all the people who have been mentioned in any command and the total
amount of money they have been accumulated.
The following are some sample data"
file Company.txt
Borland
Microsoft
IBM
Intel
Compaq
NEC
Oracle
Commands from keyboard:
JOIN David IBM
JOIN Peter Intel
PAYDAY
CHANGE Peter Microsoft
Explanation / Answer
public class Person {
private String name;
private String company;
private boolean employed;
private int salaryDrawn;
public Person(String name, String company, boolean employed, int salaryDrawn) {
super();
this.name = name;
this.company = company;
this.employed = employed;
this.salaryDrawn = salaryDrawn;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public boolean isEmployed() {
return employed;
}
public void setEmployed(boolean employed) {
this.employed = employed;
}
public int getSalaryDrawn() {
return salaryDrawn;
}
public void setSalaryDrawn(int salaryDrawn) {
this.salaryDrawn = salaryDrawn;
}
}
-------------------------------------------------------------
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class CompanyTest {
static List<String> companies = new ArrayList();
static List<Person> persons = new ArrayList();
public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(new File("companies.txt"));
Scanner inSacnner = new Scanner(System.in);
while (scanner.hasNext()) {
companies.add(scanner.next());
}
for (int i = 0; i < 5; i++) {
persons.add(new Person("person" + (i + 1), null, false, 0));
}
String[] command = null;
do {
System.out.println("Enter a Command");
command = inSacnner.nextLine().split(" ");
if (command[0].equalsIgnoreCase("END")) {
scanner.close();
inSacnner.close();
return;
} else if (command[0].equalsIgnoreCase("JOIN")) {
join(command[1], command[2]);
} else if (command[0].equalsIgnoreCase("CHANGE")) {
change(command[1], command[2]);
} else if (command[0].equalsIgnoreCase("QUIT")) {
quit(command[1]);
} else if (command[0].equalsIgnoreCase("PERDAY")) {
perday();
} else if (command[0].equalsIgnoreCase("EMPLOYEES")) {
employees(command[1]);
} else if (command[0].equalsIgnoreCase("UNEMPLOYED")) {
unemployed();
} else if (command[0].equalsIgnoreCase("DUMP")) {
dump();
} else {
System.out.println("Not a valid command, Please try again ");
}
} while (true);
}
private static void dump() {
System.out.println("Employed Persons");
System.out.println("--------------------");
for (Person p : persons) {
if (p.isEmployed()) {
System.out.println(p.getName() + " " + p.getCompany());
}
}
System.out.println("UnEmployed Persons");
System.out.println("--------------------");
for (Person p : persons) {
if (!p.isEmployed()) {
System.out.println(p.getName());
}
}
}
private static void unemployed() {
System.out.println("Unemployed Persons ");
System.out.println("-------------------------");
for (Person p : persons) {
if (!p.isEmployed()) {
System.out.println(p.getName());
}
}
}
private static void employees(String cname) {
System.out.println("Persons Working in " + cname);
System.out.println("-------------------------------");
for (Person p : persons) {
if (p.getCompany() != null && p.getCompany().equals(cname)) {
System.out.println(p.getName());
}
}
}
private static void perday() {
for (Person p : persons) {
if (p.isEmployed()) {
p.setSalaryDrawn(p.getSalaryDrawn() + 5000);
}
}
System.out.println("per day applied to all employees");
}
private static void quit(String pname) {
for (Person p : persons) {
if (p.getName().equals(pname)) {
p.setCompany(null);
p.setEmployed(false);
System.out.println(pname + " Quit successfully");
}
}
}
private static void change(String pname, String cname) {
if (companies.contains(cname)) {
for (Person p : persons) {
if (p.getName().equals(pname) && p.isEmployed()) {
p.setCompany(cname);
System.out.println(pname +" chnaged to" + cname);
return;
}
}
} else {
System.out.println("Invalid Company: " + cname);
}
}
private static void join(String pname, String cname) {
if (companies.contains(cname)) {
for (Person p : persons) {
if (p.getName().equals(pname)) {
if (!p.isEmployed()) {
p.setCompany(cname);
p.setEmployed(true);
System.out.println(pname + " Joined in " + cname);
} else {
System.out.println("Person is already employed");
}
}
}
} else {
System.out.println("Invalid Company: " + cname);
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.