Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Provide class headers (a brief description of the class), method headers (a brie

ID: 3805821 • Letter: P

Question

Provide class headers (a brief description of the class), method headers (a brief description of the methods and parameters), and additional comments where appropriate for the following block of Java Code.

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;
}
}

Explanation / Answer

// class to check weight and method of the delivering Package and calculate cost
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;           //define lows for Air,Truck and mail packages
   final double LOWTRUCK = 1.50;
   final double LOWMAIL = 0.50;
   final int MEDWT = 17;                   //define lows for Air,Truck and mail packages
   final double MEDAIR = 3.00;
   final double MEDTRUCK = 2.35;
   final double MEDMAIL = 1.50;
   final double HIGHAIR = 4.50;               //define lows for Air,Truck and mail packages
   final double HIGHTRUCK = 3.25;
   final double HIGHMAIL = 2.15;
   public Package(int w, char m)           //Package constructor
   {
      weight = w;
      method = m;
      cost = calculateCost(w, m);        //calculate the cost of Package based on weight and method used
   }

   private double calculateCost(int w, char m)
   {
      double c;
      if(w < LOWWT)
      {
        if(m == AIR)             //if method is AIR and weight is less than LOWWT cost = LOWAIR
           c = LOWAIR;
        else
           if(m == TRUCK)      //if method is TRUCK and weight is less than LOWWT cost = LOWTRUCK
              c = LOWTRUCK;
           else
              c = LOWMAIL;   //if method is Mail and weight is less than LOWWT cost = LOWMAIL
      }
      else
         if(w < MEDWT)       //for medium weight
         {
            if(m == AIR)
               c = MEDAIR;      //method = AIR cost = MEDAIR
            else
               if(m == TRUCK)
                  c = MEDTRUCK;   //method = TRUCK cost = MEDTRUCK
               else
                  c = MEDMAIL;    //method = Mail cost = MEDMAIL
         }
         else              //high cost
         {
            if(m == AIR)
               c = HIGHAIR;
            else
               if(m == TRUCK)
                  c = HIGHTRUCK;
               else
                  c = HIGHMAIL;
         }
      return c;
   }

   //display package weight ,shipping method and cost

   public void display()
   //money format//
   {
      System.out.println("The package weighs " +
         weight + " pounds. Ship method " + method +
         "Cost $" + cost);
   }

   //get method for cost
   public double getCost()
   //get cost method//
   {
      return cost;
   }

   //method to increase cost
   public void increaseCost(double c)
   {
      cost = cost + c;
   }
}


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote