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

I can\'t figure out where I am loosing a child in the math on this program. If I

ID: 3661452 • Letter: I

Question

I can't figure out where I am loosing a child in the math on this program. If I enter 3 children, it initially assigns nc = 3, but by time it gets around to printing the # of children in the BabysittingJob.java, it losses one and prints 2. Also, if the user selects option 1 for needing diapers changed, it initially assigns the value 1 to "dc" in CreateBabysittingJob.java but again, by time it gets to the end of BabysittingJob.java to print the selection for Diaper Charges, it's printing $0. Is anyone able to help with where I'm going wrong on this? I tried the recommended fix on the previous post and still gettting same result.

______________________________________________________________________________________________________

Requirements for program:

Create a BabysittingJob class for Georgette’s Babysitting Service. The class contains fields to hold the following:
* A job number that contains six digits. The first two digits represent the year, and the last four digits represent a sequential number. For example, the first job in 2014 has a job number of 140001.
* A code representing the employee assigned to the job. Assume that the code will always be 1, 2, or 3.
* A name based on the babysitter code. Georgette has three babysitters: (1) Cindy, (2) Greg, and (3) Marcia.
* The number of children to be watched. Assume that this number is always greater than zero.
* The number of hours in the job. Assume that all hour values are whole numbers.
* The fee for the job. Cindy is paid $7 per hour per child. Greg and Marcia are paid $9 an hour for the first child, and $4 per additional hour for each additional child.

For example, if Greg watches three children for two hours, he makes $17 per hour for two hours, or $34.

* Add a Boolean variable that stores whether a child requires diaper changing.

* Enhance the constructor so that this value is received and the price is increased by $20 if a child requires diaper changing.

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. Save the file as BabysittingJob.java.

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:
* A four-digit year between 2013 and 2025 inclusive
* A job number for the year between 1 and 9999 inclusive
* A babysitter code of 1, 2, or 3

* A number of children for the job between 1 and 9 inclusive
* A number of hours between 1 and 12 inclusive

* Enhance this program so that it asks the user if a child requires diaper changing.


When all the 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 CreateBabysittingJob.java.

___________________________________________________________________________________________________

public class BabysittingJob
{
   public int jobNum;
   public int empNum;

   public String sitterName;
   public int empPrice = 0;
   public int addPrice = 0;
   public int numChildren = 0;
   public int costPerChild = 0;
   public int numHours;
   public int costPerHr;
   public double jobCost;
   public int diaperCharge;
   public int charge = 0;
  
   public void setJobNum(int n)
   {
      jobNum = n;
   }

   public void setEmpNum(int e)
   {
      empNum = e;
      if(e == 1)
      {
         sitterName = "Cindy";
         empPrice=7;
         addPrice=7;
      }
         else if(e==2)
         {
            sitterName = "Greg";
            empPrice=9;
            addPrice=4;
         }
               else if(e==3)
               {  
                  sitterName = "Marcia";
                  empPrice=9;
                  addPrice=4;
               }

   }

   public void setNumChildren(int nc)
   {
      numChildren = nc;
      if(nc == 1)
      {
         costPerChild = empPrice;
      }
      else
         costPerChild = empPrice +((nc-1) * addPrice);

   }

   public void setNumHours(int nh)
   {
      numHours = nh;
      if(nh==1)
      {
         costPerHr = empPrice;
      }
      else
         costPerHr = (costPerChild)*(nh);
   }

   public void setDiaperCharge(int dc)
   {
      diaperCharge = dc;
      if(dc == 1)
      {
         charge = (20 * (numChildren));
      }
      else
         charge = 0;
   }

   public void display()
   {
      int totalCost = (costPerHr)+(charge);
      System.out.println("Your job #: " + jobNum);
      System.out.println("Employee #: " + empNum);
      System.out.println("Your Babysitters is: " + sitterName);
      System.out.println("Number of children visiting today: " + numChildren);
      System.out.println("Hours of babysitting: " + numHours);
      System.out.println("Diaper Charges: $" + charge);
      System.out.println("Babysitting Total: $" + totalCost);
   }
}

____________________________________________________________________________________________

import java.util.Scanner;

public class CreateBabysittingJob
{
   public static void main(String[]args)
   {

      BabysittingJob customer = new BabysittingJob();
      Scanner input = new Scanner(System.in);

      System.out.println("Welcome to Georgette’s Babysitting Service");

      while(true)
      {
         System.out.println("Enter a 6 digit job number: 1) First 2 digits are the last 2 digits of current year"
            +" 2) Last 4 digits are the item number (Item # has to be between 0 and 9,999)"
            +" Example: Item # 1000 in year 2015 would be typed as 151000");
         int n = input.nextInt();

         if(n >= 150000&& n <= 250000)
         {
            customer.setJobNum(n);
            break;
          }
         else
            System.out.print("Invalid job # entered. Please read the directions and enter a valid job number:");
            System.out.println();
      }

      while(true)
      {
         System.out.print("Enter the number for the babysitter you which to watch your child:"+
            " [enter 1] Cindy - $7 per hour, per child"+
            " [enter 2] Greg - $9 per hour for the first child, and $4 per additional hour for each additional child"+
            " [enter 3] Marcia - $9 per hour for the first child, and $4 per additional hour for each additional child"+" ");
          int e = input.nextInt();

          if(e >= 1&& e <= 3)
          {
             customer.setEmpNum(e);
             break;
           }
           else
              System.out.print("Invalid babysitter # entered. Please read the directions and enter a valid babysitter number:");
              System.out.println();
      }

      while(true)
      {
         System.out.print("Enter the number of children you will be dropping off. (max children = 9): " + " ");
         int nc = input.nextInt();

         if(nc >= 1&& nc <= 9)
         {
            customer.setNumChildren(nc);
            break;
         }
         else
            System.out.print("Invalid # of children. Maxiumum is 9. Please re-enter the number of children to be dropped off: ");
            System.out.println();

      }

      while(true)
      {
         System.out.print("Do any of the children require diaper changes?" +
            " [Enter 1] - For diaper change - additional non-refundable $20 charge." +
            " [Enter 2] - No additional charge proceed to hrs" + " ");
          int dc = input.nextInt();

         if(dc == 1 || dc == 2)
         {
             customer.setNumChildren(dc);
             break;
         }
         else
            System.out.print("Invalid response, type 1 or 2 for your selection.");
      }

      while(true)
      {
         System.out.print("How many hours will you need child care per day? " +
            " Please enter time in whole hours, no minutes. " +
            " (min: 1 hr per day)" +
            " (max: 12 hr per day)" + " ");
         int nh = input.nextInt();

         if(nh >= 1&& nh <= 12)
         {
            customer.setNumHours(nh);
            break;
         }
         else
            System.out.print("Sorry only whole hours between 1 and 12.");
      }

      customer.display();
   }
}

Explanation / Answer

There is a small correction in the file "CreateBabysittingJob.java".

While taking input from user regarding diaper change, by mistake you are calling setNumChildren method. Change it to setDiaperCharge method.

Code snippet written by you:

while(true)
{
System.out.print("Do any of the children require diaper changes?" +
" [Enter 1] - For diaper change - additional non-refundable $20 charge." +
" [Enter 2] - No additional charge proceed to hrs" + " ");
int dc = input.nextInt();

if(dc == 1 || dc == 2)
{
customer.setNumChildren
(dc); // Requires change here
break;
}
else
System.out.print("Invalid response, type 1 or 2 for your selection.");
}

Modify the code as:

while(true)
{
System.out.print("Do any of the children require diaper changes?" +
" [Enter 1] - For diaper change - additional non-refundable $20 charge." +
" [Enter 2] - No additional charge proceed to hrs" + " ");
int dc = input.nextInt();

if(dc == 1 || dc == 2)
{
customer.setDiaperCharge(dc); // Modify this line
break;
}
else
System.out.print("Invalid response, type 1 or 2 for your selection.");
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote