Question

In: Computer Science

IN JAVA: Build a class called ExamPractice from scratch. This class should include a main method...

IN JAVA: Build a class called ExamPractice from scratch. This class should include a main method that does the following:

  1. Prompt the user to enter a number of inches
  2. Read the number of inches entered from the console
  3. Convert the inches into an equivalent number of miles, yards, feet, and inches.
  4. Output the results to the console.

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

Solutions

Expert Solution

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:


Related Solutions

Assignment 1: Build a simple class called DBTester.java. This class should have only one method, main...
Assignment 1: Build a simple class called DBTester.java. This class should have only one method, main method. In the main method you should read in all of the rows of data from the Instructors Table in the Registration Database, then print out this data. Follow the steps outlined in class. Remember to use try-catch blocks for all database access code. The example in the book does not use Try-catch blocks, but you should
in JAVA: implement a class called tree (from scratch) please be simple so i can understand...
in JAVA: implement a class called tree (from scratch) please be simple so i can understand thanks! tree(root) node(value, leftchild,rightchild) method: insert(value)
In Java Create a class called "TestZoo" that holds your main method. Write the code in...
In Java Create a class called "TestZoo" that holds your main method. Write the code in main to create a number of instances of the objects. Create a number of animals and assign a cage and a diet to each. Use a string to specify the diet. Create a zoo object and populate it with your animals. Declare the Animal object in zoo as Animal[] animal = new Animal[3] and add the animals into this array. Note that this zoo...
*****Using Java 1.         There is a class called Wages. It should have one method: calculateWages. This...
*****Using Java 1.         There is a class called Wages. It should have one method: calculateWages. This method accepts from a user (1) an integer hourly rate and (2) an integer total number of hours worked in a week. It calculates and displays the total weekly wage of an employee. The company pays straight time for the first 40 hours worked by an employee and times and a half for all the hours worked in excess of 40. This class should...
Write a class in Java called 'RandDate' containing a method called 'getRandomDate()' that can be called...
Write a class in Java called 'RandDate' containing a method called 'getRandomDate()' that can be called without instantiating the class and returns a random Date between Jan 1, 2000 and Dec 31, 2010.
Required components: A controller class with Java main() method and a PaymentCalculator class to hold the...
Required components: A controller class with Java main() method and a PaymentCalculator class to hold the data and methods for the application. Scenario/Information: If you carry a balance on a credit card, it can be nice to see how long it would take to payoff the card. For this scenario, you should design a Java application the prints a credit card payment schedule. Inputs for your program should include: Customer’s name (first and last), the account number (as an integer),...
C#. Build a class that will be called “MyDate”. The class should have 3 properties: month,...
C#. Build a class that will be called “MyDate”. The class should have 3 properties: month, day and year. Make month, day and year integers. Write the get and set functions, a display function, and constructors, probably two constructors. (No Database access here.)
Java Create a method to display a menu. When this method is called it should receive...
Java Create a method to display a menu. When this method is called it should receive the user's name, great the user, and ask them to make a selection. 1 - Change your name, 2 - Test your IQ, 3 - Display a table, 4 - Play a game, 5 - Exit.
2-Dimensional Array Operations. Use a Java class with a main method. In this class (after the...
2-Dimensional Array Operations. Use a Java class with a main method. In this class (after the main method), define and implement the following methods: public static void printArray. This method accepts a two-dimensional double array as its argument and prints all the values of the array, separated by a comma, each row in a separate line. public static double getAverage. This method accepts a two-dimensional double array as its argument and returns the average of all the values in the...
Java Language -Create a project and a class with a main method, TestCollectors. -Add new class,...
Java Language -Create a project and a class with a main method, TestCollectors. -Add new class, Collector, which has an int instance variable collected, to keep track of how many of something they collected, another available, for how many of that thing exist, and a boolean completist, which is true if we want to collect every item available, or false if we don't care about having the complete set. -Add a method addToCollection. In this method, add one to collected...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT