import javax.swing.*; public class TankTest { public static void main(String[] args) { String input; double c1 = 6.0; double c2 = 30.0; double totalCost = 0; double totalVol = 0; double totalMass = 0; double totalWeld = 0; // Prompt and read number of tanks, names, volumes from user input = JOptionPane.showInputDialog("Enter number of tanks (1-3)"); int n = Integer.parseInt(input); for (int i = 0; i < n; i++) { String name = JOptionPane.showInputDialog("Enter tank name"); input = JOptionPane.showInputDialog("Enter tank volume(m^3)"); double volume = Double.parseDouble(input); // Create Tank object and set t to refer to the latest tank made Tank t = new Tank(volume, name); // Still in the loop, compute cost, get data members, update totals t.computeCost(c1, c2); System.out.println( "\nTank name: " + t.getTankName() + " \n Volume: " + t.getVolume() + " \n Cost: " + t.getCost() + " \n Radius: " + t.getRadius() + " \n Length: " + t.getLength() + " \n Steel mass: " + t.getMass() + " \n Weld length: " + t.getWeldLen()); totalCost += t.getCost(); totalVol += t.getVolume(); totalMass += t.getMass(); totalWeld += t.getWeldLen(); } // At end of loop, output totals across all tanks System.out.println( "\nTotal cost: " + totalCost + " \n Total volume: " + totalVol + " \n Total mass: " + totalMass + " \n Total weld length: " + totalWeld); System.exit(0); } }