In: Computer Science
Need IN JAVA
Please DO NOT COPY AND PASTE old solutions
WILL UPVOTE
The Babysitters Club Employment Agency has decided to computerize their payroll. A babysitter earns a specific fee per hour until 9:00 PM (while the children are awake and active), a lower rate between 9:00 PM and midnight (after bedtimes and the babysitter can study), and a higher fee after midnight (when babysitting cuts into prime sleeping time).
They maintain two datafiles are one for the employees and one for their data
Personnel data file
employee no.
lastname, firstname
street address
city, state zipcode
hourly rate before 9:00 PM hourly rate between 9:00 PM and midnight hourly rate after midnight
¼
Payroll data file
employee no.
number of days employed
starting time and ending time for each day
¼
Write a program that reads the starting time and ending times (in hours and minutes) for a babysitter and computes the babysitter’s fee. Assume all times are between 6:00 PM and 6:00 AM.
Your output should consist of an alphabetical list (by last name) of each babysitter and their pay.
Be sure to use the structured programming techniques you have learned in prior classes. Namely, use methods and maximize legibility by using proper indentation, spacing, and comments. Do not forget to provide program documentation.
The Data below is the data you should use to do the assignment
Personnel file Data
0001
McGill, Stacey
231 Maple Avenue
Stoneybrook, Connecticut 30122
5.50 4.00 6.00
0002
Spier, Maryann
401 Orange Lane
Stoneybrook, Connecticut 30122
10.00 8.00 15.00
0003
Thomas, Kristy
222 Blossom Blvd.
Stoneybrook, Connecticut 30122
5.00 4.00 6.00
0004
Schafer, Dawn
131 Apple Gardens
Stoneybrook, Connecticut 30122
4.00 3.00 5.00
0005
Pike, Mallory
656 Brook Lane
Stoneybrook, Connecticut 30122
1.75 1.00 1.25
0006
Ramsey, Jessi
545 Greenleaf Street
Stoneybrook, Connecticut 30122
10.00 10.00 10.00
0007
Kishi, Claudia
303 Ginger Blvd.
Stoneybrook, Connecticut 30122
5.00 2.50 7.50
Payroll file data
0001
2
8:00 10:00
9:00 11:30
0002
1
6:00 2:00
0003
2
8:00 10:00
9:00 11:30
0004
3
9:30 1:00
6:00 9:00
7:15 8:15
0005
2
7:00 5:30
6:00 1:45
0006
3
9:30 1:00
7:00 9:00
1:15 3:15
0007
2
7:00 3:30
9:00 1:45
package babysitters_club;
import java.util.stream.Stream;
public class BabySitter {
//To store employee number
private String employee_no;
//To store lastName
private String lastName;
//To store firstName
private String firstName;
//To store street address
private String address;
//To store city
private String city;
//To store state
private String state;
//To store zipcode;
private String zipcode;
//To store number of days employed
private int days;
//To store the timings employed
private String[] hours;
//To store the rates
private String rateChart;
//Constructor to create a new class object with all
the fields populated
public BabySitter(String employee_no, String lastName,
String firstName, String address, String city, String state,
String
zipcode,String rateChart) {
this.employee_no =
employee_no;
this.lastName = lastName;
this.firstName = firstName;
this.address = address;
this.city = city;
this.state = state;
this.zipcode = zipcode;
this.rateChart = rateChart;
}
//Getters and Setters[START]
public String getEmployee_no() {
return employee_no;
}
public void setEmployee_no(String employee_no)
{
this.employee_no =
employee_no;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getZipcode() {
return zipcode;
}
public void setZipcode(String zipcode) {
this.zipcode = zipcode;
}
public int getDays() {
return days;
}
public void setDays(int days) {
this.days = days;
}
public String[] getHours() {
return hours;
}
public void setHours(String[] hours) {
this.hours = hours;
}
public String getRateChart() {
return rateChart;
}
public void setRateChart(String rateChart) {
this.rateChart = rateChart;
}
//Getters and Setters[END]
public double computeFees() {
double startHour = 0,endHour =
0;
String[] temp;
String[] temp_time;
double[] rates;
double hr;
double fees = 0.0;
rates =
Stream.of(rateChart.split("\\s")).mapToDouble(r ->
Double.parseDouble(r)).toArray();
for (String h:this.hours)
{
temp =
h.split("\\s\\s");
temp_time =
temp[0].split(":");
startHour =
Double.parseDouble(temp_time[0]);
startHour = startHour +
Integer.parseInt(temp_time[1])/60.00;
temp_time =
temp[1].split(":");
endHour =
Double.parseDouble(temp_time[0]);
endHour = endHour +
Integer.parseInt(temp_time[1])/60.00;
if (endHour
<= startHour)
endHour = endHour + 12;
if (startHour
< 9 && endHour > 12)
{
hr = 9 - startHour;
//Computing fees before 9 pm
fees = fees + hr * rates[0];
//Computing fees from 9pm to 12 am
fees = fees + 3* rates[1];
//Computing fees after 12 am
fees = fees + (endHour - 12)*rates[2];
}
else
if(startHour < 9 && endHour > 9 && endHour
< 12)
{
hr = 9 - startHour;
//Computing fees before 9 pm
fees = fees + hr * rates[0];
//Computing fees from 9pm to 12 am
fees = fees + (endHour - 9)* rates[1];
}
else
if(startHour < 9 && endHour < 9)
{
hr = endHour - startHour;
//Computing fees before 9 pm
fees = fees + hr * rates[0];
}
}
return fees;
}
}
package babysitters_club;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws
FileNotFoundException {
//Creating two scanners to read two
data files simultaneously
Scanner s1 = new Scanner(new
FileReader("personnel.txt"));
Scanner s2 = new Scanner(new
FileReader("payroll.txt"));
//To store the temporary variables
before creating an object
String
emp_id,f_name,l_name,address,city,state,zipcode,chart;
String[] temp;
//To store the days and index of
Babysitter in babysitter array
int i = 0,days;
//Creating an empty array of seven
babysitter references
BabySitter[] sitter = new
BabySitter[7];
//Reading through the files and extracting the values and creating
the babysitter objects
while(s1.hasNext() ||
s2.hasNext())
{
emp_id =
s1.nextLine();
temp =
s1.nextLine().split(",");
f_name =
temp[0];
l_name =
temp[1];
address =
s1.nextLine();
temp =
s1.nextLine().split(" ");
//To exclude the
comma that comes after city
city =
temp[0].substring(0, temp[0].length() - 1);
state =
temp[1];
zipcode =
temp[2];
chart =
s1.nextLine();
//Ignoring the
first line of the second file as they are same in the first
file
s2.nextLine();
sitter[i] = new
BabySitter(emp_id,l_name,f_name,address,city,state,zipcode,chart);
days =
Integer.parseInt(s2.nextLine());
sitter[i].setDays(days);
temp = new
String[days];
for (int
k=0;k<days;k++)
{
temp[k] = s2.nextLine();
}
sitter[i].setHours(temp);
i++;
}
System.out.println("The pays of
each babysitter in alphabetical order of lastname");
for(int j = sitter.length -1
;j>=0;j--)
{
System.out.println(sitter[j].getFirstName() + " " +
sitter[j].getLastName() + " " + " Pay:- $" + String.format("%.2f",
sitter[j].computeFees()));
}}}