In: Computer Science
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
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
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);
    }
}