import java.text.NumberFormat; public class program2 { public static void main(String[] args) { Customer A = new Customer(10202,"home",67400); Customer B = new Customer(20367,"commercial",3500000); Customer C = new Customer(30581,"commercial",9400000); Customer D = new Customer(40387,"industrial",2300000); Customer E = new Customer(50169,"industrial",8500000); Customer F = new Customer(60123,"industrial",15900000); /* A.Calculate_Amount(); B.Calculate_Amount(); C.Calculate_Amount(); D.Calculate_Amount(); E.Calculate_Amount(); F.Calculate_Amount(); */ //I call Calculate_Amount from Display A.Display(); B.Display(); C.Display(); D.Display(); E.Display(); F.Display(); } // end main } // end class WaterBill class Customer { public Customer() { idNum = 0; custType = ""; gallons = 0; } public Customer(int id,String cust,int gal) { idNum = id; custType = cust; gallons = gal; } public Customer(Customer obj) { idNum = obj.idNum; custType = obj.custType; gallons = obj.gallons; } public int getIdNum() { return idNum; } public String getCustType() { return custType; } public int getGallons() { return gallons; } public double Calculate_Amount() { double amount = 0; int diff = 0; final int FOURMIL = 4000000; final int TENMIL = 10000000; if(custType.equalsIgnoreCase("home")) { amount = (0.0005 * gallons) + 5; } else if(custType.equalsIgnoreCase("commercial")) { if(gallons > FOURMIL) { diff = gallons - FOURMIL; amount = (0.00025 * diff) + 1000; } else { amount = 1000; } } else if(custType.equalsIgnoreCase("industrial")) { if(gallons <= FOURMIL) { amount = 1000; } else if((gallons > FOURMIL)&&(gallons <= TENMIL)) { amount = 2000; } else if(gallons > TENMIL) { diff = gallons - TENMIL; amount = (0.00040 * diff) + 3000; } else {} } else {} return amount; } public void Display() { NumberFormat formatter = NumberFormat.getCurrencyInstance(); formatter.setMaximumFractionDigits(2); formatter.setMinimumFractionDigits(2); NumberFormat numformat = NumberFormat.getNumberInstance(); numformat.setMaximumFractionDigits(0); numformat.setMinimumFractionDigits(0); System.out.println("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="); System.out.println("Customer ID : " + getIdNum()); System.out.println("Customer Type: " + getCustType()); System.out.println("Gallons Used : " + numformat.format(getGallons())); System.out.println("Total Cost : " + formatter.format(Calculate_Amount())); System.out.println("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="); System.out.println(); } private int idNum; private String custType; private int gallons; }