Question

Java Convert the QuartsToGallons program to an interactive application. Instead of assigning a value to the...

Java

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.

Given program:

public class QuartsToGallons {
public static final int QUARTS_IN_GALLON = 4;

public static void main(String[] args) {
int quartsNeeded=18;
// finding required quarts
System.out.println("A job that needs " + quartsNeeded + " quarts requires " + (quartsNeeded/QUARTS_IN_GALLON) + " gallons plus "
+ (quartsNeeded % QUARTS_IN_GALLON) + " quarts");
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class QuartsToGallons {
    public static final int QUARTS_IN_GALLON = 4;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int quartsNeeded = scanner.nextInt();

        // finding required quarts
        System.out.println("A job that needs " + quartsNeeded + " quarts requires " + (quartsNeeded/QUARTS_IN_GALLON) + " gallons plus "
                + (quartsNeeded % QUARTS_IN_GALLON) + " quarts");
    }
}
Add a comment
Know the answer?
Add Answer to:
Java Convert the QuartsToGallons program to an interactive application. Instead of assigning a value to the...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using the latest version of Java JDK, Create a version of this TempConverter program to convert...

    Using the latest version of Java JDK, Create a version of this TempConverter program to convert from Fahrenheit to Kelvin. Read the Fahrenheit temperature from the user. public class TempConverter { //----------------------------------------------------------------- // Computes the Fahrenheit equivalent of a specific Celsius // value using the formula F = (9/5)C + 32. //----------------------------------------------------------------- public static void main (String[] args) { final intBASE = 32; final double CONVERSION_FACTOR = 9.0 / 5.0; double fahrenheitTemp; intcelsiusTemp= 24; // value to convert fahrenheitTemp= celsiusTemp*...

  • What display is produced by the execution of this JAVA program if we make the following...

    What display is produced by the execution of this JAVA program if we make the following call f(0,0). Please explain your answer public class function {    static void f(int x){        System.out.println(1);    }    static void f(double x){        System.out.println(2);    }    static void f(char x){        System.out.println(3);    }    static void f(long x){        System.out.println(4);    }    public static void main(String[] args) {       } }

  • Draw a UML class diagram (with associations) to show the design of the Java application. public...

    Draw a UML class diagram (with associations) to show the design of the Java application. public class OOPExercises {     public static void main(String[] args) {         //A objA = new A();         B objB = new B();         System.out.println("in main(): ");         //System.out.println("objA.a = "+objA.getA());         System.out.println("objB.b = "+objB.getB());         //objA.setA (222);         objB.setB (333.33);         //System.out.println("objA.a = "+objA.getA());         System.out.println("objB.b = "+objB.getB());     } } public class A {     int a = 100;     public A() {...

  • 1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program!...

    1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program! 3     public static void main(String[] args) { 4         System.out.println("Hello, World!"); 5     } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...

  • Java 1. Create an application named NumbersDemo whose main() method holds two integer variables. Assign values...

    Java 1. Create an application named NumbersDemo whose main() method holds two integer variables. Assign values to the variables. In turn, pass each value to methods named displayTwiceTheNumber(), displayNumberPlusFive(), and displayNumberSquared(). Create each method to perform the task its name implies. 2. Modify the NumbersDemo class to accept the values of the two integers from a user at the keyboard. This is the base code given: public class NumbersDemo { public static void main (String args[]) { // Write your...

  • Write a program that will check a Java file for syntax errors. The program will ask...

    Write a program that will check a Java file for syntax errors. The program will ask for an input-file name and output-file name and will then copy all the code from the Java input file to the Java output file, but with the following changes: 1. Any syntax error found in the Java input file will be corrected: a. Missing semicolon b. Missing compound statements (curly braces) c. All comments have to start with // and end with a period....

  • Predict the output of following Java program class T { int t= 20; T() { t...

    Predict the output of following Java program class T { int t= 20; T() { t = 40 } } class Main { public static void main(String args[]) {    T t1 = new T();    System.out.println(t1.t); } } a.20 b.Garbage value c.40 d.Compiler Error

  • Looking for some simple descriptive pseudocode for this short Java program (example italicized in bold directly...

    Looking for some simple descriptive pseudocode for this short Java program (example italicized in bold directly below): //Create public class count public class Count {     public static void main(String args[])     {         int n = getInt("Please enter an integer value greater than or equal to 0");                System.out.println("Should count down to 1");         countDown(n);                System.out.println();         System.out.println("Should count up from 1");         countUp(n);     }            private static void countUp(int n)     {...

  • JAVA HELP: Directions Write a program that will create an array of random numbers and output...

    JAVA HELP: Directions Write a program that will create an array of random numbers and output the values. Then output the values in the array backwards. Here is my code, I am having a problem with the second method. import java.util.Scanner; import java.util.Random; public class ArrayBackwards { public static void main(String[] args) { genrate(); print(); } public static void generate() { Scanner scanner = new Scanner(System.in);    System.out.println("Seed:"); int seed = scanner.nextInt();    System.out.println("Length"); int length = scanner.nextInt(); Random random...

  • Filename(s): ReformatCode. java Public class: ReformatCode Package-visible class(es): none Write a program that reformats Java source...

    Filename(s): ReformatCode. java Public class: ReformatCode Package-visible class(es): none Write a program that reformats Java source code from the next-line brace style to the end-of-line brace style. The program is invoked from the command line with the input Java source code file as args [0] and the name of the file to save the formatted code in as args [1]. The original file is left untouched. The program makes no other changes the source code, including whitespace. For example, the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT