Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am working on an application that I need some help with. The program is supposed to simulate a casino with some specific requirements which

I am working on an application that I need some help with. The program is supposed to simulate a casino with some specific requirements which I will list below. However, I am running into some issues. In the main method whenever I enter a new customer's name it prompts me with:

"Exception in thread "main" java.util.InputMismatchException

at java.base/java.util.Scanner.throwFor(Unknown Source)

at java.base/java.util.Scanner.next(Unknown Source)

at java.base/java.util.Scanner.nextDouble(Unknown Source)

at project.main(project.java:361)"

Here is what I have for my program thus far (the class customer is commented out because I have it running as a different java file in my compiler.) Can anyone help me understand my error and help me make the last two games for the casino? (I need High Low & Seven Eleven)

Seven Eleven Instructions:

Seven-Eleven

The game is played with dice. The objective of the game is to roll a seven or an eleven first.

Gameplay as follows:

The user makes a bet, the casino matches the amount to create the pot

The user and the casino each roll 2 six-sided dice simultaneously. The sum of both die is that player's total

If a player rolls a 7 or 11 and the other does not, the player with the 7 or 11 wins

If neither player rolls a 7 or 11, roll again

If both players roll a 7 or if both players roll an 11, roll again

If one player rolls a 7 and the other rolls an 11, the one who rolled an 11 wins

The winner wins the pot and adds the money to their balance

High Low Instructions:

High Low

The game is played with cards. The rank of the cards from low to high is as follows: A,2,3,4,5,6,7,8,9,10, Jack, Queen, King. The objective of the game is to guess whether the next card is going to be higher or lower than the current card. Assume the casino is using one deck for High Low, so no duplicates of cards can be drawn in the same game

CURRENT PROGRAM CODE:

import java.util.*; //Applicaation

/*

You can create new customers

All new customers have a new customerID assigned to them, starting with 1 for the first, 2 for the second, 3 for the third, ect.

New customers have names and monetary balances

Default values are default customer for name and 1000 for balance

You can add or subtract from a customers balance

Customer balances cannot go below 0

You can change a customers name

You can display a customers name and his or her balance */ /* class Customer { double balance; String customername; Customer() { this.balance = 1000; this.customername = "default customer"; } public void createCustomer(String customername,double balance) { if(balance==0) { this.balance = 1000; } else this.balance = balance; if(customername == "") { this.customername = "default customer"; } else this.customername = customername;

} void addBalance(double balance) { this.balance += balance; } void subtractBalance(double balance) { if((this.balance == 0 ) || (this.balance - balance <= 0)) System.out.println("Customer Balance shouldn't 0 or lessthan that"); else this.balance -= balance; }

public void changeCustomerName(String name) { this.customername = name; } public void showCustomer() {

System.out.println("Customer Name : "+ customername); System.out.println("Customer Balance : "+ balance); }

/*

You can create a new casino

All new casinos have a new casinoID assigned to them, starting with 1 for the first, 2 for the second, 3 for the third, ect.

New casinos have names and monetary balances

Default values are default casino for name and 50000 for balance

You can add or subtract from a casinos balance

Casino balances cannot go below 0

Casinos offer 4 different games that customers can play

*/

//import java.util.*; import java.util.Scanner; import java.util.*; class Casino { private int casinoID; private String casinoName; private double casinobalance; double balance; String customername; Casino() { casinoID=0; } //Customer public void createCustomer(String customername,double balance) { if(balance==0) { this.balance = 1000; } else this.balance = balance; if(customername == "") { this.customername = "default customer"; } else this.customername = customername; } void addBalance(double balance) { this.balance += balance; } boolean subtractBalance(double balance) { boolean status =true; if((this.balance == 0 ) || (this.balance - balance <= 0)) { System.out.println("Customer Balance shouldn't 0 or lessthan that"); status =false; } else this.balance -= balance; return status; }

public void changeCustomerName(String name) { this.customername = name; } public void showCustomer() { System.out.println("Customer Name : "+ customername); System.out.println("Customer Balance : "+ balance); } //Casino public void createCasino(String casinoName,double casinobalance) { casinoID = casinoID+1; if(casinobalance==0) { this.casinobalance = 50000; } else this.casinobalance = casinobalance; if(casinoName == "") { this.casinoName = "default customer"; } else this.casinoName = casinoName; } void addcasinoBalance(double casinobalance) { this.casinobalance += casinobalance; } boolean subtractcasinoBalance(double casinobalance) { boolean status =true; if((this.casinobalance == 0 ) || (this.casinobalance - casinobalance <= 0)) { System.out.println("Casino Balance shouldn't 0 or lessthan that"); status = false; } else this.casinobalance -= casinobalance; return status; } public void changeCasinoName(String name) { if(subtractcasinoBalance(15000)) this.casinoName = name; else System.out.println("Insufficent funds to change casino name"); } void showGames() { System.out.println("Games List"); System.out.println("1) Twenty-one"); System.out.println("2) Slots"); System.out.println("3) High Low"); System.out.println("4) Seven-Eleven"); } public void showCasinoDetails() { System.out.println("Casino ID : "+ casinoID); System.out.println("Casino Name : "+ casinoName); System.out.println("Casino Balance : "+ casinobalance); } public void playGame() { showGames(); System.out.println("Select Game :"); Scanner in = new Scanner(System.in); int Option = in.nextInt(); switch(Option) { case 1: System.out.println("Select Game :"); Scanner in1 = new Scanner(System.in); int bet = in1.nextInt(); Random rand = new Random(); while(true) { int playerroll = rand.nextInt(11) + 1; int casinoroll = rand.nextInt(11) + 1; if((playerroll ==7 && casinoroll == 7) || (playerroll ==11 && casinoroll == 11) || (playerroll !=7 && casinoroll != 7) || (playerroll !=11 && casinoroll != 11)) { continue; } if((playerroll == 7 || playerroll == 11) && (casinoroll !=7 && casinoroll != 11)) { addBalance(bet); subtractcasinoBalance(bet); } else if(playerroll == 7 && casinoroll == 11) { addcasinoBalance(bet); subtractBalance(bet); } else if(playerroll ==11 && casinoroll == 7) { addBalance(bet); subtractcasinoBalance(bet); } System.out.println("Player : "+ playerroll); System.out.println("casino : "+ casinoroll); break; } break; case 2: System.out.println("Number of Spins : "); Scanner in2 = new Scanner(System.in); int noofspins = in2.nextInt(); addcasinoBalance(noofspins*5); if(subtractBalance(noofspins*5) == false) { System.out.println(" Insufficent Balance in customer... "); break; }

int count=0; int[] intArray = {1,9,20,70}; while(count < noofspins) { int idx = new Random().nextInt(intArray.length); int chance = intArray[idx]; int bal=0; switch(chance) { case 1: bal=1; break; case 9: bal= 5; break; case 20: bal= 10; break; case 70: bal= 100; break; } addBalance(bal); subtractcasinoBalance(bal); System.out.println(bal); } case 3: //sorry due lack of time i wasn't implement 3 and 4

System.out.println(" Game not supported... "); break; case 4:

System.out.println(" Game not supported... "); break; } }

}

public class project{

public static void main(String []args){ Casino obj=new Casino(); while (true){ System.out.println(" Casino System Application "); System.out.println("1) Create a new customer "); System.out.println("2) Create a new casino "); System.out.println("3) Change a customers name "); System.out.println("4) Change a casinos name "); System.out.println("5) Play games as a customer "); System.out.println("6) Display customer details "); System.out.println("7) Display casino details "); System.out.println("Select Option : "); Scanner in = new Scanner(System.in); int choice = in.nextInt(); switch(choice) {

case 1: System.out.println("Enter Customer Name : "); String custname= in.nextLine(); System.out.println("Enter Customer Balance : "); double custbal = in.nextDouble(); obj.createCustomer(custname,custbal); //obj.createCustomer("",0); // you can give user defined break; case 2: System.out.println("Enter Casino Name : "); String cname= in.nextLine(); System.out.println("Enter Casino Balance : "); double cbal = in.nextDouble(); obj.createCasino(cname,cbal); //obj.createCasino("",0); //default casino creation break; case 3: System.out.println("Enter Customer Name : "); String name= in.nextLine(); obj.changeCustomerName(name); break; case 4: System.out.println("Enter Casion Name : "); String name1= in.nextLine(); obj.changeCasinoName(name1);

break; case 5: obj.playGame(); break; case 6: obj.showCustomer(); break; case 7: obj.showCasinoDetails(); break; case 8: break; } /* class Customer { double balance; String customername; Customer() { this.balance = 1000; this.customername = "default customer"; } public void createCustomer(String customername,double balance) { if(balance==0) { this.balance = 1000; } else this.balance = balance; if(customername == "") { this.customername = "default customer"; } else this.customername = customername;

} void addBalance(double balance) { this.balance += balance; } void subtractBalance(double balance) { if((this.balance == 0 ) || (this.balance - balance <= 0)) System.out.println("Customer Balance shouldn't 0 or lessthan that"); else this.balance -= balance; }

public void changeCustomerName(String name) { this.customername = name; } public void showCustomer() {

System.out.println("Customer Name : "+ customername); System.out.println("Customer Balance : "+ balance); } */ }}}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Navigating The Supply Chain Maze A Comprehensive Guide To Optimize Operations And Drive Success

Authors: Michael E Kirshteyn Ph D

1st Edition

B0CPQ2RBYC, 979-8870727585

More Books

Students also viewed these Databases questions