Question

In: Computer Science

Write a java program called ImperialMetric that displays a conversion table for feet and inches to...

Write a java program called ImperialMetric that displays a conversion table for feet
and inches to metres. The program should ask the user to enter the range of values that
the table will hold.
Here is an example of what should be output when the program runs:
Enter the minimum number of feet (not less than 0):
5
Enter the maximum number of feet (not more than 30):
9

|
|
|
|
|
|
0"
1.524
1.829
2.134
2.438
2.743
1"
1.549
1.854
2.159
2.464
2.769
2"
1.575
1.880
2.184
2.489
2.794
3"
1.600
1.905
2.210
2.515
2.819
4"
1.626
1.930
2.235
2.540
2.845
5"
1.651
1.956
2.261
2.565
2.870
6"
1.676
1.981
2.286
2.591
2.896
7"
1.702
2.007
2.311
2.616
2.921
8"
1.727
2.032
2.337
2.642
2.946
9"
1.753
2.057
2.362
2.667
2.972
10"
1.778
2.083
2.388
2.692
2.997
11"
1.803
2.108
2.413
2.718
3.023
5'
6'
7'
8'
9'

The sample solution used to generate the above example and the automarker scripts
uses System.out.printf() with a format string of "%6.3f" to print the metric values.
We recommend the following formula:
double metres = (feet*12+inches)*0.0254;

Solutions

Expert Solution

Solution: The required java code has been provided below, along with the output. Comments have been placed to depict the functionality.

main() has been implemented to complete the test.

import java.util.*;

public class PrintfTest
{

        public static void main (String arg[])
        {
     //declare variables
     int minfeet, maxfeet;
     double metres;

     //Scanner to ask user input
     Scanner reader = new Scanner(System.in);

     System.out.println("Enter the minimum number of feet(not less than 0)");
     minfeet = reader.nextInt();

        System.out.println("Enter the maximum number of feet(not more than 30)");
     maxfeet = reader.nextInt();

     //print the inches
     System.out.printf("| ");
    for (int i =0;i<12;i++)
    {
        System.out.printf(i+"''   ");

    }

    //print the minimum feet
    System.out.printf(minfeet+"'"+"\n");
    

    //Nested loop to calculate the metres and display
    for (int j=minfeet;j<=maxfeet;j++)
    {
      System.out.printf("|");
      for (int i=0;i<12;i++)
        {
        metres = ((j*12)+i) * 0.0254;

        //Use formatted output
        System.out.printf("%6.3f",metres);
                 }
                if (j+1 < (maxfeet + 1))
                {
                System.out.printf("   "+(j+1)+"'"+"\n"); 
            }
            if (j+1 == maxfeet + 1)
                {System.out.println("");}
          
        }
}       
}

Output:

Enter the minimum number of feet(not less than 0)
5
Enter the maximum number of feet(not more than 30)
9
| 0''       1''       2''       3''      4''       5''      6''       7''       8''      9''      10''     11''       5'
| 1.524 1.549 1.575 1.600 1.626 1.651 1.676 1.702 1.727 1.753 1.778 1.803   6'
| 1.829 1.854 1.880 1.905 1.930 1.956 1.981 2.007 2.032 2.057 2.083 2.108   7'
| 2.134 2.159 2.184 2.210 2.235 2.261 2.286 2.311 2.337 2.362 2.388 2.413   8'
| 2.438 2.464 2.489 2.515 2.540 2.565 2.591 2.616 2.642 2.667 2.692 2.718   9'
| 2.743 2.769 2.794 2.819 2.845 2.870 2.896 2.921 2.946 2.972 2.997 3.023


Related Solutions

Write a program that displays a temperature conversion table for degrees Celsius and degrees Fahrenheit. The...
Write a program that displays a temperature conversion table for degrees Celsius and degrees Fahrenheit. The table should include rows for all temperatures between 0 and 100 degrees Celsius that are multiples of 10 degrees Celsius. Include appropriate headings on your columns. The formula for converting between degrees Celsius and degrees Fahrenheit can be found on the internet. Python 3
Java language. 1. write a conversion method that have 2 parameter 1. feet and 2. inches(as...
Java language. 1. write a conversion method that have 2 parameter 1. feet and 2. inches(as small as 1/8 inch)(make sure precondition, can't be smaller than 1/8 inch) and give output as feet in decimal place. 2 Write a method to calculate the area of a rectangle that take in width and height (feet) (as small as 1/8 inch)(make sure precondition, can't be smaller than 1/8 inch) and round up to the closet feet. Write test cases for both method...
Write a JAVA program that displays a table of the Celsius temperatures and their Fahrenheit equivalents....
Write a JAVA program that displays a table of the Celsius temperatures and their Fahrenheit equivalents.  The formula for converting a temperature from Celsius to Fahrenheit is F = 9/ 5 C + 32 where F → Fahrenheit temperature C → Celsius temperature.  Allow the user to enter the range of temperatures in Celsius to be converted into Fahrenheit.  Your program must use a loop to display the values of the temperature conversions (see sample output). Sample...
I need to write this program in Python. Write a program that displays a temperature conversion...
I need to write this program in Python. Write a program that displays a temperature conversion table for degrees Celsius and degrees Fahrenheit. The tabular format of the result should include rows for all temperatures between 70 and 270 degrees Celsius that are multiples of 10 degrees Celsius (check the sample below). Include appropriate headings on your columns. The formula for converting between degrees Celsius and degrees Fahrenheit is as follow F=(9/5C) +32 Celsius Fahrenheit 70 158 80 176 90...
Meant to be written in Java JDK 14.0 Write a program to display the conversion table...
Meant to be written in Java JDK 14.0 Write a program to display the conversion table from meter to feet using formatted output (printf()): 1 meter = 3.28084 feet; 1 foot = 12 inch When display the number, round the number to 2 decimal places. Set the number in the 1st the 2nd columns to the left align, set the 3rd column to the right align: meter(s) feet inch(es) 1 3.28 37.37 2 x.xx xx.xx 3 x.xx xxx.xx
Write a program named MakeChange that calculates and displays the conversion of an entered number of...
Write a program named MakeChange that calculates and displays the conversion of an entered number of dollars into currency denominations—twenties, tens, fives, and ones. For example, if 113 dollars is entered, the output would be twenties: 5 tens: 1 fives: 0 ones: 3. Answer in C# (P.S i'm posting the incomplete code that i have so far below.) using System; using static System.Console; class MakeChange { static void Main() { int twenties, tens, fives, ones; WriteLine("Enter the number of dollars:");...
Java Programming Write a program that displays the following pattern *                         *       &nbsp
Java Programming Write a program that displays the following pattern *                         *          *          * *          *          *          *          *          *          *          *          *          *          *          *             *          *          *          *          *                         *          *          *                                     * Printing Pattern A * ** *** **** ***** ****** ******* Printing Pattern B ******* ****** ***** **** *** ** * Printing Pattern C * ** *** **** ***** ****** *******
Write a Java program that reads a name and displays on the screen.
Write a Java program that reads a name and displays on the screen.
URGENT!! DO THIS CODE IN JAVA Write a complete Java FX program that displays a text...
URGENT!! DO THIS CODE IN JAVA Write a complete Java FX program that displays a text label and a button.When the program begins, the label displays a 0. Then each time the button is clicked, the number increases its value by 1; that is each time the user clicks the button the label displays 1,2,3,4............and so on.
in java Write a Java Program that displays a menu with five different options: 1. Lab...
in java Write a Java Program that displays a menu with five different options: 1. Lab Test Average Calculator 2. Dice Roll 3. Circle Area Calculator 4. Compute Distance 5. Quit The program will display a menu with each of the options above, and then ask the user to enter their choice. There is also a fifth option to quit, in which case, the program will simply display a goodbye message. Based on the user’s choice, one of the options...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT