In: Computer Science
Convert the MileConversions program to an interactive application. Instead of assigning a value to the miles variable, accept it from the user as input.
class MileConversionsInteractive
{
public static void main(String[] args) {
// Modify the code below
final double INCHES_IN_MILE = 63360;
final double FEET_IN_MILE = 5280;
final double YARDS_IN_MILE = 1760;
double miles = 4;
double in, ft, yds;
in = miles * INCHES_IN_MILE;
ft = miles * FEET_IN_MILE;
yds = miles * YARDS_IN_MILE;
System.out.println(miles + " miles is " + in +
" inches, or " + ft + " feet, or " +
yds + " yards");
}
}
import java.util.Scanner; class MileConversionsInteractive { public static void main(String[] args) { // Modify the code below final double INCHES_IN_MILE = 63360; final double FEET_IN_MILE = 5280; final double YARDS_IN_MILE = 1760; Scanner scanner = new Scanner(System.in); System.out.print("Enter number of miles: "); double miles = scanner.nextDouble(); double in, ft, yds; in = miles * INCHES_IN_MILE; ft = miles * FEET_IN_MILE; yds = miles * YARDS_IN_MILE; System.out.println(miles + " miles is " + in + " inches, or " + ft + " feet, or " + yds + " yards"); } }