Question
Hi, I need to convert the following code I have to allow for user input, as well as swap it to GUI/JOptionPane. See the bottom
Hi,
I need to convert the following code I have to allow for user input, as well as swap it to GUI/JOptionPane.
See the bottom of the document for specific photo instructions,
public class Package { private double weight; private char method; private double cost; public Package(double weight, char method) { super(); this.weight = weight; this.method = method; } public void calculateCost(){ this.cost = 0; if(weight >= 1 && weight = 9 && weight = 17 ) { if(method == 'A') { cost = 4.5; } else if(method == 'T') { cost = 2.35; } else if(method == 'M') { cost = 2.15; } }
} public void display() { System.out.println("The weight: " + weight + " (oz) Method: " + method + " Cost: " + cost); } public double getWeight() { return weight; } public void setWeight(double weight) { this.weight = weight; } public char getMethod() { return method; } public void setMethod(char method) { this.method = method; } public double getCost() { return cost; } public void setCost(double cost) { this.cost = cost; } }
public class InsuredPackage extends Package { private double insuranceCost; public InsuredPackage(double weight, char method) { super(weight, method); } public void calculateInsuranceCost() { calculateCost(); double shippingCost = getCost(); if(shippingCost >=0 && shippingCost=1.01 && shippingCost
public class PackageDemo { public static void main(String[] args) { Package package1 = new Package(2.1, 'A'); Package package2 = new Package(9.4, 'T'); Package package3 = new Package(17.8, 'M'); package1.calculateCost(); package2.calculateCost(); package3.calculateCost(); package1.display(); package2.display(); package3.display(); InsuredPackage insuredPackage1 = new InsuredPackage(2.2, 'A'); InsuredPackage insuredPackage2 = new InsuredPackage(9.7, 'T'); InsuredPackage insuredPackage3 = new InsuredPackage(18.9, 'M'); insuredPackage1.calculateInsuranceCost(); insuredPackage2.calculateInsuranceCost(); insuredPackage3.calculateInsuranceCost(); insuredPackage1.display(); insuredPackage1.display(); insuredPackage1.display(); } }
In our fourth lab of the semester we will create a Java application that uses GUI input (use JOptionPane) which enables a shipping company enter package information in order to output final shipping cost for a single package The shipping clerk (our user in this application) can can choose t ship a package by air, truck or mail, as well as insure the package or not insure the package. Depending on the clerk's choices combined with package weight, total cost of shipping will vary 1 also need to handle potential exceptions such as entering a string when an integer is expected, etc Lab Parameters We will use Exercise 7 on pages 531-532 of the textbook as our starting point. Do use the table values for shipping rates and insurance costs in your application. Make sure to get the customer's name as well. This is not discussed in the exercise You should also add specific Exception handling to your application as you deem appropriate. For example, if the application is expecting a number for the weight and the shipping clerk enters nothing or "heavy" you application should be able to recover However, do not automatically instantiate objects as the exercise directs.Instead allow the shipping clerk (our user) to set the parameters in terms of customer name, package weight, shipping method and whether to add insurance. Use the select parameters to determine from which superclass or subclass to instantiate your object In our fourth lab of the semester we will create a Java application that uses GUI input (use JOptionPane) which enables a shipping company enter package information in order to output final shipping cost for a single package The shipping clerk (our user in this application) can can choose t ship a package by air, truck or mail, as well as insure the package or not insure the package. Depending on the clerk's choices combined with package weight, total cost of shipping will vary 1 also need to handle potential exceptions such as entering a string when an integer is expected, etc Lab Parameters We will use Exercise 7 on pages 531-532 of the textbook as our starting point. Do use the table values for shipping rates and insurance costs in your application. Make sure to get the customer's name as well. This is not discussed in the exercise You should also add specific Exception handling to your application as you deem appropriate. For example, if the application is expecting a number for the weight and the shipping clerk enters nothing or "heavy" you application should be able to recover However, do not automatically instantiate objects as the exercise directs.Instead allow the shipping clerk (our user) to set the parameters in terms of customer name, package weight, shipping method and whether to add insurance. Use the select parameters to determine from which superclass or subclass to instantiate your object
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started