Question 6

Write an application that shows the sum of 1 to n for every n from 1 to 50. That is, the program displays 1 (the sum of 1 alone), 3 (the sum of 1 and 2), 6 (the sum of 1, 2, and 3), 10 (the sum of 1, 2, 3, and 4), and so on. Save the file as EverySum.java.

Question 14

a. Create a class named Purchase. Each Purchase contains an invoice number, amount of sale, and amount of sales tax. Include set methods for the invoice number and sale amount. Within the set() method for the sale amount, calculate the sales tax as 5% of the sale amount. Also include a display method that displays a purchase's details. Save the file as Purchase.java.

b. Create an application that declares a Purchase object and prompts the user for purchase details. When you prompt for an invoice number, do not let the user proceed until a number between 1,000 and 8,000 has been entered. When you prompt for a sale amount, do not proceed until the user has entered a nonnegative value. After a valid Purchase object has been created, display the object's invoice number, sale amount, and sales tax. Save the file as CreatePurchase.java.

Question 15

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.

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.

When all the data entries are valid, construct a job number from the last two digits of the year and 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.

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.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.