43.6k views
0 votes
There are 12 inches in a foot and 3 feet in a yard. Create a class named InchConversion. Its main() method accepts a value in inches from a user at the keyboard, and in turn passes the entered value to two methods. One converts the value from inches to feet, and the other converts the same value from inches to yards. Each method displays the results with appropriate explanation.

User Mikeschuld
by
4.6k points

1 Answer

5 votes

Answer:

import java.util.Scanner;

public class InchConversion

{

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("Enter inches: ");

double inches = input.nextDouble();

inchesToFeet(inches);

inchesToYards(inches);

}

public static void inchesToFeet(double inches){

double feet = inches / 12;

System.out.println(inches + " inches = " + feet + " feet");

}

public static void inchesToYards(double inches){

double yards = inches / 36;

System.out.println(inches + " inches = " + yards + " yards");

}

}

Step-by-step explanation:

In the inchesToFeet() method that takes one parameter, inches:

Convert the inches to feet using the conversion rate, divide inches by 12

Print the feet

In the inchesToYards() method that takes one parameter, inches:

Convert the inches to yards using the conversion rate, divide inches by 36

Print the yards

In the main:

Ask the user to enter the inches

Call the inchesToFeet() and inchesToYards() methods passing the inches as parameter for each method

User LpLrich
by
5.6k points