0
amount = keyboard.nextInt();

Is this where you get the error when you enter: 15.75

What kind of data is acceptable to that method?

Have you read the API doc for the Scanner class and its methods?

Edited by NormR1: n/a

0

An integer (in real life, not just Java), is any number that basically has no decimal point (e.g. 7, 0, -4).

Clearly, 15.75 doesn't fit that definition, which is why you're getting an error.

0

your convert method takes an int, so you have to preserve your int type so you don't get a mismatch. your compiler expects amount to be an int and freaks out when it's not.

you can still have amount be a double at first and then just do some simple math operations to get the 15 and the 75 in 15.75 so your convert method works like it should. You don't need an array, you just need to call convert() once for the left side int and once for the right side int and then append them together.

I might do the following:

double amount = 15.75;

/*do some simple math that gets you the 15 and the 75 as ints*/

String leftSide = w.convert(leftSideInt);//since it takes an int
String rightSide = w.convert(rightSideInt);

append rightside and append leftside into the StringBuilder object like the rest

You do need to have the scanner accept input as a double though first, right?

Edited by brandonrunyon: n/a

0

Yup, still at it...

I am at the point now where I can enter in $15 and it will print fifteen dollars, but if I enter in $15.50, it prints fifty dollars. I know I need to get the two to go together and tried doing some things in append, but it's not working (surprise, surprise).

Here's my code for this section:

// Get amount of check from user
					System.out.print("Please enter amount of check: ");
					input = keyboard.nextLine();

					// Create StringTokenizer for dollar amount
					StringTokenizer da = new StringTokenizer(input, ".");

					String dollar;
					dollar = da.nextToken();
					amount = Integer.parseInt(dollar);

					// Create StringTokenizer for cent amount
					StringTokenizer ca = new StringTokenizer(input, ".");

					String cents;
					cents = da.nextToken();
					amount = Integer.parseInt(cents);

					// Test the amount

                	// Convert dollar amount to word amount
                	String inwords = w.convert(amount);
                	input=keyboard.nextLine();

                	// Create StringBuilder and append strings
					StringBuilder str = new StringBuilder();

					str.append("Date: " +date+ "\n"); 					// Append date
					str.append("Pay to the Order of: " +name+ "\n");	// Append payee
					str.append(nf.format(amount)+ "\n");				// Append amount
					str.append(" "); 									// Append word amount

					// Display output of check
					System.out.println(str);
                	System.out.println(inwords + "dollars");
0

I'm trying to get them both in there. I thought by doing concat written as:

amount = dollar.concat(cents);

would work, but it didn't.

0

amount = dollar.concat(cents);
You can't assign a String value: dollar.concat() to an int: amount.

You need to get two Strings, one with the dollar words and one with the cents words and then you can concatenate them.

Edited by NormR1: n/a

0

So here's how I'm trying to do this:

String input = ""; // To hold user's input
String date = ""; // To hold the date
String name = ""; // To hold the payee name
int amount = 0; // To hold amount of check

Num w = new Num(); // To hold written value of number

//Create a Scanner object to read input
Scanner keyboard = new Scanner(System.in);

//create Currency formater
NumberFormat nf = NumberFormat.getCurrencyInstance();

// Get date from user
System.out.print("Please enter the date: ");
date = keyboard.nextLine();

// Create StringTokenizer for date
StringTokenizer strTokenizer = new StringTokenizer(date, "/");

// Test the date

// Get the payee name from user
System.out.print("Please enter the payee name: ");
name = keyboard.nextLine();

// Test the payee name

// Get amount of check from user
System.out.print("Please enter amount of check: ");
input = keyboard.nextLine();

// Create StringTokenizer for dollar amount
StringTokenizer da = new StringTokenizer(input, ".");

String dollar;
dollar = da.nextToken();
amount = Integer.parseInt(dollar);

String dAmount = Integer.toString(dollar);

// Create StringTokenizer for cent amount
StringTokenizer ca = new StringTokenizer(input, ".");

String cents;
cents = da.nextToken();
amount = Integer.parseInt(cents);
String cAmount = Integer.toString(cents);

// Test the amount

// Convert dollar amount to word amount
String inwords = w.convert(amount);
input=keyboard.nextLine();
String strAmount;

//String strAmount = Integer.toString(strAmount);
strAmount = dollar + cents;

// Create StringBuilder and append strings
StringBuilder str = new StringBuilder();

str.append("Date: " +date+ "\n"); // Append date
str.append("Pay to the Order of: " +name+ "\n"); // Append payee
str.append(nf.format(amount)+ "\n"); // Append amount
str.append(" "); // Append word amount


// Display output of check
System.out.println(str);
System.out.println(inwords + "dollars");

// Exit system
System.exit(0);


When I try to compile it, I receive the following errors:

java:212: cannot find symbol
symbol : method toString(java.lang.String)
location: class java.lang.Integer
String dAmount = Integer.toString(dollar);

java:220: cannot find symbol
symbol : method toString(java.lang.String)
location: class java.lang.Integer
String cAmount = Integer.toString(cents);

What am I really missing here?

0

cannot find symbol
symbol : method toString(java.lang.String)

Read the API doc for the toString method. You are using it incorrectly.

Please post your code using code tags. Use the icon above to right of input area.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.