Question

In: Computer Science

Convert the MileConversions program to an interactive application. Instead of assigning a value to the miles...

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");

   }

}

Solutions

Expert Solution

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");

    }

}


Related Solutions

Miles to Kilometers ASSIGNMENT: Write a program to convert miles to kilometers. Put the entire program...
Miles to Kilometers ASSIGNMENT: Write a program to convert miles to kilometers. Put the entire program in a sentinel-controlled loop that runs until the user enters a negative number. Use both a pre-test sentinel-controlled loop and a post-test sentinel-controlled loop in the program. There are 1.6 kilometers in 1.0 mile. Store the value of 1.6 in a constant and use the constant in the calculations. There is 1 blank line after the descriptions, and 2 blanks lines between the pre-test...
Create in java an interactive GUI application program that will prompt the user to use one...
Create in java an interactive GUI application program that will prompt the user to use one of three calculators, label project name MEDCALC. You can use any color you want for your background other than grey. Be sure to label main java box with “MEDCALC” and include text of “For use only by students” On all three calculators create an alert and signature area for each user. The alert should be something like “All calculations must be confirmed by user...
This is C# programming. In Chapter 2, you created an interactive application named GreenvilleRevenue. The program...
This is C# programming. In Chapter 2, you created an interactive application named GreenvilleRevenue. The program prompts a user for the number of contestants entered in this year’s and last year’s Greenville Idol competition, and then it displays the revenue expected for this year’s competition if each contestant pays a $25 entrance fee. The programs also display a statement that compares the number of contestants each year. Now, replace that statement with one of the following messages: If the competition...
c# In Chapter 2, you created an interactive application named MarshallsRevenue. The program prompts a user...
c# In Chapter 2, you created an interactive application named MarshallsRevenue. The program prompts a user for the number of interior and exterior murals scheduled to be painted during the next month by Marshall’s Murals. Next, the programs compute the expected revenue for each type of mural when interior murals cost $500 each and exterior murals cost $750 each. The application also displays the total expected revenue and a statement that indicates whether more interior murals are scheduled than exterior...
Complete the following program skeleton. When finished, the program will ask the user for a length (in inches), convert that value to centimeters, and display the result. You are to write the function convert.
Complete the following program skeleton. When finished, the program will ask the user for a length (in inches), convert that value to centimeters, and display the result. You are to write the function convert. (Note: 1 inch = 2.54 cm. Do not modify function main.) #include #include using namespace std;// Write your function prototype here.int main(){ double measurement; cout ≪ "Enter a length in inches, and I will convert\n"; cout ≪ "it to centimeters: "; cin ≫ measurement; convert(&measurement); cout...
Consider this interactive scenario: The 1000 employees of the EconoPlant all live in QuietTown miles away....
Consider this interactive scenario: The 1000 employees of the EconoPlant all live in QuietTown miles away. There are two roads from QuietTown to the EconoPlant, Wide Road and Narrow Road. Every day each employee needs to decide which road to take for commuting to work. The two roads differ in their commute time such that: • Wide Road has a low-speed limit, but is sufficiently wide so that traffic does not cause a slowdown. The commute on Wide Road takes...
How do I convert 60 miles per hour to SIU?
How do I convert 60 miles per hour to SIU?
Write a program to calculate the time to run 5 miles, 10 miles, half marathon, and...
Write a program to calculate the time to run 5 miles, 10 miles, half marathon, and full marathon if you can run at a constant speed. The distance of a half marathon is 13.1 miles and that of a full marathon is 26.2 miles. Report the time in the format of hours and minutes. Your program will prompt for your running speed (mph) as an integer. Write a program that displays the Olympic rings. Color the rings in the Olympic...
Write an interactive Java class which accepts an input argument when the application is executed from...
Write an interactive Java class which accepts an input argument when the application is executed from the command-line. Accept input from the user and compare the value entered to the command-line argument value. If the strings do not equal, display "INVALID VALUE! TRY AGAIN!", otherwise display "PERMISSION GRANTED!" and exit the program.
You will create a program that runs in one of two modes, interactive mode and test...
You will create a program that runs in one of two modes, interactive mode and test mode. The mode will determined by the command line, passing in a "-i" flag for interactive or "-t" for test mode. Require the user to pass in a flag. $> ./lab02 -i Make a selection: 1) Insert value at position 2) Remove at position 3) Replace value at position 4) Print length 5) Print list 6) Exit Choice: $> ./lab02 -t <output from your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT