Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please do NOT use Hashmap, Treemap, map, or Arraylist..... Use only the basics of Java such as classes, loops, 2D Arrays, static attributes and static

Please do NOT use Hashmap, Treemap, map, or Arraylist.....

Use only the basics of Java such as classes, loops, 2D Arrays, static attributes and static methods. Please run the program and show me the result of the code at the end.

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

Part I) In this part, you need to create a class called LadderAndSnake. A LadderAndSnake object has a board of 10x10 and a number of players attached to it, which is initialized at the creation time of the object. For the scope of this assignment, the number of players will be limited to exactly 2 . However, since an extension can be easily achieved where more players can play the game, the number of players must be set through the use of a parameterized constructor of the class. However, if any parameter is passed with a different value than 2, and warning message should be displayed, and the number of players is set to 2 . If the value given to the paramterized constructor is less than 2 , the program terminates (see details below). The playing board itself is set as shown in Figure 1 below. As a strict requirement, you MUST create and the board and manipulate it as 2-D arrav. More than one 2-D array tcan be used to achieve what is needed. Figure 1: Ladder and Snake Board Besides the constructors, and all basic methods in the class, the class must include two methods, one called flipDice(0, which should return a random value between 1 and 6 inclusively. The other method is called play0, which actually initiate the core engine of the game where the players start to play the game. The rules of the game are as below: - The game will be played only by 2 players. - Before any of the players starts playing, the order of playing turns must be determined. For that, each player must throw the dice to obtain the largest possible number. In case of a tie between the players, the process is repeated until the order of playing is determined. You will need to keep track and report the number of attempts it took before the order was determined. - At this point, the players start playing the game by alternating dice flipping. - Each dice flip will move a player form square 0 (which you can think about it as outside the board) with the value of the dice. For example, if a player is at square 0 and the dice value was 5 , then the player moves to square 5. - If the reached square has a bottom of a ladder, then the player moves up to the square that has the top of the ladder. For instance, if a player is at square 33, and the flipped dice value was 3 , then the player moves to square 36, which in turn will end moving the player up to square 44 . - If the reached square has a head of a snake, then the player moves down the square that has the tail of the snake. For instance, if a player is at square 77, and the flipped dice value 2, then the player moves to square 79 (which has the tip of the snake's head), which in turn end moving the player down to square 19. You will have to find a way to record the relation between these particular ladder and snake squares. - The game is concluded once one of the players EXACTLY, reaches square 100. - If a player is close to 100 , and the dice value exceeds the maximum possible moves, the player moves backward with the excessive amount. For instance, if a player is at square 96 and the dice value is 5 , then the player moves to 99 (that is 4 moves to 100 , then 1 move backward to 99 ). As a general requirement, you must show/display ALL operations of the game. For instance, at start, you should indicate something like: - Game is played only by 2 players. - If the initialization attempted a different number that is >2, you should display the following warning: "Initialization was attempted for x member of players; however, this is only expected for an extended version the game. Value will be set to 2" (where x is the number of players attempted by the parameterized constructor); - If the number given as

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

Students also viewed these Databases questions

Question

2. What is the meaning and definition of Banking?

Answered: 1 week ago

Question

3.What are the Importance / Role of Bank in Business?

Answered: 1 week ago