Question

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

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

class InchesToFeetInteractive

{    

  public static void main(String[] args) {

      // Modify the code below

     final int INCHES_IN_FOOT = 12;

     int inches = 86;

     int feet;

     int inchesLeft;

     feet = inches / INCHES_IN_FOOT;

     inchesLeft = inches % INCHES_IN_FOOT;

     System.out.println(inches + " inches is " +

        feet + " feet and " + inchesLeft + " inches");

  }

}

Homework Answers

Answer #1
//InchesToFeetInteractive.java
import java.util.Scanner;
public class InchesToFeetInteractive {
    public static void main(String[] args) {
        int inches;
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter number of inches: ");
        inches = scanner.nextInt();
        InchesToFeet inchesToFeet = new InchesToFeet(inches);
        inchesToFeet.print();
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Convert the QuartsToGallons program to an interactive application. Instead of assigning a value to the number...
Convert the QuartsToGallons program to an interactive application. Instead of assigning a value to the number of quarts, accept the value from the user as input. class QuartsToGallonsInteractive {    public static void main(String[] args)    {          // Modify the code below       final int QUARTS_IN_GALLON = 4;       int quartsNeeded = 18;       int gallonsNeeded;       int extraQuartsNeeded;       gallonsNeeded = quartsNeeded / QUARTS_IN_GALLON;       extraQuartsNeeded = quartsNeeded % QUARTS_IN_GALLON;       System.out.println("A job that needs " + quartsNeeded +          " quarts requires " + gallonsNeeded + " gallons...
Write an application that asks a user to enter an integer. Display a statement that indicates...
Write an application that asks a user to enter an integer. Display a statement that indicates whether the integer is even or odd. ------------------------------------------ import java.util.Scanner; class EvenOdd {     public static void main(String[] args) {         // Write your code here     }     public static boolean isEven(int number) {     } }
Mention the concepts analyzed from the below given program and write the output. [0.5 M] class...
Mention the concepts analyzed from the below given program and write the output. [0.5 M] class Test { int a, b; Test(int i, int j) { a = i; b = j; } void meth(Test s) { s.a *= 2; s.b /= 2; } } class demo { public static void main(String args[]) { Test ob = new Test(15, 20); System.out.println("Before call: " + ob.a + " " + ob.b); ob.meth(ob); System.out.println("After call: " + ob.a + " " +...
Question: Squares. Write a program class named SquareDisplay that asks the user for a positive integer...
Question: Squares. Write a program class named SquareDisplay that asks the user for a positive integer no greater than 15. The program should then display a square on the screen using the character ‘X’. The number entered by the user will be the length of each side of the square. For example, if the user enters 5, the program should display the following:       XXXXX       XXXXX       XXXXX       XXXXX       XXXXX INPUT and PROMPTS. The program prompts for an integer as follows: "Enter...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
JAVA What values are stored in variables a and b in the code below? public class...
JAVA What values are stored in variables a and b in the code below? public class StackQuestion { public static void main(String[] args) { Stack s = new Stack(); s.push(1); s.push(2); s.push(3); s.pop(); s.pop(); s.push(4); s.push(5); s.pop(); s.pop(); int a = s.pop(); s.push(6); int b = s.pop(); } } What numbers are stored in variable a and b when the code below executes? public class QueueQuestion { public static void main(String[] args) { Queue s = new Queue(); s.enqueue(1); s.enqueue(2);...
4.2.2 Basic while loop with user input. JAVA Write an expression that executes the loop while...
4.2.2 Basic while loop with user input. JAVA Write an expression that executes the loop while the user enters a number greater than or equal to 0. Note: These activities may test code with different test values. This activity will perform three tests, with user input of 9, 5, 2, -1, then with user input of 0, -17, then with user input of 0 1 0 -1. See "How to Use zyBooks". Also note: If the submitted code has an...
We may expand the general strategy established in the prior question to determine whether a given...
We may expand the general strategy established in the prior question to determine whether a given number is divisible by another. Modify the program from the prior question or write one from scratch which determines whether 12345 is divisible by 15. public class Main {   public static void main( String[] args ) {     int myNumber = 12345; //15     int divisor = 15; //4     System.out.print( "(" + myNumber + ") is " );     if( myNumber%divisor==0) {       // Do nothing     }     else...
import java.util.Scanner; public class FindMinLength { public static int minLength(String[] array) { int minLength = array[0].length();...
import java.util.Scanner; public class FindMinLength { public static int minLength(String[] array) { int minLength = array[0].length(); for (int i = 0; i < array.length; i++) { if (array[i].length() < minLength) minLength = array[i].length(); } return minLength; } public static void main(String[] args) { Scanner in = new Scanner(System.in); String[] strings = new String[50]; for (int i = 0; i < strings.length; i++) { System.out.print("Enter string " + (i + 1) + ": "); strings[i] = in.nextLine(); } System.out.println("Length of smallest...
I am writing code in java to make the design below. :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) I already have...
I am writing code in java to make the design below. :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) I already have this much public class Main { int WIDTH = 0; double HEIGHT = 0; public static void drawSmileyFaces() { System.out.println(" :-):-):-):-):-):-)"); } public static void main (String[] args) { for (int WIDTH = 0; WIDTH < 3; WIDTH++ ) { for(double HEIGHT = 0; HEIGHT < 2; HEIGHT++) { drawSmileyFaces(); } } } } I am pretty sure that alot of this is wrong...