In: Computer Science
NEED DONE IN AN HOUR
File 1 - HotTubLastname.java
The capacity of the hot tub can be calculated by using the following formula:
Capacity in gallons = (Length * Width * Depth) / 1728 * 4.8
| 
 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
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:
