Question

In: Computer Science

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

Solutions

Expert Solution

Complete code in java:-

import java.util.*;

// Main class
class Conversion {
   // Main method
   public static void main(String ... args) {
       // Creating three arrays, one array for each column.
       double []meters = new double[6];
       double []feets = new double[6];
       double []inches = new double[6];
       // Doing conversion
       // Between units
       for(int i = 0; i < 6; i++) {
           meters[i] = i+1;
           feets[i] = meters[i]*3.28084;
           inches[i] = feets[i]*12;
       }
       // Printing columnwise formatted output.
       System.out.printf("%-22s|%-22s|%-26s\n", "Meters", "Feets", "Inches");
       for(int i = 0; i < 6; i++) {
           System.out.printf("%-22.2f|%-22.2f|%-26.2f\n", meters[i], feets[i], inches[i]);
       }
   }
}

Screenshot of output:-


Related Solutions

Meant to be written in Java JDK 14.0 A String object is called palindrome if it...
Meant to be written in Java JDK 14.0 A String object is called palindrome if it is same when read from the front and the end. For example, String “abcba” is palindrome, while “12322” is not. Write Java program to check a String object of 5 characters is palindrome or not: (a) The comparison is case sensitive (b) The comparison is case insensitive
Meant to be written in Java JDK 14.0 In New York state, the vehicle plate number...
Meant to be written in Java JDK 14.0 In New York state, the vehicle plate number has the following format: xxx-yyyy, where x is a letter and y is a digit. Write a program to enter a string, verify if it is a valid plate number or not
Meant to be written in Java JDK 14.0 4. Define 2 String variables str1 and str2,...
Meant to be written in Java JDK 14.0 4. Define 2 String variables str1 and str2, get input from console and assign input to str1 and str2. (a) Display the length of str1 and str2 (b) Display the first and last characters in str1 and str2 (c) Compare str1 and str2 to check if they are equal or not: (1) The comparison is case sensitive (2) The comparison is case insensitive (d) Compare str1 with str2 to check which string...
Meant to be written in Java JDK 14.0 1. Define 2 double variables. (a) Use method(s)...
Meant to be written in Java JDK 14.0 1. Define 2 double variables. (a) Use method(s) define in Math class to check if these 2 numbers are equal or not. Display result (b) Write code (not to use Math method) check if these 2 numbers are equal or not. Display result
Java Program Use for loop 1.) Write a program to display the multiplication table of a...
Java Program Use for loop 1.) Write a program to display the multiplication table of a given integer. Multiplier and number of terms (multiplicand) must be user's input. Sample output: Enter the Multiplier: 5 Enter the number of terms: 3 5x0=0 5x1=5 5x2=10 5x3=15 2 Create a program that will allow the user to input an integer and display the sum of squares from 1 to n. Example, the sum of squares for 10 is as follows: (do not use...
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
PROGRAM MUST BE WRITTEN IN JAVAFX Develop a program flowchart and then write a menu-driven Java...
PROGRAM MUST BE WRITTEN IN JAVAFX Develop a program flowchart and then write a menu-driven Java program that will solve the following problem. The program uses one and two-dimensional arrays to accomplish the tasks specified below. The menu is shown below. Please build a control panel as follows: (Note: the first letter is shown as bold for emphasis and you do not have to make them bold in your program.) Help SetParams FillArray DisplayResults Quit Upon program execution, the screen...
Q1: Write a Java program that will display different messages depending on your age. Your program...
Q1: Write a Java program that will display different messages depending on your age. Your program should ask the user for his/her name and their age in years and give one or more answers from the following ones below: if the age of the user is less than 16, the program should print on the screen “You are not allowed to drive at the moment”. if the age of the user is less than 18, the program should print on...
Write a program in java that uses methods to input data for calculation, calculate, and display...
Write a program in java that uses methods to input data for calculation, calculate, and display the results of the calculations. That is, there are at least three methods. The problem is to write a program that calculates the area of a rectangle. This action should be repeatable.
Java - Write a program to calculate a user’s BMI and display his/her weight status. The...
Java - Write a program to calculate a user’s BMI and display his/her weight status. The status is defined as Underweight, Normal, Overweight and obese if BMI is less than 18.5, 25, 30 or otherwise respectively. You need to read weight (in kilogram) and height (in metre) from the user as inputs. The BMI is defined as the ratio of the weight and the square of the height. [10 marks]
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT