Question

In: Computer Science

NEED DONE IN AN HOUR File 1 - HotTubLastname.java Write a class that will hold fields...

NEED DONE IN AN HOUR

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

HotTubLastname.java file:

package hottub;

// HotTubLastname class
public class HotTubLastname {
    private String model;
    private String featurePackage;
    private Double length;
    private Double width;
    private Double depth;

    // non-parametrized constructor
    public HotTubLastname() {
    }

    // parametrized constructor
    public HotTubLastname(String model, String featurePackage, Double length, Double width, Double depth) {
        this.model = model;
        this.featurePackage = featurePackage;
        this.length = length;
        this.width = width;
        this.depth = depth;
    }

    // getters and setters
    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public String getFeaturePackage() {
        return featurePackage;
    }

    public void setFeaturePackage(String featurePackage) {
        this.featurePackage = featurePackage;
    }

    public Double getLength() {
        return length;
    }

    public void setLength(Double length) {
        this.length = length;
    }

    public Double getWidth() {
        return width;
    }

    public void setWidth(Double width) {
        this.width = width;
    }

    public Double getDepth() {
        return depth;
    }

    public void setDepth(Double depth) {
        this.depth = depth;
    }


    /**
     * Calculate area of the hot tub and return it
     * @return double
     */
    public Double getCapacity(){
        return Math.round(((length * width * depth)/(1728 * 4.8))*100)/100.0;
    }

    /**
     * calculate price of the hot tub and return it
     * @return double
     */
    public Double getPrice(){
        // check if featurePackage equals basic then calculate the price according to their capacity
        if(featurePackage.equalsIgnoreCase("basic")){
            if(getCapacity()<350){
                return getCapacity() * 5;
            }else if(getCapacity() < 500){
                return getCapacity() * 6;
            }else{
                return getCapacity() * 7.5;
            }
        }
        // else featurePackage equals premium so calculate the price according to their capacity
        else{
            if(getCapacity()<350){
                return getCapacity() * 6.5;
            }else if(getCapacity() < 500){
                return getCapacity() * 8;
            }else{
                return getCapacity() * 10;
            }
        }
    }
}

Screenshots of HotTubLastname.java file:

DemoLastname.java file:

package hottub;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class DemoLastname {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        // hotTubLastnames list which stores HotTubLastName
        List<HotTubLastname> hotTubLastnames = new ArrayList<>();

        // taking infinite while loop
        while(true){

            // taking input of model
            System.out.print("The model of the hot tub: ");
            String model = scanner.nextLine();

            // taking input of featurePackage
            System.out.print("The hot tub’s feature package (can be Basic or Premium): ");
            String featurePackage = scanner.nextLine();

            // asks for input of featurePackage until input is valid
            while(!featurePackage.equalsIgnoreCase("basic") && !featurePackage.equalsIgnoreCase("premium")){
                System.out.println("Invalid feature package.");
                System.out.print("The hot tub’s feature package (can be Basic or Premium): ");
                featurePackage = scanner.nextLine();
            }

            // taking input of length
            System.out.print("The hot tub’s length (in inches): ");
            double length = scanner.nextDouble();

            // asks for input of length until input is valid
            while(length<60){
                System.out.println("Invalid length.");
                System.out.print("The hot tub’s length (in inches): ");
                length = scanner.nextDouble();
            }

            // taking input of width
            System.out.print("The hot tub’s width (in inches): ");
            double width = scanner.nextDouble();

            // asks for input of width until input is valid
            while(width<60){
                System.out.println("Invalid width.");
                System.out.print("The hot tub’s width (in inches): ");
                width = scanner.nextDouble();
            }

            // taking input of depth
            System.out.print("The hot tub’s depth (in inches): ");
            double depth = scanner.nextDouble();

            // asks for input of depth until input is valid
            while(depth<30){
                System.out.println("Invalid depth.");
                System.out.print("The hot tub’s width (in inches): ");
                depth = scanner.nextDouble();
            }

            // creating an instance of HotTubLastname
            HotTubLastname hotTubLastname = new HotTubLastname(model, featurePackage, length, width, depth);

            // add hotTubLastname to hotTubLastnames list
            hotTubLastnames.add(hotTubLastname);

            System.out.print("Do you want to add more? y or n: ");
            scanner.nextLine();
            String yesNo = scanner.nextLine();

            // if yesNo equals n then break the while loop
            if(yesNo.equalsIgnoreCase("n")){
                break;
            }
        }
        // print the hot Tub's information
        System.out.println("\nHot Tub's Information\n");
        System.out.println(String.format("%-10s %-10s %-20s %-10s", "Model", "Package", "Capacity", "Price"));
        double totalPrice = 0;

        for(HotTubLastname hotTub : hotTubLastnames){
            // calculate capacity
            double capacity = hotTub.getCapacity();

            // calculate  price
            double price = Math.round(hotTub.getPrice()*100)/100.0;
            // comma separated price
            String formattedPrice = String.format("%,.2f",price);

            // calculate Total price
            totalPrice = totalPrice + price;
            System.out.println(String.format("%-10s %-10s %-20s %-10s", hotTub.getModel(), hotTub.getFeaturePackage(), capacity+" gallons", "$"+formattedPrice));
        }
        // print the total cost
        System.out.println(String.format("\nTotal Cost: $%,.2f",totalPrice));
    }
}





Screenshots of DemoLastname.java file:

Screenshots of Output:


Related Solutions

In class need to define two fields: 1. Integer part of the number - ulong; &...
In class need to define two fields: 1. Integer part of the number - ulong; & fractional part of the number - ushort in C# Using C#, create the following methods: 1. Method for adding two prices (parameters for function is 2 numbers, integer(main currency) and fractional parts(Fractional currency)) 2. Method for adding two prices(parameter is object of same type as your class) 3. Method for adding two prices(parameter is string)
More Object Concepts (Exercise 4) Part A: Open the file BloodData.java that includes fields that hold...
More Object Concepts (Exercise 4) Part A: Open the file BloodData.java that includes fields that hold a blood type (the four blood types are O, A, B, and AB) and an Rh factor (the factors are + and –). Create a default constructor that sets the fields to “O” and “+”, and an overloaded constructor that requires values for both fields. Include get and set methods for each field. Open the file TestBloodData.java and click the Run button to demonstrate...
Create a class named CollegeCourse that includes data fields that hold the department (for example, ENG),...
Create a class named CollegeCourse that includes data fields that hold the department (for example, ENG), the course number (for example, 101), the credits (for example, 3), and the fee for the course (for example, $360). All of the fields are required as arguments to the constructor, except for the fee, which is calculated at $120 per credit hour. Include a display() method that displays the course data. Create a subclass named LabCourse that adds $50 to the course fee....
I need to have this done within 1 hour and a half. Thank YOU!:) 17. Minnesota...
I need to have this done within 1 hour and a half. Thank YOU!:) 17. Minnesota Department of Health wants to test the claim that variability in COVID-19 within Minnesota is greater than 12.75. For this, they took a sample of 25 days data and found that the mean is 215 and standard deviation was 14.17. At alpha=5% what will be the decision?   Question 17 options: Reject H0 at alpha =5% Do not reject H0 at alpha=5% We do not...
Create a class named Lease with fields that hold an apartment tenant’s name, apartment number, monthly...
Create a class named Lease with fields that hold an apartment tenant’s name, apartment number, monthly rent amount, and term of the lease in months. Include a constructor that initializes the name to “XXX”, the apartment number to 0, the rent to 1000, and the term to 12. Also include methods to get and set each of the fields. Include a nonstatic method named addPetFee() that adds $10 to the monthly rent value and calls a static method named explainPetPolicy()...
Implement an Employee class that includes data fields to hold the Employee’s ID number, first name,...
Implement an Employee class that includes data fields to hold the Employee’s ID number, first name, last name, and hourly pay rate (use of string datatype is not allowed). Create an array of five Employee objects. Input the data in the employee array. Write a searchById() function, that ask the user to enter an employee id, if its present, your program should display the employee record, if it isn’t there, simply print the message ”Employee with this ID doesn’t exist”....
Create a class named Lease with fields that hold an apartment tenant’s name, apartment number, monthly...
Create a class named Lease with fields that hold an apartment tenant’s name, apartment number, monthly rent amount, and term of the lease in months. Include a constructor that initializes the name to “XXX”, the apartment number to 0, the rent to 1000, and the term to 12. Also include methods to get and set each of the fields. Include a nonstatic method named addPetFee() that adds $10 to the monthly rent value and calls a static method named explainPetPolicy()...
Introduction to Inheritance (Exercise 1) Write the class named Horse that contains data fields for the...
Introduction to Inheritance (Exercise 1) Write the class named Horse that contains data fields for the name, color, and birth year. Include get and set methods for these fields. Next, finish the subclass named RaceHorse, which contains an additional field that holds the number of races in which the horse has competed and additional methods to get and set the new field. Run the provided DemoHorses application that demonstrates using objects of each class. DemoHorses.java public class DemoHorses { public...
INVENTORY CLASS You need to create an Inventory class containing the private data fields, as well...
INVENTORY CLASS You need to create an Inventory class containing the private data fields, as well as the methods for the Inventory class (object). Be sure your Inventory class defines the private data fields, at least one constructor, accessor and mutator methods, method overloading (to handle the data coming into the Inventory class as either a String and/or int/float), as well as all of the methods (methods to calculate) to manipulate the Inventory class (object). The data fields in the...
I need this done in JAVA. Define a class named Cash. The class contains the following...
I need this done in JAVA. Define a class named Cash. The class contains the following public elements: A Double stored property that contains the amount of money (dollars and cents) described by an object of the class. A read-only, computed property. It calculates and returns the minimum number of U.S. bills and coins that add up to the amount in the stored property.  The return value is an Int array of length 9 that contains (beginning with index 0 of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT