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.");
}
}
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."); } }
Get Answers For Free
Most questions answered within 1 hours.