Note that there are some explanatory texts on larger screens.

plurals
  1. POI can't figure out my simple Java homework
    primarykey
    data
    text
    <p>I have this programming assignment that converts between meters and feet, and between kilograms and pounds. When I tell the program I want to convert weight (by entering "w" when prompted), it gives me my the following error:</p> <blockquote> <p><code>Error: Too many input characters error.</code></p> </blockquote> <p>I worked on this for a long time, but can't figure it out. Can someone please tell me how to make the weight conversion work like the length conversion? </p> <pre><code>import java.util.Scanner; /** * This class.. */ public class UnitConversion3b { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String maxInputWarning = "\nError: Too many input characters." + "\nProgram is now terminating."; String lengthOrWeight; final double LENGTH_CONVERSION_FACTOR = 3.2808399; final double WEIGHT_CONVERSION_FACTOR = 2.20462; String whichWeightConversion = "empty" , whichLengthConversion = "empty"; double feet = 0, meters = 0, pounds =0 , kilograms = 0; double metersConvertedToFeet, feetConvertedToMeters; double poundsConvertedToKilograms, kilogramsConvertedToPounds; System.out.println(""); System.out.print("What kind of value would you like to convert?"); System.out.print("\nEnter L for length, or W for weight: "); lengthOrWeight = keyboard.nextLine(); if (lengthOrWeight.length() &gt; 1 ) { System.out.println(maxInputWarning); System.out.print("Press Enter to continue ... "); keyboard.nextLine(); return; } else if ((!(lengthOrWeight.equalsIgnoreCase("l")) &amp;&amp; (!(lengthOrWeight.equalsIgnoreCase("w"))))){ System.out.println("\nError: Unrecognized conversion type." + "\nProgram is now terminating."); System.out.print("Press Enter to continue ... "); keyboard.nextLine(); return; } else if (lengthOrWeight.equalsIgnoreCase("l")){ System.out.println("\nConverting feet or meters?"); System.out.print("Enter F to convert feet, or M for meters: "); whichLengthConversion = keyboard.nextLine(); } if (whichLengthConversion.length() &gt; 1 ) { System.out.println(maxInputWarning); System.out.print("Press Enter to continue ... "); keyboard.nextLine(); return; } else if ((!(whichLengthConversion.equalsIgnoreCase("f")) &amp;&amp; (!(whichLengthConversion.equalsIgnoreCase("m"))))){ System.out.println("\nError: Unrecognized unit of " + "measurement.\nProgram is now terminating." ); System.out.print("Press Enter to continue ... "); keyboard.nextLine(); return; } else if (whichLengthConversion.equalsIgnoreCase("f")){ System.out.print ("Enter the number of feet to" + " convert to meters: "); feet = keyboard.nextDouble(); feetConvertedToMeters = feet / LENGTH_CONVERSION_FACTOR; System.out.println("The number of meters in " + feet + " feet is " + feetConvertedToMeters + "."); keyboard.nextLine(); System.out.print("Press Enter to continue ... "); keyboard.nextLine(); return; } else if (whichLengthConversion.equalsIgnoreCase("m")){ System.out.print ("Enter the number of meters to" + " convert to feet: "); meters = keyboard.nextDouble(); metersConvertedToFeet = meters * LENGTH_CONVERSION_FACTOR; System.out.println("The number of feet in " + meters + " meters is " + metersConvertedToFeet + "."); keyboard.nextLine(); System.out.print("Press Enter to continue ... "); keyboard.nextLine(); return; } if (lengthOrWeight.equalsIgnoreCase("w")){ System.out.println("Converting pounds or kilograms?"); System.out.print("Enter P to convert pounds, or K for kilograms: "); whichWeightConversion = keyboard.nextLine(); } if (whichWeightConversion.length() &gt; 1 ) { System.out.println(maxInputWarning); System.out.print("Press Enter to continue ... "); keyboard.nextLine(); return; } else if ((!(whichWeightConversion.equalsIgnoreCase("p")) &amp;&amp; (!(whichWeightConversion.equalsIgnoreCase("k"))))){ System.out.println("\nError: Unrecognized unit of " + "measurement.\nProgram is now terminating." ); System.out.print("Press Enter to continue ... "); return; } else if (whichWeightConversion.equalsIgnoreCase("p")){ System.out.println("Enter the number of pounds to" + " convert to kilograms:"); pounds = keyboard.nextDouble(); poundsConvertedToKilograms = pounds / WEIGHT_CONVERSION_FACTOR; System.out.println("The number of pounds in " + kilograms + " kilograms is " + poundsConvertedToKilograms + "."); keyboard.nextLine(); System.out.print("Press Enter to continue ... "); keyboard.nextLine(); return; } else if (whichLengthConversion.equalsIgnoreCase("k")){ System.out.print ("Enter the number of kilograms to" + " convert to pounds: "); kilograms = keyboard.nextDouble(); kilogramsConvertedToPounds = kilograms * WEIGHT_CONVERSION_FACTOR; System.out.println("The number of pounds in " + pounds + "pounds is " + kilogramsConvertedToPounds + "."); keyboard.nextLine(); System.out.print("Press Enter to continue ... "); keyboard.nextLine(); return; } else{ return; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload