Hi guys, please help me T_T
Here is what is SUPPOSED to happen:
Input Number >> 55
Output >> five-five
Input Number >> 790
Output >> seven-nine-zero
The red is just a system.err message
The green is user input into the Java console
The black is what the application is printing (system.out)
All I am able to produce is single digits and their cardinal outputs.
So, 5 --> five, 8 --> eight, and etc.
When I input numbers with multiple digits such as 425, I don't get any output at all.
My question is: How do I get my program to print multi-digit inputs?
Such as 415 --> four-one-five
Also, a dash is supposed to separate the strings.
Here is my code:
One last thing:
I asked my teacher for a HINT and all he said was... "Loop". Derp.
Here is what is SUPPOSED to happen:
Input Number >> 55
Output >> five-five
Input Number >> 790
Output >> seven-nine-zero
The red is just a system.err message
The green is user input into the Java console
The black is what the application is printing (system.out)
All I am able to produce is single digits and their cardinal outputs.
So, 5 --> five, 8 --> eight, and etc.
When I input numbers with multiple digits such as 425, I don't get any output at all.
My question is: How do I get my program to print multi-digit inputs?
Such as 415 --> four-one-five
Also, a dash is supposed to separate the strings.
Here is my code:
import java.util.Scanner;
public class Lab3
{
// instance variable
private Scanner scan;
private String cardString;
public static void main (String [] args)
{
Lab3 G = new Lab3();
G.printCardinals();
}
// Initializes the Scanner object for this Lab3 object.
public Lab3()
{
// create Scanner object
scan = new Scanner(System.in);
}
// get user input
// switch statement
// output cardinal number representation
public void printCardinals()
{
int enter;
boolean quit = false;
while (! quit)
{
//while (enter)
// prompt user
System.err.print("Input a number to get a cardinal number\n" +
"representation of your number.\n" +
"(Type any negative number to quit program): ");
int num = scan.nextInt();
// if user input is negative, exit program
if (num < 0)
{
quit = true;
System.err.println("Exiting program, bye!");
} // end if statement
String cardString = "";
// if num is not negative, run switch
switch (num)
{
case 0: cardString = "zero";
break;
case 1: cardString = "one";
break;
case 2: cardString = "two";
break;
case 3: cardString = "three";
break;
case 4: cardString = "four";
break;
case 5: cardString = "five";
break;
case 6: cardString = "six";
break;
case 7: cardString = "seven";
break;
case 8: cardString = "eight";
break;
case 9: cardString = "nine";
break;
} // end switch
// output cardinal numbers
System.out.println(cardString);
} // end while
} // end printCardinals method
} // end class
One last thing:
I asked my teacher for a HINT and all he said was... "Loop". Derp.