JAVA design a menu driven program. creation and use of classes. use of composite
ID: 3908429 • Letter: J
Question
JAVA
design a menu driven program.
creation and use of classes.
use of composite classes.
use of arrays or arrayLists.
Program Specifications:
You are to DESIGN and WRITE Uncle Cleetis goes to Nevada program. This program will have multiple classes. The program will contain a SlotMachine, Player, Name, Date, TestClass, and possibly other classes.
A SlotMachine will have storage locations for name of slot, current slot balance, number of jack pots that have been paid out, how much the jackpot pays, the number of regular wins, the regular win payout, plus any other fields you consider necessary.
The Player will have a Name, dob, and moneyBalance.
The Name class will include first, middle initial, and last name.
The Date class will include month, day, and year.
You can have additional fields should you find it necessary.
The program will validate the date. The first name and last name and middle initial of a name will be in sentence case.
It will cost a play 1 dollar to play any slot machine. You will create Uncle Cleetis and allow the user to create up to another 50 players.
Standard rules, no money, no playing. You will create some type of menu system. Besides creating players and machines, the program will allow slot play.
Slot Play:
The player is selected from the list of current players.
If the player has at least one dollar
The user will select the slot machine from the list of slot machines.
After one play the same player can play the same machine again.
You will show the current player’s balance during the play.
You will show the result of the play.
Return to main menu.
You program will create at least three different slot machines, but you will allow the user to create another 47 machines if the user wants:
Lucky 7, hopper has 5,000 dollars, jackpot happened once every 10,000 plays, the jackpot pays 5,000 dollars, the regular payout happens once every 10 plays. The regular payout is 5 dollars.
Lucky Lotto, hopper has 55,000 dollars, jackpot happened once every 100,000 plays, the jackpot pays 75,000 dollars, the regular payout happens once every 50 plays. The regular payout is 25 dollars.
Purple People Eater, hopper has 1,000 dollars, jackpot happened once every 50 plays, the jackpot pays 40 dollars, the regular payout happens once every 5 plays. The regular payout is 2 dollars.
YOU CANNOT
Use global variables
Use goto statement(s)
Explanation / Answer
import java.util.*;
import java.io.*;
class SlotMachine {
String name;
int balance;
int jackpotPayoutPlays;
int jackpotPayoutAmount;
int regularPayoutPlays;
int regularPayoutAmount;
public SlotMachine(String n, int b, int jP, int jA, int rP, int rA){
name = n;
balance = b;
jackpotPayoutPlays = jP;
jackpotPayoutAmount = jA;
regularPayoutPlays = rP;
regularPayoutAmount = rA;
}
}
class Player {
Name name;
Date dob;
int moneyBalance;
public Player(Name n, Date d, int b){
name = n;
dob = new Date(d);
moneyBalance = b;
}
}
class Name {
String firstName;
char middleInitial;
String lastName;
public Name(String f, char m, String l){
firstName = f;
middleInitial = m;
lastName = l;
}
public String getName(){
return firstName + middleInitial + lastName;
}
}
class Date {
int month;
int day;
int year;
public Date(int m, int d, int y){
month = m;
day = d;
year = y;
}
public Date(Date d){
month = d.month;
day = d.day;
year = d.year;
}
}
class TestClass {
public static void main(String[] args){
int MAX_COUNT = 50;
SlotMachine[] machines = new SlotMachine[MAX_COUNT];
machines[0] = new Machine("Lucky 7", 5000, 10000, 5000, 10, 5);
machines[1] = new Machine("Lucky Lotto", 55000, 100000, 75000, 50, 25);
machines[2] = new Machine("Purple People Eater", 1000, 50, 40, 5, 2);
int machineCount = 3;
Player[] players = new Player[MAX_COUNT];
player[0] = new Player(new Name("Uncle", 'A', "Cleetis"), new Date(11, 7, 1981), 1000);
int playerCount = 1;
Scanner sc = new Scanner(System.in);
int ch = 1;
while(ch!=4){
System.out.println("Welcome");
System.out.println("Choose an option from the following");
System.out.println(" 1. Start game");
System.out.println(" 2. Create a player");
System.out.println(" 3. Create a slot machine");
System.out.println(" 4. Exit");
ch = sc.nextInt();
if(ch==1){
System.out.println("Choose a player");
for(int i=0;i<playerCount;i++){
if(players[i].moneyBalance < 1)
System.out.println(" " + i + ". " + players[i].name.getName());
}
int p = sc.nextInt();
System.out.println("Choose a slot machine");
for(int i=0;i<playerCount;i++){
System.out.println(" " + i + ". " + machines[i].name);
}
int m = sc.nextInt();
} else if(ch==2){
players[playerCount++] = new Player();
} else if(ch==3){
machines[machineCount++] = new Machine();
} else{
break;
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.