Hey guys,
So I'm on the second last question of my latest homework assignment and I can not figure out what is wrong. Basically it asks you to input a date, name, amount and then prints out a check, with a word form of the name on the bottom. Well, I'm just trying to get the word form working and im trying to compare characters and its not working, I'm not sure how else to do this! I tried .equals but that failed miserably, with errors.
import java.util.*;
public class CH9Q7
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int month, year, day;
String name;
double amount;
/*
System.out.println("Please enter the month\n1.January\n2.February\n3.March\n4.April\n5.May\n6.June\n7.July\n8.August\n9.September\n10.October\n11.November\n12.December\n Enter the number of the month(1-12)");
month=keyboard.nextInt();
System.out.println("Please enter the day:");
day=keyboard.nextInt();
System.out.println("Please enter the year:");
year=keyboard.nextInt();
keyboard.nextLine();
System.out.println("Enter the name of the person:");
name=keyboard.nextLine();
System.out.println("Please enter the amount the cheque is for: $");
amount = keyboard.nextDouble();
*/
month=5;
day=25;
year=2008;
name="Joe Smith";
amount = 1920.85;
System.out.println("\t\t\t\t\t\t"+month+"/"+day+"/"+year);
System.out.println("Pay to the Order of:\t"+name+"\t\t$"+amount);
System.out.println(amountString(amount));
}
public static String amountString(double amount)
{
int count=0;
String str = Double.toString(amount);
String wordNums="!Unkown!";
if(str.length()>6)
{
wordNums=singularName(str.charAt(0))+"thousand";
System.out.println(str.charAt(0));
}
return wordNums;
}
public static String pluralName(char num)
{
String pluralName;
if(num=='1')
pluralName="Ten";
if(num=='2')
pluralName="Twenty";
if(num=='3')
pluralName="Thirty";
if(num=='4')
pluralName="Forty";
if(num=='5')
pluralName="Fifty";
if(num=='6')
pluralName="Sixty";
if(num=='7')
pluralName="Seventy";
if(num=='8')
pluralName="Eighty";
if(num=='9')
pluralName="Ninety";
else
pluralName="Error /w Plural Method";
return pluralName;
}
public static String singularName(char num)
{
String singleName;
if(num=='1');
singleName="One";
if(num=='2')
singleName="Two";
if(num=='3')
singleName="Three";
if(num=='4')
singleName="Four";
if(num=='5')
singleName="Five";
if(num=='6')
singleName="Six";
if(num=='7')
singleName="Seven";
if(num=='8')
singleName="Eight";
if(num=='9')
singleName="Nine";
else
singleName="Error /w Singular Method";
return singleName;
}
}
All ideas are appreciated! I have been working on this question for a couple of hours now and I can't get it!