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.
// 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.");
}
}
// QuartsToGallonsInteractive.java
import java.util.Scanner;
class QuartsToGallonsInteractive1
{
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);
boolean valid = false;
String s;
while (!valid) {
try {
System.out.print("Enter quarts needed >> ");
s = input.nextLine();
quartsNeeded = Integer.parseInt(s);
valid = true;
} catch (Exception e) {
System.out.println("Invalid input");
}
}
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.");
}
}



you created an application named QuartsToGallonsInteractive that accepts a number of quarts from a user and...
Q: Create a version of the UnitConverter application to convert from inches to foot. Read the inches value from the user. A: import java.util.*; class UnitConverter{ public static void main(String[] args){ int inches; int foot; Scanner scan=new Scanner(System.in); System.out.println("Enter inches:"); inches=scan.nextInt(); System.out.println(inches/12+" feet and "+inches%12+" inches."); } } Q: Write a program that converts grams to pounds. (One pound equals 453.592 grams.) Read the grams value from the user as a floating point value. A: import java.util.*; class GramsToPounds{...
Complete the do-while loop to output 0 to countLimit. Assume the user will only input a positive number. import java.util.Scanner; public class CountToLimit { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int countLimit = 0; int printVal = 0; // Get user input countLimit = scnr.nextInt(); printVal = 0; do { System.out.print(printVal + " "); printVal = printVal + 1; } while ( /* Your solution goes here */ ); System.out.println(""); return; } }
I am getting an error from eclipse stating that: Exception in thread "main" java.lang.Error: Unresolved compilation problem: at EvenOdd.main(EvenOdd.java:10) I am unable to find what I can do to fix this issue. Can you please assist? My code is below: import java.util.InputMismatchException; import java.util.Scanner; public class EvenOdd { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Welcome to this Odd program!"); int userInput1 = input.nextInt(); } public...
1. Need help with a Java application that will compute tip amounts based on user input. Please let me know what else my code could use. My code is below and I need help formatting the output and calculating the amount paid by each person. Your application will: ask the user for a restaurant name, a waiter/waitress name, a bill amount and the number of people splitting the bill calculate 10%, 15% and 20% tips on the bill amount calculate...
5. Write a static method "f(n)" in the space provide, that returns O if n is even, and if n is odd, returns 1 or -1 according as n is greater than or less than 0. importjava.util.Scanner; public class Q_05 Your "f(n)" method: public static void main(String args[]) mana int n; Scanner input = new Scanner(System.in); System.out.print("Please enetrn: "); n=input.nextInt(); System.out.println(f(n)); "Method f(n)" 7. Write a static method "max" in the space provide, that returns the maximum value from 3...
The part in bold is giving me an error. Ther error is that I cant convert an int to a boolean. The program asks the user to input two integer values and determines whether the first is divisible (without a remainder) by the second import java.util.Scanner; public class CheckDivisible { int isDivisible(int dividend, int divisor) { if(dividend % divisor == 0) return 1; else return 0; } public static void main(String[] args) { int dividend = 0; int divisor =...
Modify the virtual translator program: virtual.java Modify it so it loops ten times asking the user for the ten virtual address from the work sheet we did the week before spring break. Once you have it working run it in a script command capturing the output. Make sure the script file has a .txt extension and upload the output. //Java Program import java.util.Scanner; public class virtual{ public static void main(String[] args){ int[] virtualAddressPace={2,1,6,0,4,3,-1,-1,-1,5,-1,7,-1,-1,-1,-1}; Scanner input = new...
Write a java programm that calculates the total of a retail sale should ask the user for the following: The retail price of the item being purchased The sales tax rate Once these items have been entered, the program should calculate and display the following: The sales tax for the purchase The total of the sale I tried doing it here. but it is not giving me the right answer. kindly help correct the errors. import java.util.Scanner; public class SalesTax...
1. Import file ReadingData.zip into NetBeans. Also, please
download the input.txt file and store it into an appropriate folder
in your drive.
a) Go through the codes then run the file and write the output
with screenshot (please make sure that you change the location of
the file) (20 points)
b) Write additional Java code that will show the average of all
numbers in input.txt file (10 points)
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import java.io.*; 1- * @author mdkabir...
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"); } }