Question: Given the following blocks of Java code, add class headers, method headers and comments that provide a brief description of what each does. public class

Given the following blocks of Java code, add class headers, method headers and comments that provide a brief description of what each does.

public class Package { private int weight; private char method; private double cost; final char AIR = 'A'; final char TRUCK = 'T'; final int LOWWT = 9; final double LOWAIR = 2.00; final double LOWTRUCK = 1.50; final double LOWMAIL = 0.50; final int MEDWT = 17; final double MEDAIR = 3.00; final double MEDTRUCK = 2.35; final double MEDMAIL = 1.50; final double HIGHAIR = 4.50; final double HIGHTRUCK = 3.25; final double HIGHMAIL = 2.15; public Package(int w, char m) { weight = w; method = m; cost = calculateCost(w, m); }

private double calculateCost(int w, char m) { double c; if(w < LOWWT) { if(m == AIR) c = LOWAIR; else if(m == TRUCK) c = LOWTRUCK; else c = LOWMAIL; } else if(w < MEDWT) { if(m == AIR) c = MEDAIR; else if(m == TRUCK) c = MEDTRUCK; else c = MEDMAIL; } else { if(m == AIR) c = HIGHAIR; else if(m == TRUCK) c = HIGHTRUCK; else c = HIGHMAIL; } return c; }

public void display() //money format// { System.out.println("The package weighs " + weight + " pounds. Ship method " + method + "Cost $" + cost); } public double getCost() //get cost method// { return cost; } public void increaseCost(double c) { cost = cost + c; } }

public class InsuredPackage extends Package { InsuredPackage(int w, char m) { super(w, m); final double LOWCOST = 1.01; final double MEDCOST = 3.01; final double LOWINS = 2.45; final double MEDINS = 3.95; final double HIGHINS = 5.55; double i; if(getCost() < LOWCOST) i = LOWINS; else if(getCost() < MEDCOST) i = MEDINS; else i = HIGHINS; increaseCost(i); } }

public class UsePackage { public static void main(String args[]) { Package p1 = new Package(4,'A'), p2 = new Package(10,'T'), p3 = new Package(20,'M'); InsuredPackage p4 = new InsuredPackage(4,'A'), p5 = new InsuredPackage(10,'T'), p6 = new InsuredPackage(20,'M'); System.out.println("Packages:"); p1.display(); p2.display(); p3.display(); System.out.println("Insured packages:"); p4.display(); p5.display(); p6.display(); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!