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

This problem is in the looping section of my first Java class. I am having issue

ID: 664715 • Letter: T

Question

This problem is in the looping section of my first Java class. I am having issues with in the babysitting.java class with the math. Everything compiles fine but if your read the question in CreateBabysitting.java their math comes out to $34 for 3 children for 2 hours under greg who gets $9 per hr and $4 per addition child per hr kind of confusing but at any rate my number comes to $39. If you can look into this that would be great.

babysitting.java

______________________________________________________________________________________

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

// l 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.
// l A code representing the employee assigned to the job. Assume that the code will
// always be 1, 2, or 3.
// l A name based on the babysitter code. Georgette has three babysitters: (1) Cindy,
// (2) Greg, and (3) Marcia.
// l The number of children to be watched. Assume that this number is always greater
// than zero.
// l The number of hours in the job. Assume that all hour values are whole numbers.
// l 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.
// 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.

// BabysittingJob class:
// 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.

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

public String sitterName;   
public int empPrice=0;
public int addPrice=0;
public int numChildren;
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)+(costPerChild)+(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);
}
}

_________________________________________________________________________________

CreateBabysitting.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:
// l A four-digit year between 2013 and 2025 inclusive
// l A job number for the year between 1 and 9999 inclusive
// l A babysitter code of 1, 2, or 3
// l A number of children for the job between 1 and 9 inclusive
// l A number of hours between 1 and 12 inclusive

// 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.

// CreateBabysittingJob class:
// Enhance this program so that it asks the user if a child requires diaper changing.

import java.util.Scanner;

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

BabysittingJob customer = new BabysittingJob();
Scanner input = new Scanner(System.in);
//Inital description of babysititng Co.
System.out.println("Welcome to Georgette’s Babysitting Service");
System.out.println("Please take a minute to read through and select the services and specific babysitter for your little angle 0:)");
//while loop for the job code   
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)");
int n = input.nextInt();
if(n>=130000 && n<=250000){
customer.setJobNum(n);
break;
}
else
System.out.print("Error, revise job number instructions and enter the correct job number");
System.out.println();
}
while(true){
System.out.print("Enter the corresponding number for the babysitter of your choice"+
" [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("Error, revise babysitter number instructions and enter the correct babysitter number");
System.out.println();   
}
while(true){
System.out.print("Enter the number of children your wishing to pawn off (max children = 9):"+" ");
int nc = input.nextInt();
if(nc>=1 && nc<=9){
customer.setNumChildren(nc);
break;
}
else
System.out.print("Error, we only can support 9 little terrorists per babysitter");
System.out.println();
}
while(true){
System.out.print("Does this ignant' require diaper changes?"+
" [Enter 1] - For diaper change - additional non-refundable $20 charge per child"+
" [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("Its simple, type 1 or 2...nothing else");
}
while(true){
System.out.print("Enter the number of hours our sitters have to endure this creature?"+
" (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 numbers No decimals Its per hour(round up if you have to)"+
" Lastly hours have to be less than 12");

}
customer.display();
}
}

All I am looking for is help with getting the math part right. The math part is in the babysitting class under numHours and numOfChildren. I am not looking to pay extra money for someone to rewrite the program...the program is close to what its supposed to be, plus I pay chegg already for the question and ANSWER portion of their services.

Explanation / Answer

import java.util.ArrayList; import org.jacop.constraints.Alldifferent; import org.jacop.constraints.XeqY; import org.jacop.constraints.XmulCeqZ; import org.jacop.constraints.XplusCeqZ; import org.jacop.core.IntVar; import org.jacop.core.Store; /** * * It is a simple logic puzzle about babysitting. * * @author Radoslaw Szymanek * * Each weekday, Bonnie takes care of five of the neighbors' * children. The children's names are Keith, Libby, Margo, Nora, and * Otto; last names are Fell, Grant, Hall, Ivey, and Jule. Each is a * different number of years old, from two to six. Can you find each * child's full name and age? * 1. One child is named Libby Jule. * 2. Keith is one year older than the Ivey child, who is one year older than Nora. * 3. The Fell child is three years older than Margo. * 4. Otto is twice as many years old as the Hall child. * Determine: First name - Last name - Age * Given solution : * Keith Fell, five years old * Libby Jule, six years old * Margo Hall, two years old * Nora Grant, three years old * Otto Ivey, four years old * * */ public class BabySitting extends ExampleFD { @Override public void model() { vars = new ArrayList(); store = new Store(); System.out.println("Program to solve Babysitting problem "); // arrays with surnames String[] surnameNames = { "Fell", "Grant", "Hall", "Ivey", "Jule" }; int ifell = 0, /* igrant = 1, */ ihall = 2, iivey = 3, ijule = 4; // arrays with names String[] nameNames = { "Keith", "Libby", "Margo", "Nora", "Otto" }; int ikeith = 0, ilibby = 1, imargo = 2, inora = 3, iotto = 4; // FDV's in the model IntVar surname[] = new IntVar[5]; IntVar name[] = new IntVar[5]; for (int i = 0; i < 5; i++) { // Values encode actual age of the child. surname[i] = new IntVar(store, surnameNames[i], 2, 6); name[i] = new IntVar(store, nameNames[i], 2, 6); vars.add(surname[i]); vars.add(name[i]); } // Each person has to have a different surname and different name. store.impose(new Alldifferent(surname)); store.impose(new Alldifferent(name)); // 1. One child is named Libby Jule. store.impose(new XeqY(name[ilibby], surname[ijule])); // 2. Keith is one year older than the Ivey child..... store.impose(new XplusCeqZ(surname[iivey], 1, name[ikeith])); // ..... who is one year older than Nora. store.impose(new XplusCeqZ(name[inora], 1, surname[iivey])); // 3. The Fell child is three years older than Margo store.impose(new XplusCeqZ(name[imargo], 3, surname[ifell])); // 4. Otto is twice as many years old as the Hall child. store.impose(new XmulCeqZ(surname[ihall], 2, name[iotto])); } /** * It runs the program solving this puzzle. * @param args no arguments are read. */ public static void main(String args[]) { BabySitting example = new BabySitting(); example.model(); if (example.search()) System.out.println("Solution(s) found"); } }
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