In: Computer Science
IN JAVA: Build a class called ExamPractice from scratch. This class should include a main method that does the following:
For example, if a user entered 100000 inches, the program would output:
100000 inches is equivalent to:
Miles: 1
Yards: 1017
Feet: 2
Inches: 4
Answer:
import java.util.Scanner;
public class ExamPractice {
public static void main(String args[])
{
int inches,ft,yards,miles,remainingInches,inchesInFeet = 12,feetsInMile = 5280,inchesInMile;
Scanner s=new Scanner(System.in);
System.out.print("Enter the number of inches: ");
inches=s.nextInt();
//calcukates inches in miles
inchesInMile = feetsInMile * inchesInFeet;
//converts inches from miles
miles = inches / inchesInMile;
//calculates remaining inches
remainingInches = inches % inchesInMile;
//converts the remaining inches to feet
ft = remainingInches / inchesInFeet;
//converts feet to yard
yards=ft/3;
//converts the feet to feet and inches
ft=ft%3;
//calculates final remaining inches
remainingInches = remainingInches % inchesInFeet;
System.out.println(inches+" inches is equivalent to: ");
System.out.println("Miles: "+miles);
System.out.println("Yards: "+yards);
System.out.println("Feet: "+ft);
System.out.println("Inches: "+remainingInches);
}
}
Output:
