Question

In: Computer Science

Need IN JAVA Please DO NOT COPY AND PASTE old solutions WILL UPVOTE The Babysitters Club...

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

Solutions

Expert Solution

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()));
       }}}


Related Solutions

Please do not copy and paste an old question's asnwer. Please provide a new answer. Write...
Please do not copy and paste an old question's asnwer. Please provide a new answer. Write a paper (1,500-1,750 words) in which you address the following based on the information provided in the "West Coast Transit Case Study" resource.Use at least two sources as references for this assignment. APA Style. Define the three criteria for evaluating effective team/group work (as stated in the reading this week) and analyze whether the "team" assembled by Bernie Hollis and Pete Denson is effective...
Explain the Need and importance of understanding International Political Economy. (Please do not copy and paste...
Explain the Need and importance of understanding International Political Economy. (Please do not copy and paste from the internet. Would be grateful if you could also include a couple of in-text citations from a journal or a book)
Please do not go to a website and copy and paste a bunch of stuff that...
Please do not go to a website and copy and paste a bunch of stuff that does not answer the question. *ICD 10 PCS* 1. Research and discuss the guidelines that apply to the coding of CABGs, Pacemaker insertions, and also to the Coding of a Debridement.
DO NOT PLAGIARIZE, use outside sources, copy and paste, use other solutions that are on here....
DO NOT PLAGIARIZE, use outside sources, copy and paste, use other solutions that are on here. Please use your own words. How do you use the scientific method in your everyday life. At first this may seem strange, since you don't think that you use the scientific method at all. But by understanding the terms (like hypothesis, prediction, experiment, variables, controls, data gathering, and analysis), you should be able to relate them to something that you do. For example, some...
**Please fill out the chart post at the bottom and please do not copy and paste...
**Please fill out the chart post at the bottom and please do not copy and paste a previous answer that has been used on CHegg. Lehighton Chalk Company manufactures sidewalk chalk, which it sells online by the box at $24 per unit. Lehighton uses an actual costing system, which means that the actual costs of direct material, direct labor, and manufacturing overhead are entered into work-in-process inventory. The actual application rate for manufacturing overhead is computed each year; actual manufacturing...
( i need Unique answer, don't copy and paste, please) (dont' use handwriting, please). (i need...
( i need Unique answer, don't copy and paste, please) (dont' use handwriting, please). (i need references URL Link) General Question ** How to perform logistic regression in SPSS?
( i need Unique answer, don't copy and paste, please) (dont' use handwriting, please) (i need...
( i need Unique answer, don't copy and paste, please) (dont' use handwriting, please) (i need your reference URL Link) 1. Discuss charismatic traits and behaviors of a leader. How a person can manage relationship in workplace? i need more explain ( i need Unique answer, please) *** Please i need Unique answer, if you don't have unique answer don't answer ***
( i need Unique answer, don't copy and paste, please) (dont' use handwriting, please) (i need...
( i need Unique answer, don't copy and paste, please) (dont' use handwriting, please) (i need your reference URL Link) 1. Discuss charismatic traits and behaviors of a leader. How a person can manage relationship in workplace? i need more explain ( i need Unique answer, please) *** Please i need Unique answer, if you don't have unique answer don't answer ***
( i need Unique answer, don't copy and paste, please) (dont' use handwriting, please) (i need...
( i need Unique answer, don't copy and paste, please) (dont' use handwriting, please) (i need your reference URL Link) 1. Discuss charismatic traits and behaviors of a leader. How a person can manage relationship in workplace? i need more explain ( i need Unique answer, please) *** Please i need Unique answer, if you don't have unique answer don't answer ***
In context of Australia ; Please answer in detail and do not copy paste for any...
In context of Australia ; Please answer in detail and do not copy paste for any other source 1)A client has receipts for $50.00 from donations provided to door to door charity collectors. Can the client claim a tax deduction for this amount? Why? 40–50 words 2) A client wants to claim $300 for work-related expenses and says they might not have spent that amount but because it does not need to be substantiated they will still make the claim....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT