Question

Problem Statement: Mini Lottery. This mini lottery company caters to regular players and high rollers. It...

Problem Statement: Mini Lottery.

This mini lottery company caters to regular players and high rollers. It allows the regular players and the high rollers to add money to the jackpot. It can select a random set of players and awards them the jackpot money.

The app must repeatedly do the following:

         Display the list of players. Allow the user to (1) add a player (2) have one player add money to the jackpot (3) select one or more random players and award them the jackpot money (4) exit the app.   

Super class (abstract class)

Player:
data members –
private String name - The name of the player
private int purse - The amount of money the player has
private static double jackpot – Total money in play so far

Two subclasses, both extend Player

RegularPlayer:
instance variable–private double max – Maximum amount of money that the player can play
HighRoller:
instance variable– private double comp – an amount of money that the company credits the player with on each play

Required abstract method
void play(double amount): Declared in class Player; Implemented in RegularPlayer and HighRoller.

In class RegularPlayer:

  • play(double amount): If the amount parameter is less than or equal to 0, do nothing and return. If the amount parameter is greater than purse or greater than max, do nothing and return. If not, subtract the value of amount from purse and add the value of amount to jackpot.

In class HighRoller:

  • play(double amount): If the amount parameter is less than or equal to 0, do nothing and return. If the amount parameter is greater than purse, do nothing and return. If not, subtract the value of amount from purse, add the value of amount to jackpot, and add the value of comp to purse.

  • In the Tester class:

    • main():

    • Set up a single ArrayList of RegularPlayer objects and HighRoller objects. For a total of about 6 objects.

    • Have a menu with four options (1) add a player (2) have one player add money to the jackpot (3) select one or more random players and award them the jackpot money (4) exit the app. Hint - You may use a do...while loop and a switch statement

    • Display the array list to the user

    • If the user enters 1, add a new RegularPlayer or a new HighRoller object to the list. Use the add() method to add to the list.

    • If the user enters 2, ask them for the index of the player that wants to play and the amount of money that they want to play. Use the play() method.

    • If the user enters 3, generate a random number, winners, between 1 and the size of the list of players. Distribute the jackpot money evenly over winners players, and set jackpot to 0. For example, if winners = 4 and jackpot = $1000, pick 4 random players from the list and add $250 to the purse of each of these players.

    • If the user enters 4, terminate the program. Otherwise, take them back to the menu so they can make another selection.

Special Note: Please complete in Java using BlueJ and make the code as simple as possible. Please provide notes for understanding. Thank you.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Java code

/**
 * Super class (abstract class)
 */
public abstract class Player {
    //data members –
    protected String name;//- The name of the player
    protected int purse;// - The amount of money the player has
    protected static double jackpot;// – Total money in play so far
    //constructor

    public Player(String name, int purse) {
        this.name = name;
        this.purse = purse;
    }
    //abstract method
    public abstract void play(double amount);
    //getters

    public String getName() {
        return name;
    }

    public int getPurse() {
        return purse;
    }

    public static double getJackpot() {
        return jackpot;
    }
    //setters

    public void setName(String name) {
        this.name = name;
    }

    public void setPurse(int purse) {
        this.purse = purse;
    }

    public static void setJackpot(double jackpot) {
        Player.jackpot = jackpot;
    }

    @Override
    public String toString() {
        return "Player Name: "+name+" Amount in purse: $"+String.format("%d",purse)+" ";
    }
}

//============================================

public class RegularPlayer extends Player {
    /**
     * instance variable–private double max
     * – Maximum amount of money that the player can play
     */
    private double max;

    public RegularPlayer(String name, int purse, double max) {
        super(name, purse);
        this.max = max;
    }
    //getter and setter

    public double getMax() {
        return max;
    }

    public void setMax(double max) {
        this.max = max;
    }

    /**
     * If the amount parameter is less than or equal to 0,
     * do nothing and return. If the amount parameter
     * is greater than purse or greater than max, do nothing and return.
     * If not, subtract
     * the value of amount from purse and add the value of amount to jackpot.
     * @param amount
     */
    @Override
    public void play(double amount) {
        if(amount<=0)
            return;
        else if(amount>getPurse()|| amount>max)
            return;
        else
        {
            purse-=amount;
            jackpot+=amount;
        }
    }

    @Override
    public String toString() {
        return super.toString()+"Maximum amount of money to play game: $"+String.format("%.2f",max);
    }
}

//==========================================

public class HighRoller extends Player {
    /**
     * instance variable– private double comp –
     * an amount of money that the company credits the player with on each play
     */
    private double comp;


    //constructor

    public HighRoller(String name, int purse, double comp) {
        super(name, purse);
        this.comp = comp;
    }
    //getters and setter

    public double getComp() {
        return comp;
    }

    public void setComp(double comp) {
        this.comp = comp;
    }

    /**
     *  If the amount parameter is less than or equal to 0,
     *  do nothing and return. If the amount parameter is greater
     *  than purse, do nothing and return. If not,
     *  subtract the value of amount from purse,
     *  add the value of amount to jackpot,
     *  and add the value of comp to purse.
     * @param amount
     */
    @Override
    public void play(double amount) {
        if(amount<=0)
            return;
        else if(amount>getPurse())
            return;
        else
        {
           purse-=amount;
           jackpot+=amount;
           purse+=comp;
        }
    }

    @Override
    public String toString() {
        return super.toString()+" credit amount $"+String.format("%.2f",comp);
    }
}

//===========================================

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

public class Main {
    public static void main(String[] args)
    {
        /**
         * single ArrayList of RegularPlayer objects and HighRoller objects.
         * For a total of about 6 objects.
         */
        ArrayList<Player> players = new ArrayList<>();
        players.add(new RegularPlayer("Bob",200,100));
        players.add(new HighRoller("Jack",500,200));
        players.add(new RegularPlayer("Mike",450,300));
        /**
         * Have a menu with four options
         * (1) add a player (2) have one player add money to the jackpot (3) select one or more random players and award them the jackpot money (4) exit the app.
         * Hint - You may use a do...while loop and a switch statement
         */
        //To get random numbers
        Random random = new Random();
        int choice=0;
        Scanner input = new Scanner(System.in);
        boolean again=true;
        String name="";
        int purseAmount=0;
        int playerIndex=0;
        double maxAmount=0,creditAmount=0,playAmount=0;
        do {
            //Display the array list to the user
            displayPlayers(players);
            menu();

            choice =input.nextInt();
            switch (choice)
            {
                /**
                 * If the user enters 1, add a new
                 * RegularPlayer or a new HighRoller object to the list.
                 * Use the add() method to add to the list.
                 */
                case 1:
                    System.out.println("1.Regular user\n2. HighRoller User\nSelect your choice: ");
                    choice=input.nextInt();
                    input.nextLine();
                    if(choice==1)
                    {
                        System.out.print("Enter Name: ");
                        name =input.nextLine();
                        System.out.print("Enter purse amount: ");
                        purseAmount = input.nextInt();
                        System.out.print("Enter maximum Amount to play: ");
                        maxAmount = input.nextDouble();
                        players.add(new RegularPlayer(name,purseAmount,maxAmount));
                        System.out.println("Player created successfully..");
                    }
                    else if(choice==2)
                    {

                        System.out.print("Enter Name: ");
                        name =input.nextLine();
                        System.out.print("Enter purse amount: ");
                        purseAmount = input.nextInt();
                        System.out.print("Enter credit Amount to play: ");
                        creditAmount = input.nextDouble();
                        players.add(new HighRoller(name,purseAmount,creditAmount));
                        System.out.println("Player created successfully..");
                    }

                    else
                    {
                        System.out.println("Wrong choice...!!!");
                    }
                    break;
                /**
                 * If the user enters 2, ask them for the index of
                 * the player that wants to play
                 * and the amount of money that they want to play.
                 * Use the play() method.
                 */
                case 2:
                        System.out.print("Enter player index: ");
                        playerIndex = input.nextInt();
                        if(playerIndex>=players.size()||playerIndex<0)
                            System.out.print("This player number does not exist");
                        else
                        {
                            System.out.print("Enter amount of money to play game: $");
                            playAmount = input.nextDouble();
                            players.get(playerIndex).play(playAmount);
                        }
                    break;
                /**
                 * If the user enters 3,
                 * generate a random number, winners,
                 * between 1 and the size of the list of players.
                 * Distribute the jackpot money evenly over winners players,
                 * and set jackpot to 0. For example, if winners = 4
                 * and jackpot = $1000, pick 4 random players
                 * from the list and add $250 to the purse of each of these players.
                 */
                case 3:
                    int randomWinners = random.nextInt(players.size())+1;
                    System.out.println("There are total "+randomWinners+" players, who wins jackpot..");
                    double prizeMoney = Player.getJackpot()/randomWinners;
                    //get random winners from list
                    for (int i = 0; i < randomWinners; i++) {
                        int randomWinner = random.nextInt(players.size());
                        System.out.println(players.get(randomWinner).getName()+"\ngot jackpot of $"+String.format("%.2f",prizeMoney));
                        //add money to purse
                        double money = players.get(randomWinner).getPurse()+prizeMoney;
                        players.get(randomWinner).setPurse((int)money);
                    }
                    System.out.println("Congratulations to all winners........");
                    break;
                case 4:
                    again = false;
                    break;

                    default:
                        System.out.println("Wrong Choice... Try Again...");
                        break;
            }
        }while (again);

    }
    public static void menu()
    {
        System.out.println("(1) add a player \n(2) have one player add money to the jackpot" +
                " \n(3) select one or more random players and award them the jackpot money \n(4) exit the app" +
                "\nSelect an Option: ");
    }
    public static void displayPlayers(ArrayList<Player>players)
    {
        System.out.println("List of players: ");
        for (Player p:players
             ) {
            System.out.println(p);
        }
    }
}

//output

//If you need any help regarding this solution ........ please a comment ...... thanks

Add a comment
Know the answer?
Add Answer to:
Problem Statement: Mini Lottery. This mini lottery company caters to regular players and high rollers. It...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question: Write the Main class code for the following application. The first three classes are given...

    Question: Write the Main class code for the following application. The first three classes are given below. Lottery This lottery app allows users to sign up for an account, choose a random number or two, and then win a certain amount of money if their chosen number matches the number that the game draws. The house keeps the cash proceeds if nobody wins. The app must repeatedly do the following: Allow the user to (1) Add Player Account (2) Play...

  • Problem Statement: A company intends to offer various versions of roulette game and it wants you...

    Problem Statement: A company intends to offer various versions of roulette game and it wants you to develop a customized object-oriented software solution. This company plans to offer one version 100A now (similar to the simple version in project 2 so refer to it for basic requirements, but it allows multiple players and multiple games) and it is planning to add several more versions in the future. Each game has a minimum and maximum bet and it shall be able...

  • the card game Acey Deucey, which is also known by several other names. In general, the...

    the card game Acey Deucey, which is also known by several other names. In general, the game is played with three or more people that continue to gamble for a pot of money. The pot grows and shrinks depending on how much General description of the game ● Two cards are dealt face up to a player from a shuffled deck of cards. ○ If the face of each card is the same then the player adds $1 into the...

  • PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4...

    PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4 THE GAME STARTS 1=PLAY GAME, 2=SHOW GAME RULES, 3=SHOW PLAYER STATISTICS, AND 4=EXIT GAME WITH A GOODBYE MESSAGE.) PLAYERS NEED OPTION TO SHOW STATS(IN A DIFFERNT WINDOW-FOR OPTION 3)-GAME SHOULD BE rock, paper, scissor and SAW!! PLEASE USE A JAVA GRAPHICAL USER INTERFACE. MUST HAVE ROCK, PAPER, SCISSORS, AND SAW PLEASE This project requires students to create a design for a “Rock, Paper, Scissors,...

  • Need help with assignment This assignment involves simulating a lottery drawing. In this type of lottery...

    Need help with assignment This assignment involves simulating a lottery drawing. In this type of lottery game, the player picks a set of numbers. A random drawing of numbers is then made, and the player wins if his/her chosen numbers match the drawn numbers (disregarding the order of the numbers). More specifically, a player picks k distinct numbers between 1 and n (inclusive), as well as one bonus number between 1 and m (inclusive). "Distinct" means that none of the...

  • You will write a two-class Java program that implements the Game of 21. This is a...

    You will write a two-class Java program that implements the Game of 21. This is a fairly simple game where a player plays against a “dealer”. The player will receive two and optionally three numbers. Each number is randomly generated in the range 1 to 11 inclusive (in notation: [1,11]). The player’s score is the sum of these numbers. The dealer will receive two random numbers, also in [1,11]. The player wins if its score is greater than the dealer’s...

  • please answer "def turn_payouts(move_a, move_b):" in python. Notes Two players will face each other. They each...

    please answer "def turn_payouts(move_a, move_b):" in python. Notes Two players will face each other. They each decide independently to "cooperate" or "cheat". If they both cooperated, they each win two points. If they both cheated, nobody wins anything. one cheats, the cheater gets +3 and the cooperator loses a point. That wasn't very kind! One turn is defined as each player making a choice, and winning or losing some points as a result. Shared history against this player is available...

  • please answer "class playerexception(exception):" in python Notes Two players will face each other. They each decide...

    please answer "class playerexception(exception):" in python Notes Two players will face each other. They each decide independently to "cooperate" or "cheat". If they both cooperated, they each win two points. If they both cheated, nobody wins anything. one cheats, the cheater gets +3 and the cooperator loses a point. That wasn't very kind! One turn is defined as each player making a choice, and winning or losing some points as a result. Shared history against this player is available to...

  • You will implement 2 games, the Prisoner's Dilemma, The Stag Hunt and compare their results for...

    You will implement 2 games, the Prisoner's Dilemma, The Stag Hunt and compare their results for your report. After you finish implementing everything else, you will only need to change one function to make it a prisoner's dilemma or a stag hunt game 1) main.cpp: This is the driver program that sets up the game and plays it. This is where you will call functions to print the statistics. The required statistics is percentage of players using strategy 1 (cooperate...

  • I need that in Java CSCI 24000- Fall 2017 Assignment #3-Class-v Players Due: 10/9/2017 This third...

    I need that in Java CSCI 24000- Fall 2017 Assignment #3-Class-v Players Due: 10/9/2017 This third assignment will allow you to explore (by comparing and contrasting through construction and implementation) two different object-oncnted programman罨languages (C++ and Javal You will be creating tme scparate programs-onc written in C++ and on written in Java For this assignment, we are going to explore how we can use objects to build more expressive and cleaner programs. In honor of football season we are going...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT