Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Perform JUnit test of this COMMUNITY CHEST class that extends SQUARE. This code is of game similar to monopoly. I have attached the community chest

Perform JUnit test of this COMMUNITY CHEST class that extends SQUARE. This code is of game similar to monopoly. I have attached the community chest code and square code.

import java.util.Random;public class CommunityChest extends Square { private String[] cards; Random rand = new Random(); public CommunityChest() { super(); cards = new String[10]; cards[0] = "Advance to Start"; cards[1] = "Banking Error, Award $200"; cards[2] = "Vet Fees, Take $50"; cards[3] = "Go To Jail"; cards[4] = "Get out of Jail Free Added"; cards[5] = "Tax man has come, Pay $30 for each Sanctuary"; cards[6] = "School Trip to your sanctuary, Award $100"; cards[7] = "Maintenance Fee, Take $100"; cards[8] = "One of your animals is in critical condition, Take $200"; cards[9] = "Draw another Card"; // TODO Auto-generated constructor stub } public String getSquareDetails() { String description = "You have landed on the community square"; return description; } public CommunityChest(int PositionID) { // TODO Auto-generated constructor stub } public String[] getCards() { return cards; } public void setCards(String[] cards) { this.cards = cards; } public void DrawCard(Player p) { int intRand = rand.nextInt(10); if(intRand == 0) { System.out.println(cards[intRand]); //p.goToStart(); } if(intRand == 1) { System.out.println(cards[intRand]); p.addMoney(200); } if(intRand == 2) { System.out.println(cards[intRand]); p.removeMoney(50); } if(intRand == 3) { System.out.println(cards[intRand]); //p.goToJail(); } if(intRand == 4) { System.out.println(cards[intRand]); p.addOutIfJail(); } if(intRand == 5) { System.out.println(cards[intRand]); p.addMoney(-(p.getProtectedAnimalList().size()*30)); } if(intRand == 6) { System.out.println(cards[intRand]); p.addMoney(100); } if(intRand == 7) { System.out.println(cards[intRand]); p.removeMoney(100); } if(intRand == 8) { System.out.println(cards[intRand]); p.removeMoney(200); } if(intRand == 9) { System.out.println(cards[intRand]); DrawCard(p); } }} abstract class Square { public abstract String getSquareDetails(); }

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

App Inventor

Authors: David Wolber, Hal Abelson

1st Edition

1449397484, 9781449397487

More Books

Students also viewed these Programming questions

Question

Identify two cost objects and three activities for Apple inc.

Answered: 1 week ago

Question

The domain of the variable in the expression x 3/x + 4 is________.

Answered: 1 week ago