CSC Aggisment #5

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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