Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I know I said 4, but I had a surprise question Alright guys, this is kind of a l

ID: 3556400 • Letter: I

Question

I know I said 4, but I had a surprise question

Alright guys, this is kind of a long question, and I have no idea where to begin. I am a little behind, and it is around finals time

Create a BabysittingJob class for Georgette's Babysitting Service. The class contains fields to hold the following:

Create a constructor for the BabysittingJob class that accepts arguments for the job number, babysitter code, number of children, and hours. The constructor determines the babysitter name and fee for the job. Also include a method that displays every BabysittingJob object field.

Part II.

Next, create an application that prompts the user for data for a babysitting job. Keep prompting the user for each of the following values until they are valid:

When all data entries are valid, construct a job number from the last two digits of the year and a four-digit sequential number (which might require leading zeroes). Then construct a BabysittingJob object, and display its values. Save the file as CreatBabysittingJob.java.

Explanation / Answer

Answered as per the question. Please review and rate.

/****************** File BabysittingJob.java ************************/

public class BabysittingJob {

    private int jobNumber;
    private int code;
    private String name;
    private int numChildrenToBeWatched;
    private int numHours;
    private int fee;
    private static String SITTER_NAME_CODE_1 = "Cindy";
    private static String SITTER_NAME_CODE_2 = "Greg";
    private static String SITTER_NAME_CODE_3 = "Marcia";

    public BabysittingJob(int jobNumber, int code, int numChildrenToBeWatched, int numHours) {
        this.jobNumber = jobNumber;
        this.code = code;
        this.numChildrenToBeWatched = numChildrenToBeWatched;
        this.numHours = numHours;

        if (code == 1) {
            name = SITTER_NAME_CODE_1;
            this.fee = 7 * numHours * numChildrenToBeWatched;
        } else if (code == 2) {
            name = SITTER_NAME_CODE_2;
            this.fee = 9 + (4 * (numChildrenToBeWatched - 1));
        } else if (code == 3) {
            name = SITTER_NAME_CODE_3;
            this.fee = 9 + (4 * (numChildrenToBeWatched - 1));
        }

    }

    @Override
    public String toString() {
        String obj = "Job Number : " + jobNumber + " "
                + "Name : " + name + " "
                + "Code : " + code + " "
                + "Number Of Children : " + numChildrenToBeWatched + " "
                + "Number Of Hours : " + numHours + " "
                + "Fee : " + fee;
        return obj;
    }
}

/******************* File CreatBabysittingJob.java *****************/
import java.util.Scanner;

public class CreatBabysittingJob {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int year, jobnum, code, numchildren, numhours;
        int jobnum_constructed;
        year = readInRange(input, 2013, 2025, "Please Enter four-digit year between 2013 and 2025 inclusive.");
        jobnum = readInRange(input, 1, 9999, "Please Enter job number for the year between 1 and 9999 inclusive.");
        code = readInRange(input, 1, 3, "Please Enter A babysitter code of 1,2, or 3");
        numchildren = readInRange(input, 1, 9, "Please Enter A number of children for the job between 1 and 9 inclusive");
        numhours = readInRange(input, 1, 12, "A number of hours between 1 and 12 inclusive");

        // For the first job in 2014 it will be 140000 + 0 +0 + 0 +1
        jobnum_constructed = ((year % 2000) * 10000) + ((jobnum / 1000) * 1000) + ((jobnum / 100) * 100) + ((jobnum / 10) * 10) + (jobnum % 10);

        BabysittingJob babysittingJob = new BabysittingJob(jobnum_constructed, code, numchildren, numhours);

        System.out.println(babysittingJob);
    }

    private static int readInRange(Scanner sc, int min, int max, String promptString) {
        int read;
        while (true) {
            System.out.println(promptString);
            if (sc.hasNextInt()) {
                read = sc.nextInt();
                if (read >= min && read <= max) {
                    return read;
                }
            }
        }

    }
}