0% found this document useful (0 votes)
30 views3 pages

CSC Aggisment #5

This document contains the code for a slot machine game simulation program. The program uses random number generation to simulate spinning reels on a slot machine. It tracks the user's coin total and allows them to play multiple rounds, winning coins if the reels match. The program outputs a welcome message and prompts the user to insert a coin or quit each round, displays the reel results, updates the coin count accordingly, and asks if the user wants to play again. After gameplay it prints the user's total coins won.

Uploaded by

kotisekhan10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views3 pages

CSC Aggisment #5

This document contains the code for a slot machine game simulation program. The program uses random number generation to simulate spinning reels on a slot machine. It tracks the user's coin total and allows them to play multiple rounds, winning coins if the reels match. The program outputs a welcome message and prompts the user to insert a coin or quit each round, displays the reel results, updates the coin count accordingly, and asks if the user wants to play again. After gameplay it prints the user's total coins won.

Uploaded by

kotisekhan10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

CSC 109- Spring 2023

College of New Caledonia

Lab Assignment # 07
Name - Manpreet Singh
Student ID -0164720
Submission Date - 15-03-2023
Input:

import java.util.Scanner;

import java.util.Random;

public class SlotMachineGame {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

Random random = new Random();

int coins = 0;

boolean playAgain = true;

System.out.println("Welcome to the slot machine game!");

do {

System.out.println("Insert a coin by typing 'C' and pressing Enter, or press any other key to
quit.");

String userInput = scanner.nextLine();

if (userInput.equals("C")) {

int wheel1 = random.nextInt(3) + 1;

int wheel2 = random.nextInt(3) + 1;

int wheel3 = random.nextInt(3) + 1;

System.out.println("Spinning the wheels...");


CSC 109- Spring 2023
College of New Caledonia

System.out.println(wheel1 + " " + wheel2 + " " + wheel3);

if (wheel1 == wheel2 && wheel2 == wheel3) {

System.out.println("Congratulations! You won 4 coins!");

coins += 4;

} else if (wheel1 == wheel2 || wheel2 == wheel3 || wheel1 == wheel3) {

System.out.println("Congratulations! You won 2 coins!");

coins += 2;

} else {

System.out.println("Sorry, you lost this round.");

} else {

playAgain = false;

if (playAgain) {

System.out.println("You now have " + coins + " coins. Would you like to play again? (Y/N)");

String playAgainInput = scanner.nextLine();

if (!playAgainInput.equalsIgnoreCase("Y")) {

playAgain = false;

} while (playAgain);

System.out.println("Thank you for playing the slot machine game! You won a total of " + coins + "
coins.");

}
CSC 109- Spring 2023
College of New Caledonia

OUTPUT :

Welcome to the slot machine game!

Insert a coin by typing 'C' and pressing Enter, or press any other key to quit.

Thank you for playing the slot machine game! You won a total of 0 coins.

You might also like