any help would be great Overview: Write a compelete Java program in a source fil
ID: 3541809 • Letter: A
Question
any help would be great
Overview: Write a compelete Java program in a source file to be named Assignment2.java. Your program will convert American measurements to metric. Specifically, the progarm will convert a person's height from feet and inches to meters. Example Execution Below is a sample execution. Bold text indicates user input. What is your name? Steve What is your height? Feet: 6 Inches: 4 Steve, your height in meters is 1.93 Algorithms: Converting inches to meters To convert the height to meters, you must first convert height from feet and inches to just inches. Then you can convert the inches to meters. Since there are 12 inches in a foot, 2.54 inches in a centimeter, and 100 centimeters in a meter, you can use one equation to do all the convertion: Hm = ((Hf * 12) + Hi) * 2.54 / 100 where Hf is the number of feet entered by the user Hi is the number of inches entered by the user Hm is the height of the person in meters In the above eample, Hf = 6, Hi = 4, and Hm = 1.93 Formatting Decimal Numbers (I will cover this in class) Implementation Details You can assume the the user will always input a positive integer for feet and inches. The user may enter zero but not negative numbers. The user may also enter a number greater than 12 for inches (see Sample Output #2 below). You may want to create variable for the following pieces of information: Name (String) Feet entered by user (int) Inches entered by user (int) Height in meters (double) You may use additional variables if you desire, and you are not required to create the ones mentioned above. This program should be implemented using only one class (called Assignment2) and should only contain one method (main).Explanation / Answer
please rate - thanks
any questions ask
without formatting
import java.util.*;
public class main
{public static void main(String[] args)
{Scanner in=new Scanner(System.in);
String name;
int feet, inches;
double meters;
System.out.print("What is your name? ");
name=in.next();
System.out.println("What is your height? ");
System.out.print("Feet: ");
feet=in.nextInt();
System.out.print("Inches: ");
inches=in.nextInt();
meters=((feet*12)+inches)*2.54/100.;
System.out.println(name+", your height in meters is "+meters);
}
}
-------------------------------
with formatting --this is 1 of multiple ways to do the formatting-don't know how you are going to be taught-I find this the easiest
import java.util.*;
public class main
{public static void main(String[] args)
{Scanner in=new Scanner(System.in);
String name;
int feet, inches;
double meters;
System.out.print("What is your name? ");
name=in.next();
System.out.println("What is your height? ");
System.out.print("Feet: ");
feet=in.nextInt();
System.out.print("Inches: ");
inches=in.nextInt();
meters=((feet*12)+inches)*2.54/100.;
System.out.printf("%s, your height in meters is %.2f ",name,meters);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.