Results 1 to 2 of 2
- 11-12-2011, 09:36 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 49
- Rep Power
- 0
I'm not sue why this isn't working.
I am instantiating an object "list" from the Shopkeeper class. I'm trying to get the user to type in a specific item and then have a total that outputs the total of the items they purchased. (I'm learning Java on my own and believe I have the terminology correct.) Here is the code.
package dark.dominion;
import java.util.Scanner;
import java.lang.System;
public class Shopkeeper
{
public static void list(){
int rope = 1;
int bedroll = 3;
int rations = 2;
int total = 0;
String list = "";
System.out.println("Welcome to my shop. We have rope, a bedroll"
+ " and rations. Type the name of the items you want.");
Scanner keyboard = new Scanner(System.in);
list = keyboard.nextLine();
total = Integer.parseInt(list);
System.out.println("Your total is: " + total);
I am using netbeans and here are the error messages:
Exception in thread "main" java.lang.NumberFormatException: For input string: "bedroll"
at java.lang.NumberFormatException.forInputString(Num berFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.parseInt(Integer.java:527)
at dark.dominion.Shopkeeper.list(Shopkeeper.java:31)
at dark.dominion.DarkDominion.main(DarkDominion.java: 44)
Java Result: 1
BUILD SUCCESSFUL (total time: 10 seconds)
Thanks for any and all help!
Matt
- 11-12-2011, 10:19 PM #2
Similar Threads
-
Collisions are working & not working
By Jayayoh in forum Java 2DReplies: 1Last Post: 06-24-2011, 05:21 PM -
Why isn't this working?
By nickburris in forum New To JavaReplies: 14Last Post: 02-03-2011, 02:00 AM -
\n not working in GUI (working code, but \n isn't working)
By cc11rocks in forum New To JavaReplies: 2Last Post: 01-04-2011, 04:30 AM -
This Is Not Working.
By FatalSylence in forum New To JavaReplies: 8Last Post: 10-16-2010, 02:15 AM -
Java mail problem(working in intranet,but not working in iternet)
By sundarjothi in forum Advanced JavaReplies: 8Last Post: 05-28-2008, 07:00 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks