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...
Java Please comment code Create an Interactive JavaFX Application Create an application with the following controls:...
Java Please comment code Create an Interactive JavaFX Application Create an application with the following controls: A Label control with the following text displayed: "First Number:" A Label control with the following text displayed: "Second Number:" An empty TextField control beside the First Number label. An empty TextField control beside the Second Number label. Five buttons: Button 1 labeled + Button 2 labeled - Button 3 labeled * Button 4 labeled / Button 5 labeled = An empty Label control...
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...
Using Python, create a program that will act as a number convertor. This program will convert...
Using Python, create a program that will act as a number convertor. This program will convert an input decimal integer into binary and hexadecimal formats. a) Define a main function named numberconvertor(). Inside the main function, write all the logic of your code. [5% marks] b) Looping indefinitely (Hint: use infinite while loop), the program should give the user the 3 options given below and allow the user to select one among them. [15% marks] 1. converting a decimal number...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT