I desperately need some help with the following.
I'm in my first year, studying Java, and we were asked to come up with a working slot machine.
I wrote the code, attached below, which is working. However, it needs to be in a JFrame, which I am really struggling with. And I also need some way to let the player continue on, without having the program close on them. At least until they enter 0 to quit.
I would really appreciate anyone's input.
Thanks lots,
import java.util.*;
import javax.swing.*;
public class SlotMachine {
public static void main(String[] args) {
System.out.println("Welcome to our Slot Machine\n\nRULES:\n\n"
+ "1. You can bet between 1 and 4 slot coins per spin\n"
+ "2. Each slot coin is worth €0.25\n"
+ "3. Enter 0 to close the slot machine\n"
+ "4. Have fun and Good luck!!\n\n");
int Bet;
Scanner input = new Scanner(System.in);
System.out.print("Please enter your bet from 1-4 here, or 0 to close : ");
Bet = input.nextInt();
while(Bet>4){
System.out.println("\nYou have not entered a valid bet.\n\nPlease try again :\n");
Bet = input.nextInt();
}
while(Bet<=0){
System.exit(0);
}
int a = (Bet*10);
int b = (Bet*7);
int c = (Bet*5);
int d = (Bet*3);
int e = Bet;
double Total1 = (a*0.25);
double Total2 = (b*0.25);
double Total3 = (c*0.25);
double Total4 = (d*0.25);
double Total5 = (e*0.25);
Random Shapes = new Random();
int combination = Shapes.nextInt(28);
switch (combination){
case 1:
System.out.println("\nBELL BELL BELL\n\nYou have won " + a + " slot coins\n"
+ "Total Winnings: €" + Total1 + "\nWell done!");
break;
case 2:
System.out.println("\nGRAPES GRAPES GRAPES\n\nYou have won " + b + " slot coins\n"
+ "Total Winnings: €" + Total2 + "\nWell done!");
break;
case 3:
System.out.println("\nCHERRY CHERRY CHERRY\n\nYou have won "+ c + " slot coins\n"
+ "Total Winnings: €" + Total3 + "\nWell done!");
break;
case 4:
System.out.println("\nCHERRY CHERRY BELL\n\nYou have won " + d + " slot coins\n"
+ "Total Winnings: €" + Total4 + "\nWell done!");
break;
case 5:
System.out.println("\nCHERRY CHERRY GRAPES\n\nYou have won " + d + " slot coins\n"
+ "Total Winnings: €" + Total4 + "\nWell done!");
break;
case 6:
System.out.println("\nCHERRY BELL CHERRY\n\nYou have won " + d + " slot coins\n"
+ "Total Winnings: €" + Total4 + "\nWell done!");
break;
case 7:
System.out.println("\nCHERRY GRAPES CHERRY\n\nYou have won " + d + " slot coins\n"
+ "Total Winnings: €" + Total4 + "\nWell done!");
break;
case 8:
System.out.println("\nBELL CHERRY CHERRY\n\nYou have won " + d + " slot coins\n"
+ "Total Winnings: €" + Total4 + "\nWell done!");
break;
case 9:
System.out.println("\nGRAPES CHERRY CHERRY\n\nYou have won " + d + " slot coins\n"
+ "Total Winnings: €" + Total4 + "\nWell done!");
break;
case 10:
System.out.println("\nCHERRY BELL GRAPES\n\nYou have won " + e + " slot coins\n"
+ "Total Winnings: €" + Total5 + "\nWell done!");
break;
case 11:
System.out.println("\nCHERRY GRAPES BELL\n\nYou have won " + e + " slot coins\n"
+ "Total Winnings: €" + Total5 + "\nWell done!");
break;
case 12:
System.out.println("\nBELL CHERRY GRAPES\n\nYou have won " + e + " slot coins\n"
+ "Total Winnings: €" + Total5 + "\nWell done!");
break;
case 13:
System.out.println("\nGRAPES CHERRY BELL\n\nYou have won " + e + " slot coins\n"
+ "Total Winnings: €" + Total5 + "\nWell done!");
break;
case 14:
System.out.println("\nGRAPES BELL CHERRY\n\nYou have won " + e + " slot coins\n"
+ "Total Winnings: €" + Total5 + "\nWell done!");
break;
case 15:
System.out.println("\nBELL GRAPES CHERRY\n\nYou have won " + e + " slot coins\n"
+ "Total Winnings: €" + Total5 + "\nWell done!");
case 16:
System.out.println("\nCHERRY BELL BELL\n\nYou have won " + e + " slot coins\n"
+ "Total Winnings: €" + Total5 + "\nWell done!");
break;
case 17:
System.out.println("\nCHERRY GRAPES GRAPES\n\nYou have won " + e + " slot coins\n"
+ "Total Winnings: €" + Total5 + "\nWell done!");
break;
case 18:
System.out.println("\nBELL CHERRY BELL\n\nYou have won " + e + " slot coins\n"
+ "Total Winnings: €" + Total5 + "\nWell done!");
break;
case 19:
System.out.println("\nBELL BELL CHERRY\n\nYou have won " + e + " slot coins\n"
+ "Total Winnings: €" + Total5 + "\nWell done!");
break;
case 20:
System.out.println("\nBELL BELL GRAPES\n\nSorry, you have not won anything on this occasion.");
break;
case 21:
System.out.println("\nBELL GRAPES BELL\n\nSorry, you have not won anything on this occasion.");
break;
case 22:
System.out.println("\nBELL GRAPES GRAPES\n\nSorry, you have not won anything on this occasion.");
break;
case 23:
System.out.println("\nGRAPES CHERRY GRAPES\n\nYou have won " + e + " slot coins\n"
+ "Total Winnings: €" + Total5 + "\nWell done!");
break;
case 24:
System.out.println("\nGRAPES BELL BELL\n\nSorry, you have not won anything on this occasion.");
break;
case 25:
System.out.println("\nGRAPES BELL GRAPES\n\nSorry, you have not won anything on this occasion.");
break;
case 26:
System.out.println("\nGRAPES GRAPES CHERRY\n\nYou have won " + e + " slot coins\n"
+ "Total Winnings: €" + Total5 + "\nWell done!");
break;
case 27:
System.out.println("\nGRAPES GRAPES BELL\n\nSorry, you have not won anything on this occasion.");
break;
default:
}
}
}
This post has been edited by Dogstopper: 21 November 2010 - 12:18 PM

New Topic/Question
Reply




MultiQuote





|