Question: Write TWO classes. Use the Player class from PP 1 and write another class that is meaningful to you. In the driver, you will create

  • Write TWO classes. Use the Player class from PP 1 and write another class that is meaningful to you.

  • In the driver, you will create objects of these classes, and manipulate them using two stacks, with one for each class.

  • You have to make sure you test all methods in the Stack class meaningfully.

  • You also have to make sure you test all methods in the two classes you have written while manipulating the objects using the Stack data structure, meaningfully.

  • In the Driver, you must test all methods in a self-documentary way. When the output is displayed, it should be self-explanatory. The reader should not have to look at your code to understand the output.

Player Class

package main;

//Player.java

import java.util.Random;

public class Player {

// instance variables

private String name;

private int score;

private String rank;

public Player() {

this.score = 0;

}

public Player(String name) {

this();

this.name = name;

}

// Accessors and Mutator

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getScore() {

return score;

}

// create random score

public void play() {

Random random = new Random();

for (int i=0; i

this.score += random.nextInt(10);

}

// decide the rand based on score

this.rank = decideRank();

}

// decide the rand based on score

public String decideRank(){

if (score >=50)

return "Level 1";

else if(score >= 30)

return "Level 2";

else if( score >= 20)

return "Level 3";

else

return "Level 4";

}

public String getRank() {

return rank;

}

@Override

public String toString() {

return "Player: " +name + " " +

"Score:" + score + " " +

"Rank: " + rank + " ";

}

}

Sample Output

 Write TWO classes. Use the Player class from PP 1 and
write another class that is meaningful to you. In the driver, you
will create objects of these classes, and manipulate them using two stacks,

Original stack of caus: Name: Kicty Breed: Tabby Age: 9 Name: Flurry Breed: Persian Age: 1 Name: Eurball Breed: Linx Age: 5 Current number of cats in the stack: 3 Current cat on top of stack: Name: Furball Bread: Linx Age: 5 Cats in stack speaking: Furball Speak: Meow! Fluffy Speak: Meow! Kitty Speak: Meow! Altered stack of cats: Name: Kitty Breed: Tabby Age: 3 Current number of cats in the stack: 1 Current cat on top of stack: Name : Kitty Breed: Tabby Age: 3 Stack cmpty true or talse): false Current number of cats in the stack: 0 Stock empty (tzue or folse): true P Consoles * * * tominated Stack Driver (0) Java Application Program FilesVavaljrel 80.101bir briginal stack of players: Name: Rex Score: 29 Rankt Level 3 Name: Christy Score: 13 Rank: Level 4 Name: Zane Score: 31 Rank: Level 2 Name: Cali Score: 39 Rank: Level 2 Current number of players in the stack 4 Current player on top of atack: Name Call Seore: 39 Rank Level 2 Altered stack of players: e Rex score! 29 Rank Level 3 Name Christy Score: 13 Rankt Level 4 Current number of players in the stack: 2 Current player on top of stack: NA! Christy Score! 13 Rank: Level 4 Stack empty (true or false): false Current number of players in the stack: 0 Stack empty fcrue or false): true Original stack of cats! 4 store 911 Creating first stack, to track players Peaking ot top of Stacki. exception. ElootyStackexceptions Stack is empty. No element to return Looks anpty. Let's double check, just in case true Yap, ampty. Let's odd core Players to it. Creating five Players. Pushing the five players on the stack Creating generic Players pl, P2, P3. Popping the top three Players on Stuck 1 into pl, p2, and p Arranging them in an array for easy looping- Using the play method on the player array via #loop, sad then puhtag them back to the stack. Taking a peek at the top of the stack, Susan 168 Level 2 How many players are in the stack, again? Printing out stack of players, Susan 168 Laval 2 Clara 233 Level 3 Daryl 158 Level 2 Shaun e Unranked Aaron Unranked Creating a second stack, to track Charecters. Peeking at top of stackz. exceptions for the certloo Stack is empty. No element to return Looks empty. Let's double check, just in case. true Yep, tmpty. Let's add sone Characters to it. Creating 1 Characters. Pushing the three characters on the stack. Creating a second stack, to track characters Peeking at top of stackz. exceptions. EmptyStackexception: Stack is empty. No element to return Looks empty. Let' double check, Just in case true Yep, empty. Let's add some Characters to it. Creating 3 Characters. Pushing the three characters on the stock. Printing out the stack real fast. Butane: Bef: Demon Hunter: 110 844 doav Nelf Warrior 100 712 Dracon Human: Paladin: 110 99% Let's see if they can all run Heroics. true false true Gaav can't? Ok. Let's put his back last. Let's make sure we did that right... Gev: N. Elf: Warrior: 188 712 ok, reprinting the stack one more time to make sure Gav! N. 017: Warrior: 100 712 Butone: B. Ulf: Demon Hunter: 116 944 Oracon Human Paladin: 110 997 I forgot, how many Players were in stack12 5 Original stack of caus: Name: Kicty Breed: Tabby Age: 9 Name: Flurry Breed: Persian Age: 1 Name: Eurball Breed: Linx Age: 5 Current number of cats in the stack: 3 Current cat on top of stack: Name: Furball Bread: Linx Age: 5 Cats in stack speaking: Furball Speak: Meow! Fluffy Speak: Meow! Kitty Speak: Meow! Altered stack of cats: Name: Kitty Breed: Tabby Age: 3 Current number of cats in the stack: 1 Current cat on top of stack: Name : Kitty Breed: Tabby Age: 3 Stack cmpty true or talse): false Current number of cats in the stack: 0 Stock empty (tzue or folse): true P Consoles * * * tominated Stack Driver (0) Java Application Program FilesVavaljrel 80.101bir briginal stack of players: Name: Rex Score: 29 Rankt Level 3 Name: Christy Score: 13 Rank: Level 4 Name: Zane Score: 31 Rank: Level 2 Name: Cali Score: 39 Rank: Level 2 Current number of players in the stack 4 Current player on top of atack: Name Call Seore: 39 Rank Level 2 Altered stack of players: e Rex score! 29 Rank Level 3 Name Christy Score: 13 Rankt Level 4 Current number of players in the stack: 2 Current player on top of stack: NA! Christy Score! 13 Rank: Level 4 Stack empty (true or false): false Current number of players in the stack: 0 Stack empty fcrue or false): true Original stack of cats! 4 store 911 Creating first stack, to track players Peaking ot top of Stacki. exception. ElootyStackexceptions Stack is empty. No element to return Looks anpty. Let's double check, just in case true Yap, ampty. Let's odd core Players to it. Creating five Players. Pushing the five players on the stack Creating generic Players pl, P2, P3. Popping the top three Players on Stuck 1 into pl, p2, and p Arranging them in an array for easy looping- Using the play method on the player array via #loop, sad then puhtag them back to the stack. Taking a peek at the top of the stack, Susan 168 Level 2 How many players are in the stack, again? Printing out stack of players, Susan 168 Laval 2 Clara 233 Level 3 Daryl 158 Level 2 Shaun e Unranked Aaron Unranked Creating a second stack, to track Charecters. Peeking at top of stackz. exceptions for the certloo Stack is empty. No element to return Looks empty. Let's double check, just in case. true Yep, tmpty. Let's add sone Characters to it. Creating 1 Characters. Pushing the three characters on the stack. Creating a second stack, to track characters Peeking at top of stackz. exceptions. EmptyStackexception: Stack is empty. No element to return Looks empty. Let' double check, Just in case true Yep, empty. Let's add some Characters to it. Creating 3 Characters. Pushing the three characters on the stock. Printing out the stack real fast. Butane: Bef: Demon Hunter: 110 844 doav Nelf Warrior 100 712 Dracon Human: Paladin: 110 99% Let's see if they can all run Heroics. true false true Gaav can't? Ok. Let's put his back last. Let's make sure we did that right... Gev: N. Elf: Warrior: 188 712 ok, reprinting the stack one more time to make sure Gav! N. 017: Warrior: 100 712 Butone: B. Ulf: Demon Hunter: 116 944 Oracon Human Paladin: 110 997 I forgot, how many Players were in stack12 5

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!