CISS 100 RU Dialog Boxes from The Console Window Program
I’m stuck on a Java question and need an explanation.
5-8. Modify exercise 2-4 where miles per gallon where calculated from the console window. Now modify the program so dialog boxes are used (use all arguments). The prompt and input will be a dialog box instead of a System.out.print() and sc.nextDouble(). The output will be a dialog box instead of a System.out.println(). The input and output will all be the same, but now in dialog boxes. Save as ex58.java and submit it.
* Exercise 2-4 * This program will calculate miles per gallon * */ import java.util.Scanner; public class ex24 { public static void main(String[] args) { double miles, gallons, mpg; // declare variables Scanner sc = new Scanner(System.in); System.out.print("Enter miles: "); // prompt miles = sc.nextDouble(); // input System.out.print("Enter gallons: "); gallons = sc.nextDouble(); mpg = miles / gallons; // calculate System.out.printf("Miles per gallon is %.1fn", mpg); // output } }