Question

In: Computer Science

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

Solutions

Expert Solution

please refer to below attached photos for clear understanding and implementation of the program :

code :

import java.util.*;
import java.io.*;

class HotTub{
    private String model;
    private String pkge;
    private double length;
    private double width;
    private double depth;
    
    public HotTub(){
        length = 0;
        width = 0;
        depth = 0;
    }
    
    public HotTub(String model , String pkge , double length , double width , double depth){
        this.model = model;
        this.pkge = pkge;
        this.length = length;
        this.width = width;
        this.depth = depth;
    }
    
    public double getCapacity(){
        return (length * width * depth) / 1728 * 4.8;
    }
    
    public double getPrice(){
        double cap = getCapacity();
        double cost_per_gallon = 0;
        if(cap < 350){
            if(pkge.compareTo("basic") == 0){
                cost_per_gallon = 5.00;
            }
            else{
                cost_per_gallon = 6.50;
            }
        }
        else if(cap >= 350 && cap < 500){
            if(pkge.compareTo("basic") == 0){
                cost_per_gallon = 6.00;
            }
            else{
                cost_per_gallon = 8.00;
            }
        }
        else{
            if(pkge.compareTo("basic") == 0){
                cost_per_gallon = 7.50;
            }
            else{
                cost_per_gallon = 10.00;
            }
        }
        
        return cost_per_gallon * cap;
    }
}

public class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        ArrayList<HotTub> hottubs = new ArrayList<HotTub>();
        String choice = "y";
        while(!(choice.compareTo("N") == 0) && !(choice.compareTo("n") == 0)){
            String model;
            String pkge;
            double length;
            double width;
            double depth;
            System.out.print("\nModel : ");
            model = in.nextLine();
            System.out.print("\nPackage (basic / premium) : ");
            pkge = in.nextLine();
            System.out.print("\nLength (min : 60 inches) : ");
            length = in.nextFloat();
            System.out.print("\nWidth  (min : 60 inches) : ");
            width = in.nextFloat();
            System.out.print("\nDepth (min : 30 inches) : ");
            depth = in.nextFloat();
            in.nextLine();
            HotTub tub = new HotTub(model , pkge , length , width , depth);
            hottubs.add(tub);
            System.out.print("Do u wish to Continue : (y/n) : ");
            choice = in.nextLine();
        }
        
        double total_cost = 0;
        for(int i=0;i<hottubs.size();i++){
            HotTub tub = hottubs.get(i);
            System.out.println("Capacity : " + tub.getCapacity() + " , Price : " + tub.getPrice());
            total_cost += tub.getPrice();
        }
        
        System.out.println("Total Price : " + total_cost);
    }
}

Related Solutions

Please use this description to calculate the values requested below (correct to 3 decimal places)... The...
Please use this description to calculate the values requested below (correct to 3 decimal places)... The athletic departments at 10 randomly selected U.S. universities were asked by the Equal Employment Opportunity Commission to state what percentage of their nursing scholarships were presently held by women. The responses were 5, 4, 2, 1, 1, 2, 10, 2, 3, 5. CV (hint: write this as a percentage without the % symbol, not a proportion) p-value for the Anderson-Darling normality test Upper outer...
Problem Description A local veterinarian at The Pet Boutique has asked you to create a program...
Problem Description A local veterinarian at The Pet Boutique has asked you to create a program for her office to create invoices for her patient’s office visits. When a customer brings their pet to the boutique, the clerk gets the Customer’s name, address, phone number and email address, as well as the pets name, pet type, pet age, and pet weight. After the customer sees the Veterinarian, the clerk determines the charges for the services, and medications for the office...
Please use the description below to calculate the values requested below, Answers must be reported correct...
Please use the description below to calculate the values requested below, Answers must be reported correct to 4 decimal places to receive credit. For statistics that cannot be reported, please respond with -99. For statistics with multiple answers, please respond with the lowest value. In the 145 years of the running of the Kentucky Derby, the overall average speed of the horses under all track conditions has been 35.9025mph. Only nine years have been run under sloppy track conditions, including...
Use JAVAfor this program Program Description You work in a local gift shop that is currently...
Use JAVAfor this program Program Description You work in a local gift shop that is currently running a large sale. You have been asked to create a program to calculate the total of a user’s purchases and determine if they qualify for a discount. Use the following steps to create the program: Ask the user the price of the item they wish to purchase. Ask the user the quantity they wish to purchase. Ask the user to enter the name...
IN JAVA your software company has been requested to provide a prototype program performing the simple...
IN JAVA your software company has been requested to provide a prototype program performing the simple statistical evaluations. You will need to implement a main program that reads the values into the array (or you could write another method to read them in), then call each of the various methods that you will convert from your previous programming project. The following methods comprise the StatPackage. The function specifications are as follows: Your StatPackage will accept up to 500 values as...
(Write a program in C++) A local instructor wants you to write a program to calculate...
(Write a program in C++) A local instructor wants you to write a program to calculate the average score made on exams by her students. For simplicity, she always has only 12 students in each course she teaches. She teaches multiple subjects so she would like to enter the name of the exam. She wants the program to also determine the highest and lowest scores and the number of students who passed and failed the exam. A score of 60...
DESCRIPTION Create a program to calculate and print basic stats on a set of a given...
DESCRIPTION Create a program to calculate and print basic stats on a set of a given input values representing students' scores on an exam. 1) Ask the user for the total number of exam scores to be input (assume a positive integer will be given). 2) Create an array to hold all the exam scores and then get all the scores from input to put into the array. For example, if the user input 10 in step (1) then you...
Write a C program that has a local and a global variable. The program uses a...
Write a C program that has a local and a global variable. The program uses a fork to create a child process. The parent process modifies both variables to be 10 and 20 and prints out the values. Then the child process modifies both variables to be 100 and 200 and prints out the values? Explain the program output?
Write a program that will calculate the cost of installing fiber optic cable at a cost...
Write a program that will calculate the cost of installing fiber optic cable at a cost of .87 per ft for a company. Your program should display the company name and the total cost. Display a welcome message for your program. Get the company name from the user Get the number of feet of fiber optic to be installed from the user Multiply the total cost as the number of feet times .87. Display the calculated information and company name.
General Description: Write a program that processes weekly payroll for a small company. The program starts...
General Description: Write a program that processes weekly payroll for a small company. The program starts with printing a logo then asking for the total number of employees for the week. The program then inputs data for each individual employee and prints a paystub. At the end, it prints a report based on data for all employees. Gross Pay: The company has two types of employees: Hourly and Salaried - Hourly employees have an hourly wage, and are paid overtime...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT