Using Java Eclipse IDE complete the code below. create a CommentHeader. Create a TestClass, Create a Shipping
Question:
Using Java Eclipse IDE complete the code below. create a CommentHeader. Create a TestClass, Create a Shipping Class at least 1 constructor, a toString method, a calculate shipping method. A seperate output results method. Create calculations correctly based on Weight. Create calculations correctly based on Miles. Create calculations correctly based on fragile or not fragle. Create calculations correctly based on total cost to ship. Also allow user to ship another package via a MENU SYSTEM: 1. Ship a package. 2. Quit. Enter your choice:
Code:
public class Shipping { private int miles; private double weight; private boolean fragile;
public Shipping(int miles, double weight, boolean fragile) { this.miles = miles; this.weight = weight; this.fragile = fragile; calcCost(); } public String toString() { String result = "=========================="; result += "Miles to ship package" + miles + ""; if(fragile) result += "The package is fragile."; else result += " The package is Not fragile, kick it ";
return result; }//end of toString
public void calcCost() { double milesCost = 0.0; double weightCost = 0.0; double fragileCost = 0.0; double totalCost = 0.0;
//calculate cost based on miles if (miles <= 250) milesCost = 15.00;
int noSegments = miles / 250;
if(miles % 250 == 0) milesCost = 15.00 * noSegments; else milesCost = 15.00 * noSegments + 15.00;
//calculate cost based on weight if(weight <= 10) weightCost = 3.75; else weightCost = 3.75 + (weight - 10) * .5;
//calculate cost based on fragile or not fragile if(fragile) fragileCost = 2.00; else fragileCost = 0; //calculate cost to ship a package totalCost = weightCost + milesCost + fragileCost;
//Display the output here System.out.println(toString()); System.out.println("----------------------------"); System.out.printf("The cost based on distance is $%.2f", milesCost); System.out.printf("The cost based on weight is..: $%.2f", weightCost); System.out.printf("The cost based on fragile is....: $%.2f", fragileCost); System.out.printf("The total cost to ship is...: $%.2f", totalCost); System.out.println("---------------------"); }//end ethod calcCost
}
public class TestClassShipping { public static void main(String[] args) { //(miles,weight,fragile) Shipping myPackage = new Shipping(751,11,true); System.out.println(myPackage);
}//end main }//end TestClassShipping
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill