The Plastik Chicken Company needs a new program to print certain information bas
ID: 3537263 • Letter: T
Question
The Plastik Chicken Company needs a new program to print certain information based on employee data. Write a program that meets the conditions as described below. Make sure that you code includes you name, class, section, date and a brief description as a comment header. Also be sure that your code included comments and it properly formatted.
Part 1:
Prompt the user for the following information for two employees
First Name, Last Name, Street Address, City, State, Zip code and phone number, Pay Rate, and hours worked.
Display the following information for each employee: (Display in a descriptive way using full sentences)
LAST NAME , FIRST NAME , INDEX VALUE OF LAST LETTER OF LAST NAME
CITY, STATE, ZIPCODE
LAST 4 DIGITS of PHONE NUMBER
PAY RATE, HOURS WORKED, TOTAL PAY
Part 2:
Also print the following information based on the condition of the data of one of the employees.
1)
If employees pay rate is less than $5.00 print the message %u2018You need a raise!%u2019, if it is greater than 5.00 but less than $10.00 print %u201CYour pay is about $ PAYRATE dollars%u201D (where PAYRATE is the actual amount but casted as a integer value). If the pay rate is greater than 10.00, print the message %u2018Good Job!%u2019.
2)
Based on the total pay amount, construct your own series of IF/ELSE-IF / ELSE statements (create at least 6 separate statements). You can use information based on one employee, both or in combination. Use the flowing at least once:
-A compound statement (Use && and ||)
-One statement based on the first letter of a first name
-Compare the last names of both employees to see if they are the same
-To see if a string contains a certain letter or substring
The test conditions can be based on any data or subsets of data that have been entered by the user.
Explanation / Answer
package demo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Employee {
public String firstName;
public String lastName;
public String address;
public String city;
public String state;
public int zipCode;
public String phone;
public double payRate;
public int hours;
public void getEmployeeInfo() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter the employee detais.");
System.out.println("First name: ");
this.firstName = br.readLine();
System.out.println("Last name: ");
this.lastName = br.readLine();
System.out.println("Address: ");
this.address = br.readLine();
System.out.println("City: ");
this.city = br.readLine();
System.out.println("State: ");
this.state = br.readLine();
System.out.println("Zip Code: ");
this.zipCode = Integer.parseInt(br.readLine());
System.out.println("Phone number: ");
this.phone = br.readLine();
System.out.println("Pay Rate: ");
this.payRate = Double.parseDouble(br.readLine());
System.out.println("Hours worked: ");
this.hours = Integer.parseInt(br.readLine());
}
public String getFirstName() {
return this.firstName;
}
public String getLastName() {
return this.lastName;
}
public String getAddress() {
return this.address;
}
public String getCity() {
return this.city;
}
public String getState() {
return this.state;
}
public int getZipCode() {
return this.zipCode;
}
public String getPhone() {
return this.phone;
}
public double getPayRate() {
return this.payRate;
}
public int getHours() {
return this.hours;
}
public double getTotalPay() {
return (double)this.hours * this.payRate;
}
public void displayEmployeeInfo() {
System.out.println(" Employee Details for "+this.getFirstName());
System.out.println("Last name: " + this.getLastName()
+ " First name: " + this.getFirstName()
+ " Index value of last letter of last name: "
+ this.getLastName().length());
System.out.println("Last 4 digts of phone number: "
+ this.getPhone().substring(this.getPhone().length() - 4,
this.getPhone().length()));
System.out.println("Pay rate: $" + this.getPayRate()
+ "/hour Hours worked: " + this.getHours()
+ " Total pay: $" + this.getTotalPay());
}
public void getPayMessage() {
if(this.payRate < 5)
System.out.println("You need a raise!");
else if(this.payRate >=5 && this.payRate <=10)
System.out.println("Your pay is about "+(int)this.payRate+" dollars");
else
System.out.println("Good Job!");
}
public void compoundStatements(Employee b) {
System.out.println(" Compound statements of Employee "+this.getFirstName());
if(this.getPayRate()<5 && this.getTotalPay()>300)
System.out.println("You work very hard.");
else
System.out.println("You need to work more.");
char ch = this.getFirstName().charAt(0);
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')
System.out.println("Wow! Your name starts with a vowel.");
else
System.out.println("Your name starts with a consonant.");
if(this.getLastName().equals(b.getLastName()))
System.out.println("Both the employees have the same last name !");
else
System.out.println("Both the employees have different last names.");
if(this.getAddress().contains("ab"))
System.out.println("The address of "+this.getFirstName()+" contains ab");
if(Integer.toString(this.zipCode).contains("12"))
System.out.println("The Zip code of "+this.getFirstName()+" contains 12");
}
public static void main(String args[]) throws IOException {
Employee a = new Employee();
Employee b = new Employee();
a.getEmployeeInfo();
b.getEmployeeInfo();
a.displayEmployeeInfo();
a.getPayMessage();
b.displayEmployeeInfo();
b.getPayMessage();
a.compoundStatements(b);
b.compoundStatements(a);
}
}
/*Output
* Please enter the employee detais.
First name:
hello
Last name:
world
Address:
adsf23rfdd
City:
sdfsdf
State:
mlkmdf
Zip Code:
2342341
Phone number:
234234234
Pay Rate:
7
Hours worked:
40
Please enter the employee detais.
First name:
again
Last name:
abcewfw
Address:
asdfk;234mkl
City:
;lkm;lkm
State:
jasdkf
Zip Code:
12345
Phone number:
3450958484
Pay Rate:
12
Hours worked:
20
Employee Details for hello
Last name: world First name: hello Index value of last letter of last name: 5
Last 4 digts of phone number: 4234
Pay rate: $7.0/hour Hours worked: 40 Total pay: $280.0
Your pay is about 7 dollars
Employee Details for again
Last name: abcewfw First name: again Index value of last letter of last name: 7
Last 4 digts of phone number: 8484
Pay rate: $12.0/hour Hours worked: 20 Total pay: $240.0
Good Job!
Compound statements of Employee hello
You need to work more.
Your name starts with a consonant.
Both the employees have different last names.
Compound statements of Employee again
You need to work more.
Wow! Your name starts with a vowel.
Both the employees have different last names.
The Zip code of again contains 12
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.