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 Program General Scenario: You are creating an interactive application that gets input from the keyboard...
Java Program General Scenario: You are creating an interactive application that gets input from the keyboard and keeps track of a grocery store that a businessman runs. In order to develop this application, you will be using 2 interfaces, 1 abstract class, and 1 concrete class. You should use the interfaces and the abstract class to create the concrete class. Your application should have overridden toString() at appropriate places so that you could display the object state, i.e., the string...
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...
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...
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...
How do I convert 60 miles per hour to SIU?
How do I convert 60 miles per hour to SIU?
In Chapter 4 of your book, you created an interactive application named MarshallsRevenue that prompts a...
In Chapter 4 of your book, you created an interactive application named MarshallsRevenue that prompts a user for the number of interior and exterior murals scheduled to be painted during a month and computes the expected revenue for each type of mural. The program also prompts the user for the month number and modifies the pricing based on requirements listed in Chapter 4. Now, modify the program so that the user must enter a month value from 1 through 12....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT