Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here is my code: Down towards the bottom, I would like it if I select 1, I would

ID: 669636 • Letter: H

Question

Here is my code:
Down towards the bottom, I would like it if I select 1, I would go to the Slot Machine Class or 2, BlackJack Class. Who would I do this?  Should I just put the two games in the below class and not have 3 classes?

================================
import java.util.Scanner;
import java.text.DecimalFormat;

public class Casino
{
public static void main(String[] args)
{
  String user;
  double deposit;
  double actBalance;
  int choice;
  final double MIN_BAL = 20;
  final double MAX_BAL = 1000;
  
  DecimalFormat formatter = new DecimalFormat("#,##0.00");
  Scanner keyboard=new Scanner(System.in);
  
  TheBank balance = new TheBank();
    
  System.out.println("");
  System.out.println("Enter your name.");
  user=keyboard.nextLine();
  
  System.out.println("");
  System.out.println("Enter your deposit.");
  deposit=keyboard.nextDouble();
  
  while (deposit < MIN_BAL || deposit > MAX_BAL )
   
   {
   System.out.println("");
   System.out.println("Your deposit has to be between $20.00 - $1000. Please reenter.");
   deposit=keyboard.nextDouble();
   }

  System.out.println("");
  //System.out.println("Sending to Bank:");
  balance.setBalance(deposit);
  
  System.out.println("Your Balance: $" + formatter.format(balance.getBalance()));
  
  System.out.println("");
  System.out.println("Choose your Option: 1 for Slot Machine. 2 for Black Jack. 3 to Leave Casino");
  choice=keyboard.nextInt();
  
  if (choice == 1)
    
}

}

Explanation / Answer

yes you can do that.

You can create the objects of the class once you have the corresponding choice.

example

  if (choice == 1)

{

create the object of the slot machine here

slotmachine obj = new slotmachine();

and then call the corresponding functions on that.

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote