A computer screen displaying Java code with the text 'Java Programming'" Caption: "Coding in Java
Coding in Java

How to Create an Interactive Length Converter in Java: Converting Inches to Feet and Inches.

Table of Contents

Statement

Write an interactive version of the InchesToFeet class that accepts the inches
value from a user. Save the class as InchesToFeetInteractive.java.

public class InchesToFeetInteractive {
    public static void main(String[] args) {
        int lenght;
        System.out.println("enter the lenght in inches:");
        Scanner input=new Scanner(System.in);
        lenght=input.nextInt();
        int lenght_in_feet=lenght/12;
        int lenght2_in_inches=lenght%12;
        System.out.println("your lenght will be: "+lenght_in_feet+ " feet"+" and "+lenght2_in_inches+ " inches");
    }
}

Explanation

This statement is asking you to create a new version of the “InchesToFeet” class that will be interactive.

The interactive version should accept the “inches” value from a user as input, rather than having the value assigned directly in the code.

This means that the program should prompt the user to enter a value for “inches”, and then use that value to calculate and display the equivalent length in feet and inches.

The new class should be saved as “InchesToFeetInteractive.java”.