- Joined
- Apr 21, 2005
- Sythe Gold
- 5
- Messages
- 773
- Age
- 34
Hi. I made this today.. It is something nooby program I made which has three things you can do. Play 21, Eightball, and some chew thing that I got from a Java book. It is still a nooby program, but I am still learning Java. I just learned loops and U was trying to use them in the program.
NEVERMIND! Fixed it.
Code:
/**
* @(#)GoodOne.java
*
*
* @author
* @version 1.00 2007/11/18
*/
import java.util.Scanner;
import java.util.Random;
import static java.lang.System.out;
import java.io.PrintStream;
public class GoodOne {
public static void main(String[] args) {
Scanner myScanner = new Scanner(System.in);
Random myRandom = new Random();
int play;
out.print("Name: ");
out.println("Hello " + myScanner.nextLine() + " we are going to ask you something.");
out.println("Would you like to\n1. Play 21\n2. Eightball\n3. See how many times you have to chew before you swallow. ");
play = myScanner.nextInt();
if (play == 1) {
out.println("Okay.. 21 it is ");
int card;
int total = 0;
out.println("Card\tTotal");
while(total < 21) {
card = myRandom.nextInt(10) + 1;
total += card;
out.print(card);
out.print(" ");
out.println(total);
}
if (total == 21) {
out.println("Horray you win!");
} else
if (total > 21) {
out.println("You lose!");
}
}
if (play == 2) {
int randomNumbers = myRandom.nextInt(10) + 1;
out.println("Eightball it is!");
out.println("What is your question my child? ");
myScanner.nextLine();
out.println("Your question is " + myScanner.nextLine());
switch (randomNumbers) {
case 1:
out.println("Only time will tell.");
break;
case 2:
out.println("Yes, isn't it obvious!");
break;
case 3:
out.println("No way! Jose!");
break;
case 4:
out.println("Perhaps later!");
break;
case 5:
out.println("Maybe.. Just maybe!");
break;
case 6:
out.println("Does that reallly mater to you?");
break;
case 7:
out.println("Who knows..");
break;
case 8:
out.println("Take one step at a time young one.");
break;
case 9:
out.println("Only if you try harder!");
break;
case 10:
out.println("Leave me alone!");
break;
}
}
if (play == 3) {
int chew;
out.println("OK! 3 it is!");
out.print("How many times do you have to chew? ");
chew = myScanner.nextInt();
for (int count = 0; count < chew; count++) {
out.print("You have chewed ");
out.print(count);
out.println(" times!");
}
out.print(chew);
out.println(" times! Horray I can swallow now!");
}
if ( play != 1 && play != 2 && play != 3) {
out.println("Huh?");
}
}
}


