/** CISC 1115 HW #2 * Calculates shipping costs */ import java.util.Scanner; public class HW2 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print("Enter package weight in pounds: "); // ask for weight double weight = scan.nextDouble(); System.out.print("Enter shipping distance in miles: "); // ask for distance double dist = scan.nextDouble(); dist = Math.ceil(dist/400); // rounds up the decimal after dividing by 400 if (weight>=0) // must be a positive amount { System.out.print("The shipping cost for your package is: $"); double rate; if (weight<=2) // 2 or less pounds rate = 1.59; else if (weight <= 5) // between 2 and 5 pounds rate = 3.10; else if (weight <= 9) // between 5 and 9 pounds rate = 4.25; else rate = 5.00; // over 9 pounds double cost = rate * dist; // formula to calculate cost of delivering package System.out.printf("%.2f is the cost, based upon the base cost of $%.2f" + " per 400 miles.", cost,rate); // 2 decimal places } else System.out.println("Error. Your number is negative."); // if number is less than 0 } } /** Handcheck: * -5 pounds for 100 miles = error * 1 pound for 200 miles = $1.59 * 3.5 pounds for 900 miles = $9.30 * 7.8 pounds for 1725.5 miles = $21.25 * 11 pounds for 2000 miles = $25.00 * All the calculations are correect when the program was ran * */ /** Memory Trace * Weight | Dist | Rate | Cost * -5 | 100 | 0 | 0 * -5 | 1 | 0 | 0 * 1 | 200 | 1.59 | 0 * 1 | 1 | 1.59 | 1.59 * 3.5 | 900 | 3.1 | 0 * 3.5 | 3 | 3.1 | 9.3 * */