Question
Change the code below to display as JOptionPane. The code should appear in dialog boxes like this to allow the user to input information. import
Change the code below to display as JOptionPane. The code should appear in dialog boxes like this to allow the user to input information.
import java.util.Scanner;
public class helpwithproblem { public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int numberOfPackages = 0; // number of packages to ship double weight = 0.0; // weight of the package int packageNumber = 0; //Each package has a number double shippingCharges = 0.0; // Shipping Charge int counter = 0; // Loop counter System.out.println("This program calculates shipping charges."); System.out.println("Please enter the number of packages:"); //input number of packages numberOfPackages = keyboard.nextInt(); while (counter
System.out.println("Please enter the package number:"); //input package number packageNumber = keyboard.nextInt();
System.out.println("Please enter the weight of package #" + packageNumber); //Input package weight //input package number weight = keyboard.nextDouble();
// validate weight to make sure it is not less than 0. while (weight
System.out.println("Invalid weight. Please enter a number greater than or = 0."); weight = keyboard.nextDouble(); } //end while loop for validating the weight
//You will need a print statement to print out the quarter and the number of the quarter that you are on System.out.printf("%-40s%-10s%40s ", "****************************************", ("PACKAGE " + packageNumber), "****************************************"); //You will need a printf statement to print 5 column headings System.out.printf("%-30s%-30s%-30s ", "Package Number", "Weight", "Shipping Charge");
//This begins the if structure for the determining the shipping charge if (weight =16 && weight =36 && weight
// Display the results //You will need a printf statement to print out the package number, weight, shipping charges System.out.printf("%-30d%-30.1f%-30.2f ", packageNumber, weight, shippingCharges);
counter = counter + 1; } //end of while loop that controls the running of the program
} //end of main } //end of class
Input ? Please enter the number of packages: OK CancelStep 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