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");   } }
Modify the CountByFives application so that the user enters the value to count by. Start each...
Modify the CountByFives application so that the user enters the value to count by. Start each new line after 10 values have been displayed. (Cengage Mindtap assignment). This is the java code we are given: public class CountByAnything { // Modify the code below public static void main (String args[]) { final int START = 5; final int STOP = 500; final int NUMBER_PER_LINE = 50; for(int i = START; i <= STOP; i += START) { System.out.print(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) {     } }
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 =...
Modify the C# program to allow it to calculate the average of three numbers instead of...
Modify the C# program to allow it to calculate the average of three numbers instead of the sum. then submit your program to This Drop Box. C# Program: using System; class MainClass { public static void Main (string[] args) { Console.WriteLine ("Hello World"); } }
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 =...
Fix the program: what if the input is three? import java.util.Scanner public class Test { public...
Fix the program: what if the input is three? import java.util.Scanner public class Test { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter an integer: "); int m = in.nextInt(); System.out.print("Enter another integer: "); int n = in.nextInt(); System.out.println(m + " " + n); } }
/* Program Name: BadDate.java Function: This program determines if a date entered by the user is...
/* Program Name: BadDate.java Function: This program determines if a date entered by the user is valid. Input: Interactive Output: Valid date is printed or user is alerted that an invalid date was entered. */ import java.util.Scanner; public class BadDate { public static void main(String args[]) { // Declare variables Scanner userInput = new Scanner (System.in); String yearString; String monthString; String dayString; int year; int month; int day; boolean validDate = true; final int MIN_YEAR = 0, MIN_MONTH = 1,...
int a =12; a += 3; System.out.println(a); // What is the output of the above program?-----...
int a =12; a += 3; System.out.println(a); // What is the output of the above program?----- --------------- the Java keyword "new" accomplishes what? starts a new program gets input creates an object in memory refresh variable values ------------------------ Every Java Class MUST contain the main method: 'public static void main(String[]args)'   true/false
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT