This is the question -  In Chapter 2, you created an application named QuartsToGallonsInteractive that accepts a number of quarts from a user and converts the value to gallons. Now, add exception-handling capabilities to this program and continuously reprompt the user while any nonnumeric value is entered. Code I was given -  // QuartsToGallonsInteractive.java import java.util.Scanner; class QuartsToGallonsInteractive {       public static void main(String[] args)     {         final int QUARTS_IN_GALLON = 4;       int quartsNeeded = 18;       int gallonsNeeded;       int extraQuartsNeeded;       Scanner input = new Scanner(System.in);       System.out.print("Enter quarts needed >> ");       quartsNeeded = input.nextInt();       gallonsNeeded = quartsNeeded / QUARTS_IN_GALLON;       extraQuartsNeeded = quartsNeeded % QUARTS_IN_GALLON;       System.out.println("A job that needs " + quartsNeeded +          " quarts requires " + gallonsNeeded + " gallons plus " +          extraQuar

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter12: Exception Handling
Section: Chapter Questions
Problem 3PE
icon
Related questions
Question

This is the question - 

In Chapter 2, you created an application named QuartsToGallonsInteractive that accepts a number of quarts from a user and converts the value to gallons. Now, add exception-handling capabilities to this program and continuously reprompt the user while any nonnumeric value is entered.

Code I was given - 

// QuartsToGallonsInteractive.java
import java.util.Scanner;
class QuartsToGallonsInteractive
{   
   public static void main(String[] args) 
   {  
      final int QUARTS_IN_GALLON = 4;
      int quartsNeeded = 18;
      int gallonsNeeded;
      int extraQuartsNeeded;
      Scanner input = new Scanner(System.in);
      System.out.print("Enter quarts needed >> ");
      quartsNeeded = input.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.");
   }
}
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Exception Handling Keywords
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,