Question

Program Description A local company has requested a program to calculate the cost of different hot...

Program Description

A local company has requested a program to calculate the cost of different hot tubs that it sells. Use the following instructions to code the program:

File 1 - HotTubLastname.java

  • Write a class that will hold fields for the following:
    • The model of the hot tub
    • The hot tub’s feature package (can be Basic or Premium)
    • The hot tub’s length (in inches)
    • The hot tub’s width (in inches)
    • The hot tub’s depth (in inches)
  • The class should also contain the following methods:
    • A constructor that doesn’t accept arguments
    • A constructor that accepts arguments for each field.
    • Appropriate accessor and mutator methods (i.e., setters and getters).
    • A method named getCapacity that accepts no arguments and calculates and returns the capacity (in gallons) of the hot tub.

The capacity of the hot tub can be calculated by using the following formula:

Capacity in gallons = (Length * Width * Depth) / 1728 * 4.8

    • A method named getPrice that accepts no arguments and calculates and returns the price of the hot tub based on the following table:

Hot Tub Capacity

Package

Cost Per Gallon

Less than 350 gallons

Basic

$5.00

Less than 350 gallons

Premium

$6.50

350 but not more than 500 gallons

Basic

$6.00

350 but not more than 500 gallons

Premium

$8.00

Over 500 gallons

Basic

$7.50

Over 500 gallons

Premium

$10.00


Price = Cost Per Gallon * Capacity

File 2 - DemoLastname.java

  • Write a program that demonstrates the class and calculates the cost of hot tubs. The program should ask the user for the following:
    • The model of the hot tub
    • The hot tub’s feature package (can be Basic or Premium)
    • The hot tub’s length (in inches). The program should not accept a number less than 60 for the length.
    • The hot tub’s width (in inches). The program should not accept a number less than 60 for the width.
    • The hot tub’s depth (in inches). The program should not accept a number less than 30 for the depth.
  • The program should prompt the user for all the data necessary to fully initialize the objects. IMPORTANT: Store your objects in a container that will automatically expand as objects are added.
  • The program should continue allowing the user to input information until the user indicates to stop (see sample input on page 3). Note: The program should accept lower or upper case responses to this question.
  • After the user indicates that they wish to stop, the program should output the information for each hot tub.
    • The capacity of the hot tub should be formatted to two decimal places.
    • The price of the hot tub should be formatted as currency to two decimal places and include a comma in the thousands place.
  • After the program outputs the information for each hot tub, it should output the total cost of all of the hot tubs.
  • The program should display the input and output as shown in the provided sample output (Note: this includes blank lines).

Sample Input and Output (formatting and spacing should be exactly as shown below)

What is the model of the hot tub? HT Intro Model 4 Person
Is the hot tub package Basic or Premium? Basic
What is the length (in inches) of the hot tub? 60
What is the width (in inches) of the hot tub? 65
What is the depth (in inches) of the hot tub? 30

Do you wish to enter information for another hot tub (Y/N)? Y

What is the model of the hot tub? HT Relaxation 6 Person
Is the hot tub package Basic or Premium? Premium
What is the length (in inches) of the hot tub? 75
What is the width (in inches) of the hot tub? 75
What is the depth (in inches) of the hot tub? 32

Do you wish to enter information for another hot tub (Y/N)? y

What is the model of the hot tub? HT Ultimate 8 person
Is the hot tub package Basic or Premium? Premium
What is the length (in inches) of the hot tub? 100
What is the width (in inches) of the hot tub? 100
What is the depth (in inches) of the hot tub? 36

Do you wish to enter information for another hot tub (Y/N)? N

Model: HT Intro Model 4 Person
Package: Basic
Length: 60 inches
Width: 65 inches
Depth: 30 inches
Capacity: 325.00 gallons
Price: $1,625.00

Model: HT Relaxation 6 Person
Package: Premium
Length: 75 inches
Width: 75 inches
Depth: 32 inches
Capacity: 500.00 gallons
Price: $4,000.00

Model: HT Ultimate 8 person
Package: Premium
Length: 100 inches
Width: 100 inches
Depth: 36 inches
Capacity: 1000.00 gallons
Price: $10,000.00

The total cost of all the hot tubs is: $15,625.00

Homework Answers

Answer #1

Hi,

Please find below code as per yout requirement.

Let me know if you have any doubt/concerns in this answer via comments.

Hope this answer helps you.

Thanks

/********************JAVA CODE**********************/

/***************HotTubLastname.java*******************/

public class HotTubLastname {

   //Instance variable
   private String model;
   private String tubPackage;
   private int length;
   private int width;
   private int depth;

   /**
   * This is default constructor used to construct object by default values
   */
   public HotTubLastname() {

   }

   /**
   * This is parameterized constructor used to construct object by given parameters
   * @param model
   * @param tubPackage
   * @param length
   * @param width
   * @param depth
   */
   public HotTubLastname(String model, String tubPackage, int length, int width, int depth) {
       this.model = model;
       this.tubPackage = tubPackage;
       this.length = length;
       this.width = width;
       this.depth = depth;
   }

   /**
   * @return the model
   */
   public String getModel() {
       return model;
   }

   /**
   * @param model the model to set
   */
   public void setModel(String model) {
       this.model = model;
   }

   /**
   * @return the tubPackage
   */
   public String getTubPackage() {
       return tubPackage;
   }

   /**
   * @param tubPackage the tubPackage to set
   */
   public void setTubPackage(String tubPackage) {
       this.tubPackage = tubPackage;
   }

   /**
   * @return the length
   */
   public int getLength() {
       return length;
   }

   /**
   * @param lenght the length to set
   */
   public void setLength(int length) {
       this.length = length;
   }

   /**
   * @return the width
   */
   public int getWidth() {
       return width;
   }

   /**
   * @param width the width to set
   */
   public void setWidth(int width) {
       this.width = width;
   }

   /**
   * @return the depth
   */
   public int getDepth() {
       return depth;
   }

   /**
   * @param depth the depth to set
   */
   public void setDepth(int depth) {
       this.depth = depth;
   }

   /**
   * This method returns capacity of the tub using length,width and depth
   * @return
   */
   public double getCapacity() {
       return (Double.valueOf(length) * Double.valueOf(width) * Double.valueOf(depth)) / 1728 * 4.8;
   }

   /**
   * This method returns price of the tub on the basis of type and capacity
   * @return
   */
   public double getPrice() {

       double price = 0;
       double capacity = getCapacity();
       String basic = "Basic";
       String premium = "Premium";

       if(capacity < 350) {
           if(getTubPackage().equalsIgnoreCase(basic)) {
               price = capacity * 5.00;
           } else if (getTubPackage().equalsIgnoreCase(premium)) {
               price = capacity * 6.50;
           }
       } else if(capacity >=350 && capacity <500) {
           if(getTubPackage().equalsIgnoreCase(basic)) {
               price = capacity * 6.00;
           } else if (getTubPackage().equalsIgnoreCase(premium)) {
               price = capacity * 8.00;
           }
       } else if(capacity >=500) {
           if(getTubPackage().equalsIgnoreCase(basic)) {
               price = capacity * 7.50;
           } else if (getTubPackage().equalsIgnoreCase(premium)) {
               price = capacity * 10.00;
           }
       }
       return price;
   }

  
  
}

/***************DemoLastname.java*******************/

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Locale;
import java.util.Scanner;

public class DemoLastname {

   public static void main(String[] args) {

       //Scanner is used to ask user input from console
       Scanner sc = new Scanner(System.in);

       //Creating ArrayList of Hot tub to store user entered data for end result
       ArrayList<HotTubLastname> listOfTub = new ArrayList<HotTubLastname>();

       //Decimal format is used to format amount
       DecimalFormat df = new DecimalFormat("#.00");
       //NumberFormat is used to format currency in dollar
       NumberFormat currencyFormatter =
               NumberFormat.getCurrencyInstance(Locale.US);

       //Temporary variables to store data for validation and constructing object
       String packageType = null;
       String modelName = null;
       int length = 0;
       int width = 0;
       int depth = 0;
       double totalCost = 0;
       String basic = "Basic";
       String premium = "Premium";

       while(true) {
           //Getting model from user
           System.out.print("What is the model of the hot tub? ");
           modelName = sc.nextLine();

           //Checking package of Tub if invalid input then continue asking details otherwise breaking from loop
           do {
               System.out.print("Is the hot tub package Basic or Premium? ");
               packageType = sc.nextLine();
               if(!(packageType.equalsIgnoreCase(basic) || packageType.equalsIgnoreCase(premium))) {
                   System.out.println("Invalid Package, can be Basic or Premium");
                   continue;
               } else {
                   break;
               }
           } while(true);

           //Checking length of Tub if invalid input then continue asking details otherwise breaking from loop
           do {
               System.out.print("What is the length (in inches) of the hot tub? ");
               length = Integer.parseInt(sc.nextLine());
               if(length < 60) {
                   System.out.println("Invalid length,Please enter 60 and above.");
               } else {
                   break;
               }
           } while(true);

           //Checking width of Tub if invalid input then continue asking details otherwise breaking from loop
           do {
               System.out.print("What is the width (in inches) of the hot tub? ");
               width = Integer.parseInt(sc.nextLine());
               if(width < 60) {
                   System.out.println("Invalid width,Please enter 60 and above.");
               } else {
                   break;
               }
           } while(true);

           //Checking depth of Tub if invalid input then continue asking details otherwise breaking from loop
           do {
               System.out.print("What is the depth (in inches) of the hot tub? ");
               depth = Integer.parseInt(sc.nextLine());
               if(depth < 30) {
                   System.out.println("Invalid depth,Please enter 30 and above.");
               } else {
                   break;
               }
           } while(true);

           //Creating object of Hot tub by above given input
           HotTubLastname hotTubLastname = new HotTubLastname(modelName, packageType, length, width, depth);
           //Adding object of hot tub to print details later
           listOfTub.add(hotTubLastname);

           //Asking if user wants to continue adding tub or not, If Y then continue otherwise exit from while loop
           System.out.print("Do you wish to enter information for another hot tub (Y/N)? ");
           String decision = sc.nextLine();
           if(decision.equalsIgnoreCase("Y")) {
               continue;
           } else if (decision.equalsIgnoreCase("N")) {
               break;
           } else {
               System.out.println("Invalid input");
               break;
           }

       }

       //Printing individual hot tub details in required format
       for (HotTubLastname hotTubLastname : listOfTub) {
           double price = hotTubLastname.getPrice();
           totalCost+= price;
           String result = "Model: " + hotTubLastname.getModel() + "\n Package: " + hotTubLastname.getTubPackage() + "\n Length:" + hotTubLastname.getLength() + " inches \n Width: "
                   + hotTubLastname.getWidth() + "inches \n Depth: " + hotTubLastname.getDepth() + " inches \n Capacity: "+df.format(hotTubLastname.getCapacity()) + " gallons \n Price: "+currencyFormatter.format(price);

           System.out.println(result);
       }

       //Printing total cost of the hot tubs
       System.out.println("The total cost of all the hot tubs is: "+currencyFormatter.format(totalCost));

   }

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
This is a Java program Program Description You work for a local cell phone company and...
This is a Java program Program Description You work for a local cell phone company and have been asked to write a program to calculate the price of a cell phone data plan being purchased by a customer. The program should do the following tasks: Display a menu of the data plans that are available to be purchased. Read in the user’s selection from the menu.  Input Validation: If the user enters an invalid option, the program should display an error...
I was asked to write a program in CodeBlocks. C++ format. I've written the first half...
I was asked to write a program in CodeBlocks. C++ format. I've written the first half of the code but I am using else and if statements. I feel like the code is too long to do a simple calculation. In CodeBlock when you build and run your code, a new terminal window opens (in windows a new console window) and you can enter your inputs there. It is not like eclipse that you enter your inputs in console view....
Write a Python program named lastNameVolumes that finds the volumes of different 3 D objects such...
Write a Python program named lastNameVolumes that finds the volumes of different 3 D objects such as a cube, sphere, cylinder and cone. In this file there should be four methods defined. Write a method named cubeVolFirstName, which accepts the side of a cube in inches as an argument into the function. The method should calculate the volume of a cube in cubic inches and return the volume. The formula for calculating the volume of a cube is given below....
C++. Write a program that draws a rocket shape on the screen based on user input...
C++. Write a program that draws a rocket shape on the screen based on user input of three values, height, width and stages. The type of box generated (i.e.. a hollow or filled-in) is based on a check for odd or even values input by the user for the box height (or number of rows). Here is the general specification given user input for the height of the box..... Draw a hollow box for each stage if the value for...
Write a Python 3 program called “parse.py” using the template for a Python program that we...
Write a Python 3 program called “parse.py” using the template for a Python program that we covered in this module. Note: Use this mod7.txt input file. Name your output file “output.txt”. Build your program using a main function and at least one other function. Give your input and output file names as command line arguments. Your program will read the input file, and will output the following information to the output file as well as printing it to the screen:...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how the firms resources incompetencies support the given pressures regarding costs and local responsiveness. Describe entry modes have they usually used, and whether they are appropriate for the given strategy. Any key issues in their global strategy? casestudy: Atlanta, June 17, 2014. Sea of Delta employees and their families swarmed between food trucks, amusement park booths, and entertainment venues that were scattered throughout what would...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT