Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am working on a Java project and need help with writing my final 2 classes, below is what I have so far and the

I am working on a Java project and need help with writing my final 2 classes, below is what I have so far and the criteria for the last 2 classes

BingoNumber

package bingo;

public class BingoNumber {

private int number; private boolean marked;

public BingoNumber (int num) { this.number = num; if (num == 0) marked = true; }

public int getNumber() { return number; }

public void mark() { this.marked = true; }

public boolean isMarked() { return this.marked; }

@Override public String toString() { if (this.isMarked()) { return "XX"; } else {

return ((this.number

}

public String toNumberString() { if (this.number != 0) return ((this.number

}

}

BingoCard

package bingo;

import java.util.ArrayList; import java.util.Random;

public class BingoCard {

private BingoNumber[][] card;

public BingoNumber[] getRandomColumn(int a) { int min = 0, max = 0; if (a == 0) { min = 1; max = 15; } else if (a == 1) { min = 16; max = 30; } else if (a == 2) { min = 31; max = 45; } else if (a == 3) { min = 46; max = 60; } else if (a == 4) { min = 61; max = 75; }

Random r = new Random();

ArrayList col = new ArrayList(); ArrayList column = new ArrayList(); for (int i = 0; i

}

BingoNumber[] returnVal = new BingoNumber[column.size()]; returnVal = (BingoNumber[]) column.toArray(returnVal); return returnVal;

}

public BingoCard () {

BingoNumber[][] cardTemp = new BingoNumber[5][5]; for (int i = 0; i

card = new BingoNumber[5][5]; for (int i = 0; i

private String printLine() {

return "+--+--+--+--+--+"; }

@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(" B I N G O"); sb.append(" " + printLine() + " "); for (int i = 0; i

return sb.toString(); }

public String toSideBySideString() { StringBuilder sb = new StringBuilder(); sb.append(" B I N G O "); sb.append("\t B I N G O "); sb.append(" " + printLine()); sb.append("\t" + printLine() + " "); for (int i = 0; i

return sb.toString(); }

public BingoNumber getNumber(int row, int column) { return card[row][column]; }

public boolean mark(int num) { int column = -1; boolean isMarked = false; if (num >= 1 && num = 16 && num = 31 && num = 46 && num = 61 && num

for (int i = 0; i

public static void main(String[] args) {

BingoCard b = new BingoCard(); System.out.println(b); b.getNumber(0, 0).mark(); b.getNumber(1, 0).mark(); b.getNumber(2, 0).mark(); b.getNumber(3, 0).mark();

for (int i = 1; i

}

BingoBall

package bingo;

public class BingoBall {

private int number;

public BingoBall (int number) { if (number >= 1 && number

public int getNumber() { return this.number; }

@Override public String toString() { return "" + number; }

}

BingoCage

package bingo;

import java.util.Random;

public class BingoCage {

BingoBall[] balls; int ballsLeft;

public int getBallsLeft() { return ballsLeft; }

public BingoCage () { balls = new BingoBall[75]; for (int i = 1; i

public BingoBall draw() { Random r = new Random(); BingoBall returnVal = null; int num = r.nextInt(75) + 1; while (balls[num - 1] == null) { num = r.nextInt(75) + 1; } returnVal = balls[num - 1]; balls[num - 1] = null; ballsLeft--; return returnVal; }

public void reset() { balls = new BingoBall[75]; for (int i = 1; i

public static void main(String[] args) {

BingoCage b = new BingoCage(); for (int i = 1; i

b.reset(); System.out.println(b.getBallsLeft()); } }

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Part IV: The BingoPlayer Class (30 Points) This class represents a Bingo player which has the following abilities . A player has his/her first and last name A player will have his/her initial amount of oney when he/she walks into a Bingo house . A player will have a hand that can hold any number of Bingo card. . A player can be ordered to pay for a number of Bingo cards . A player can receive a number of Bingo cards to put into his/her hand . A player can show his/her winning card(s) to the house to verify . A player can receive an amount of US Dollar if he/she wins a round. . A player can discard all Bingo cards from his/her hand This class wl be a little bit big. Here are implementation details . Constructor: -public BingoPlayer(String first, String last, double amount) constructs a Bingo player with with a given first name, last name, and the initial amount of money. Note that initially the hand of a Bingo player is empty (no Bingo cards) . Accessors: - public String getFullName ) returns the string representation of the full name ofa -public String getFull Info() returns the string representation of the full information -public String toString() returns a string representation of a Bingo player together Bingo player (first name a blank and last name) (full name and the current amount of money) of a Bingo player (see example below) with his/her Bingo cards in his/her hand The following code snippet below uses the first three accessors above where the setBingoCards () method will be discussed later: Person john -new Person ("John", "Smith", 50.0); BingoPlayer aPlayer nex BingoPlayer (john) System.out.println("getFullName ): "+aPlayer.getFullName()); System.out.println("getFullInfo O "+ aPlayer.getFullInfo)); System.out.println("-"); System.out.println(aPlayer); System-out . printin ( "===='') ; BingoCard [] cards= new BingoCard [3]; cards [0]-new BingoCardO; cards [1] new BingoCardO cards [2] = new BingoCard(); aPlayer.setBingoCards (cards); System.out.println(aPlayer); The above code snippet should give you the following output (Bingo cards will be dif ferent) getFullName (): John Smith getFullInfo) John Smith ($50.0) John Smith ($50.0) ingo Cards John Smith ($50.0) B I N G C B I N G O B I N G O 113|25137 56163 10129131152171 4119136 50174l 111221 XX149173 8123 1 XX156163 61251 XX1481681 | 8124140155175 61 17136153172 9128135157163l 15|27135 59167 2120144159 168 5127138151173 public boolean isBingo ) returns true or false whether the player has one or more winning card(s) public BingoCard[] getBingoCards returns an array of type BingoCard that are winning cards s method will be called by the host to verify whether the card(s) is the winning card(s) . Mutators: -public int remove (int amount) removes a given amount in US dollars from a Bingo playcr. Note that if the playcr has cnough fund, the rcturn valuc will be the cxact amount to remove. Otherwise, the return value will be the largest integer value that the player can play (the money that he/she has rounded down to integer). Do not forget that this method must adjust the amount of money that the player has - public void add(double amount) adds more money into the player's pocket -public void addBingoCards (BingoCard[] cards) adds Bingo cards into the player's hand in the form of an array of BingoCard. Note that the parameter is an array of type BingoCard. The size of the array must be exactly the number of Bingo cards that the player wants to buy (and have enough money) - public void marks (int number) marks all Bingo cards in the player's hand that con tain the given number public void clear () clears the player's hand which must be called before starting a new round of game Part V: The Bingo Class (35 Points) This will be the main class. Note that this class must utilize objects of classes discussed carlier (OOP). There are a lot of places that the program will as for user inputs. For simplicity, we assume that the user will always enter a valid (type and range) inputs. lhe Bingo program should perform the following: 1. Read the povided file named players.txt. Here is the content of the file: 50.00 10 James, Smith,50.0 Michael,Smith,50.0 Robert,Smith, 50.0 Maria, Garcia,50.0 David, Smith,50.0 Maria, Rodriguez,50.0 Mary,Smith,50.0 Maria,Hernandez,50.0 Maria,Martinez, 50.0 James, Johnson,50.0 The first line is a string representation of the amount of money the house currently has. The next line is a string representation of the number of players in the file. Each line (after the first line is organized as first,last,amount. Your job is to read this file and construct all BingoPlayer objects from this file and put it into cither an array or ArrayList Note that we will test your program with different player file. So, make sure you utilize the number of player listed in the file correctly. Next is to Sort the player in ascending order (first name then last name) and display all players on the console screen. Here is an example amount may be different) * Welcome to SCI Bingo House* These are all available players: 1. David Smith ($46.0) 2. James Johnson ($50.0) 3. James Smith ($50.0) 4. Maria Garcia ($50.0) 5. Maria Hernandez ($46.0) 6. Maria Martinez ($50.0) 7. Maria Rodriguez ($50.0) 8. Mary Smith ($52.0) 9. Robert Smith ($50.0) 10. Michael Smith ($50.0) 2. Ask cach Bingo player whether he/she wants to play in this round If the player says no (n) move on to the next player If the player says yes (y), ask how many Bingo cards (up to 4 cards) he/she wants to If the player says between 1 and 4, take the money from the player. Do not forget to check the amount of money in case the player does not have enough money. Then give the player the appropriate number of Bingo cards If no players wants to play in this round, just exit the program. Here is an example: David Smith, would you like to play this round? (y): y How many Bingo card would you like to buy? (1 - 4): 4 James Johnson, would you like to play this round? (y): n James Smith, would you like to play this round? (y): n Maria Garcia, would you like to play this round? (y): y How many Bingo card would you like to buy? (1 - 4) 4 Maria Hernandez, would you like to play this round? (y) n Maria Martinez, would you like to play this round? (y): n Maria Rodriguez, would you like to play this round? (y): y How many Bingo card would you like to buy? (1 4): 4 Mary Smith, would you like to play this round? (y): n Robert Smith, would you like to play this round? (y): n Michael Smith, would you like to play this round? (y): n 3. Make sure that the Bingo cage has all 75 balls (either reset the old object or construct a new one 1. Show the amount of money of the house, the amount of money in the pot, the list of ball numbers (should be epty at the beginning) and show only those players that are playing (togcther with his/hcr hand) in this round House: $62.0 Pot: $6.0 Balls: C] 1. David Smith ($42.0) B I N G C | 6127145157168 61191451471651 13123140153175 8122143 571651 | 4128137146162 101211381501671 8124135156171 61 19133151169 l | 7118| XXI55170 31241XXI571611 31 171XXI55167 21281XX148173 121 19138147172 8116136158163 1120138148161 1131271411531681 | 51 16136150173 11125135149172 5126142154163 11241401561 671 B I N G O B I N G O B I N G O Garcia (946.0)512614215435368, 11123137155168 10130135160166 114128133155164 11221411521621 7122132160166 7119137158175 10123145151168 I 31251371491741 | 1121XX151 1691 81261XX151174 41221XX 153172 8124lXXI 54166 101 16140153163 9116138153168 5127141160165 121291351591 68l 15 18133157171 6127142157164 121 16143147170 61201401511731 3. Maria Rodriguez ($46.0) B I N G B I N G O | 6120145157165 7128142160165 1126144151 166 151 161361461 62 | 5128131149 166 2126136156163 13124140157 74 1117134155168 | 11 171 XX I60173 41231XX151162 151 171XXI59167 113130IXXI601701 15 16134153 75 11129144154169 12123 43152165 12|271391521721 | 4127138150169 5118140158172 14125141156161 11120131151169l There is no winning card yet 5. There are two options from here; (1) draw one ball and check the output or (2) draw balls until a player gets a BINGO. So, ask the user: 1) Draw a ball, 2) Draw balls until Bingo: 7. Tel each player in this round to mark the number (ball's number) 8. Check each player in this round whether he/she have a winning card If a player has a winning card, go to step 9 (Draw a ball). Go to step 4 (but skip step 5) if the user chooses choice number 2 (Draw bals Bingo) 9. Show the winning card (side-by-side) on the console screen for the house to verify. Maria Rodriguez says this card is a winning card XXIXX136146 |XXI 151 161361461621 10 |XXI XX134155168 1117134155168l XXI 30 | XXI60 1XX 13130 1XX1601701 XX127139 521721 12127139 52172l XX 1 20131 1 XXIXXI 11120131151169 l These are balls that have been drawn so far in this round [25, 38, 71, 16, 22, 62, 18, 61, 51, 3, 49, 12, 13, 21, 45, 40, 1, 69, 7, 35, 54, 15, 50, 4, 70, 6, 19, 17, 11] Is it a winning card? (y): Note that answer y or n is not important here. It is just for us to double check your work 10. Give the amount of moncy in the pot to the winner 11. Update the file players.txt. For simplicity, just simply create the new file named players.txt to replace the old one but use exact same format 12. Go back to stop 1 An example of an output of a run can be found in the file output2.txt Submission The due date of this project is stated on the CourseWeb. Late submissions will not be accepted For this project, you have to submit the following files: BingoNumber.java BingoCard.java BingoBall.java * BingoCage.java e BingoPlayer.java * Bingo.java Zip them in to one file named project3.zip and submit the file project3.zip via CourseWeb. Part IV: The BingoPlayer Class (30 Points) This class represents a Bingo player which has the following abilities . A player has his/her first and last name A player will have his/her initial amount of oney when he/she walks into a Bingo house . A player will have a hand that can hold any number of Bingo card. . A player can be ordered to pay for a number of Bingo cards . A player can receive a number of Bingo cards to put into his/her hand . A player can show his/her winning card(s) to the house to verify . A player can receive an amount of US Dollar if he/she wins a round. . A player can discard all Bingo cards from his/her hand This class wl be a little bit big. Here are implementation details . Constructor: -public BingoPlayer(String first, String last, double amount) constructs a Bingo player with with a given first name, last name, and the initial amount of money. Note that initially the hand of a Bingo player is empty (no Bingo cards) . Accessors: - public String getFullName ) returns the string representation of the full name ofa -public String getFull Info() returns the string representation of the full information -public String toString() returns a string representation of a Bingo player together Bingo player (first name a blank and last name) (full name and the current amount of money) of a Bingo player (see example below) with his/her Bingo cards in his/her hand The following code snippet below uses the first three accessors above where the setBingoCards () method will be discussed later: Person john -new Person ("John", "Smith", 50.0); BingoPlayer aPlayer nex BingoPlayer (john) System.out.println("getFullName ): "+aPlayer.getFullName()); System.out.println("getFullInfo O "+ aPlayer.getFullInfo)); System.out.println("-"); System.out.println(aPlayer); System-out . printin ( "===='') ; BingoCard [] cards= new BingoCard [3]; cards [0]-new BingoCardO; cards [1] new BingoCardO cards [2] = new BingoCard(); aPlayer.setBingoCards (cards); System.out.println(aPlayer); The above code snippet should give you the following output (Bingo cards will be dif ferent) getFullName (): John Smith getFullInfo) John Smith ($50.0) John Smith ($50.0) ingo Cards John Smith ($50.0) B I N G C B I N G O B I N G O 113|25137 56163 10129131152171 4119136 50174l 111221 XX149173 8123 1 XX156163 61251 XX1481681 | 8124140155175 61 17136153172 9128135157163l 15|27135 59167 2120144159 168 5127138151173 public boolean isBingo ) returns true or false whether the player has one or more winning card(s) public BingoCard[] getBingoCards returns an array of type BingoCard that are winning cards s method will be called by the host to verify whether the card(s) is the winning card(s) . Mutators: -public int remove (int amount) removes a given amount in US dollars from a Bingo playcr. Note that if the playcr has cnough fund, the rcturn valuc will be the cxact amount to remove. Otherwise, the return value will be the largest integer value that the player can play (the money that he/she has rounded down to integer). Do not forget that this method must adjust the amount of money that the player has - public void add(double amount) adds more money into the player's pocket -public void addBingoCards (BingoCard[] cards) adds Bingo cards into the player's hand in the form of an array of BingoCard. Note that the parameter is an array of type BingoCard. The size of the array must be exactly the number of Bingo cards that the player wants to buy (and have enough money) - public void marks (int number) marks all Bingo cards in the player's hand that con tain the given number public void clear () clears the player's hand which must be called before starting a new round of game Part V: The Bingo Class (35 Points) This will be the main class. Note that this class must utilize objects of classes discussed carlier (OOP). There are a lot of places that the program will as for user inputs. For simplicity, we assume that the user will always enter a valid (type and range) inputs. lhe Bingo program should perform the following: 1. Read the povided file named players.txt. Here is the content of the file: 50.00 10 James, Smith,50.0 Michael,Smith,50.0 Robert,Smith, 50.0 Maria, Garcia,50.0 David, Smith,50.0 Maria, Rodriguez,50.0 Mary,Smith,50.0 Maria,Hernandez,50.0 Maria,Martinez, 50.0 James, Johnson,50.0 The first line is a string representation of the amount of money the house currently has. The next line is a string representation of the number of players in the file. Each line (after the first line is organized as first,last,amount. Your job is to read this file and construct all BingoPlayer objects from this file and put it into cither an array or ArrayList Note that we will test your program with different player file. So, make sure you utilize the number of player listed in the file correctly. Next is to Sort the player in ascending order (first name then last name) and display all players on the console screen. Here is an example amount may be different) * Welcome to SCI Bingo House* These are all available players: 1. David Smith ($46.0) 2. James Johnson ($50.0) 3. James Smith ($50.0) 4. Maria Garcia ($50.0) 5. Maria Hernandez ($46.0) 6. Maria Martinez ($50.0) 7. Maria Rodriguez ($50.0) 8. Mary Smith ($52.0) 9. Robert Smith ($50.0) 10. Michael Smith ($50.0) 2. Ask cach Bingo player whether he/she wants to play in this round If the player says no (n) move on to the next player If the player says yes (y), ask how many Bingo cards (up to 4 cards) he/she wants to If the player says between 1 and 4, take the money from the player. Do not forget to check the amount of money in case the player does not have enough money. Then give the player the appropriate number of Bingo cards If no players wants to play in this round, just exit the program. Here is an example: David Smith, would you like to play this round? (y): y How many Bingo card would you like to buy? (1 - 4): 4 James Johnson, would you like to play this round? (y): n James Smith, would you like to play this round? (y): n Maria Garcia, would you like to play this round? (y): y How many Bingo card would you like to buy? (1 - 4) 4 Maria Hernandez, would you like to play this round? (y) n Maria Martinez, would you like to play this round? (y): n Maria Rodriguez, would you like to play this round? (y): y How many Bingo card would you like to buy? (1 4): 4 Mary Smith, would you like to play this round? (y): n Robert Smith, would you like to play this round? (y): n Michael Smith, would you like to play this round? (y): n 3. Make sure that the Bingo cage has all 75 balls (either reset the old object or construct a new one 1. Show the amount of money of the house, the amount of money in the pot, the list of ball numbers (should be epty at the beginning) and show only those players that are playing (togcther with his/hcr hand) in this round House: $62.0 Pot: $6.0 Balls: C] 1. David Smith ($42.0) B I N G C | 6127145157168 61191451471651 13123140153175 8122143 571651 | 4128137146162 101211381501671 8124135156171 61 19133151169 l | 7118| XXI55170 31241XXI571611 31 171XXI55167 21281XX148173 121 19138147172 8116136158163 1120138148161 1131271411531681 | 51 16136150173 11125135149172 5126142154163 11241401561 671 B I N G O B I N G O B I N G O Garcia (946.0)512614215435368, 11123137155168 10130135160166 114128133155164 11221411521621 7122132160166 7119137158175 10123145151168 I 31251371491741 | 1121XX151 1691 81261XX151174 41221XX 153172 8124lXXI 54166 101 16140153163 9116138153168 5127141160165 121291351591 68l 15 18133157171 6127142157164 121 16143147170 61201401511731 3. Maria Rodriguez ($46.0) B I N G B I N G O | 6120145157165 7128142160165 1126144151 166 151 161361461 62 | 5128131149 166 2126136156163 13124140157 74 1117134155168 | 11 171 XX I60173 41231XX151162 151 171XXI59167 113130IXXI601701 15 16134153 75 11129144154169 12123 43152165 12|271391521721 | 4127138150169 5118140158172 14125141156161 11120131151169l There is no winning card yet 5. There are two options from here; (1) draw one ball and check the output or (2) draw balls until a player gets a BINGO. So, ask the user: 1) Draw a ball, 2) Draw balls until Bingo: 7. Tel each player in this round to mark the number (ball's number) 8. Check each player in this round whether he/she have a winning card If a player has a winning card, go to step 9 (Draw a ball). Go to step 4 (but skip step 5) if the user chooses choice number 2 (Draw bals Bingo) 9. Show the winning card (side-by-side) on the console screen for the house to verify. Maria Rodriguez says this card is a winning card XXIXX136146 |XXI 151 161361461621 10 |XXI XX134155168 1117134155168l XXI 30 | XXI60 1XX 13130 1XX1601701 XX127139 521721 12127139 52172l XX 1 20131 1 XXIXXI 11120131151169 l These are balls that have been drawn so far in this round [25, 38, 71, 16, 22, 62, 18, 61, 51, 3, 49, 12, 13, 21, 45, 40, 1, 69, 7, 35, 54, 15, 50, 4, 70, 6, 19, 17, 11] Is it a winning card? (y): Note that answer y or n is not important here. It is just for us to double check your work 10. Give the amount of moncy in the pot to the winner 11. Update the file players.txt. For simplicity, just simply create the new file named players.txt to replace the old one but use exact same format 12. Go back to stop 1 An example of an output of a run can be found in the file output2.txt Submission The due date of this project is stated on the CourseWeb. Late submissions will not be accepted For this project, you have to submit the following files: BingoNumber.java BingoCard.java BingoBall.java * BingoCage.java e BingoPlayer.java * Bingo.java Zip them in to one file named project3.zip and submit the file project3.zip via CourseWeb

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

Introductory Relational Database Design For Business With Microsoft Access

Authors: Jonathan Eckstein, Bonnie R. Schultz

1st Edition

1119329418, 978-1119329411

More Books

Students also viewed these Databases questions

Question

=+c) Show that C is perfect [A15].

Answered: 1 week ago