Question

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 plus " +

         extraQuartsNeeded + " quarts.");

   }

}

Homework Answers

Answer #1
import java.util.Scanner;

class QuartsToGallonsInteractive {
    public static void main(String[] args) {
        int QUARTS_IN_GALLON = 4;
        int quartsNeeded;
        int gallonsNeeded;
        int extraQuartsNeeded;

        Scanner in = new Scanner(System.in);
        System.out.print("Enter number of quarts needed: ");
        quartsNeeded = in.nextInt();

        gallonsNeeded = quartsNeeded / QUARTS_IN_GALLON;
        extraQuartsNeeded = quartsNeeded % QUARTS_IN_GALLON;
        System.out.println("A job that needs " + quartsNeeded +
                " quarts requires " + gallonsNeeded + " gallons plus " +
                extraQuartsNeeded + " quarts.");
    }
}

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
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");   } }
Consider the following Java program : public static void main (string args [ ]) { int...
Consider the following Java program : public static void main (string args [ ]) { int result, x ; x = 1 ; result = 0; while (x < = 10) { if (x%2 == 0) result + = x ; + + x ; } System.out.println(result) ; } } Which of the following will be the output of the above program? A. 35 B. 30 C. 45 D. 35 2. public static void main(String args[]) { int i =...
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) {     } }
Covert the following Java program to a Python program: import java.util.Scanner; /** * Displays the average...
Covert the following Java program to a Python program: import java.util.Scanner; /** * Displays the average of a set of numbers */ public class AverageValue { public static void main(String[] args) { final int SENTINEL = 0; int newValue; int numValues = 0;                         int sumOfValues = 0; double avg; Scanner input = new Scanner(System.in); /* Get a set of numbers from user */ System.out.println("Calculate Average Program"); System.out.print("Enter a value (" + SENTINEL + " to quit): "); newValue =...
Covert the following Java program to a Python program: import java.util.Scanner; /* Calculates and displays the...
Covert the following Java program to a Python program: import java.util.Scanner; /* Calculates and displays the area of a rectangle * based on the width and length entered by the user. */ public class RectangleArea2 {             public static void main(String[] args) { int length; //longer side of rectangle             int width; //shorter side of rectangle int area; //calculated area of rectangle Scanner input = new Scanner(System.in);                               System.out.print("Enter the length: ");            length = input.nextInt(); System.out.print("Enter...
question : Take the recursive Java program Levenshtein.java and convert it to the equivalent C program....
question : Take the recursive Java program Levenshtein.java and convert it to the equivalent C program. Tip: You have explicit permission to copy/paste the main method for this question, replacing instances of System.out.println with printf, where appropriate. You can get the assert function from assert.h. Try running the Java program on the CS macOS machines. You can compile and run the program following the instructions discussed in class. Assertions are disabled by default. You can enable assertions by running java...
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....
Rearrange the following lines to produce a program that prints an image of a truck facing...
Rearrange the following lines to produce a program that prints an image of a truck facing left. System.out.println("+~: | |"); System.out.println(" o oo oo "); public class Truck System.out.println( " /-+--------------+"); System.out.println("+---+--------------+"); public static void main(String[] args) { { } }
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*;...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener {     int count;     JButton button;     Clicker() {         super("Click Me");         button = new JButton(String.valueOf(count));         add(button);         button.addActionListener(this);         setSize(200,100);         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         setVisible(true);     }     public void actionPerformed(ActionEvent e) {         count++;         button.setText(String.valueOf(count));     }     public static void main(String[] args) { new Clicker(); } } a. add(button);...
JAVA -Consider this program: public class Main { public static void main(String[] args) { String s1...
JAVA -Consider this program: public class Main { public static void main(String[] args) { String s1 = new String("hello"); String s2 = "hello"; String s3 = "hello";    System.out.println(s1 == s3); System.out.println(s1.equals(s3)); System.out.println(s2 == s3); } } When we run the program, the output is: false true true Explain why this is the output, using words and/or pictures.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT