Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

So I wanted some of the players scores to be a little lower so that some of them can get to level rank 3 &

So I wanted some of the players scores to be a little lower so that some of them can get to level rank 3 & 4 rather than all of them be such a high score number . Is there any I can change my play() method to make that work ? Java

// player class

public class Player {

private String name;

private int score;

private String rank;

public Player()

{

this.name = "";

this.score = 0;

this.rank = "Level 1";

}

public Player(String name) {

this.name = name;

this.score = 0;

this.rank = "Level 1";

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getScore() {

return score;

}

public void setScore(int score) {

this.score = score;

}

public String getRank() {

return rank;

}

public void setRank(String rank) {

this.rank = rank;

}

public void play()

{

int loopPick = (int) ((Math.random() * (10 - 5)) + 5);

while(loopPick 10)

{

loopPick = (int) ((Math.random() * (10 - 5)) + 5);

}

for(int i = 0; i

{

int pick = (int) ((Math.random() * (10 - 5)) + 5);

while(pick 10)

{

pick = (int) ((Math.random() * (10 - 5)) + 5);

}

setScore(getScore() + pick);

}

}

public String decideRank()

{

String r = "";

if(getScore() >= 50)

r = "Level 1";

else if(getScore() >= 35 && getScore()

r = "Level 2";

else if(getScore() >= 20 && getScore()

r = "Level 3";

else if(getScore()

r = "Level 4";

setRank(r);

return r;

}

@Override

public String toString()

{

return("Player: " + getName() + " Score: " + getScore() + " Rank: " + decideRank());

}

}

// game class

public class Game {

private Player[] player;

public Game(Player[] player)

{

this.player = new Player[player.length];

for(int i = 0; i this.player.length; i++)

this.player[i] = player[i];

}

public void start()

{

System.out.println("------------------------------");

System.out.println("Game has started");

System.out.println("------------------------------");

System.out.println("");

for(int i = 0; i

{

if(player[i] != null)

{

player[i].play();

System.out.println("");

System.out.println(player[i]);

}

}

}

public void end()

{

System.out.println("Game Ended");

System.out.println("");

}

public Player decideWinner()

{

int max = player[0].getScore();

int index = 0;

for(int i = 0; i

{

if(player[i] != null && player[i].getScore() > max)

{

max = player[i].getScore();

index = i;

}

}

return player[index];

}

}

// driver

public class gameDriver {

public static void main(String[] args) {

Player[] player = new Player[4];

player[0] = new Player("Joe");

player[1] = new Player("Sam");

player[2] = new Player("Mary");

player[3] = new Player("Sue");

Game game = new Game(player);

game.start();

game.end();

Player winner = game.decideWinner();

System.out.println("The winner is: " + winner);

System.out.println("");

Player[] s1 = new Player[4];

s1[0] = new Player("ben");

s1[1] = new Player("jake");

s1[2] = new Player("rose");

s1[3] = new Player("mike");

Game game1 = new Game(s1);

game1.start();

game1.end();

Player winner1 = game1.decideWinner();

System.out.println("The winner is: " + winner1);

}

}

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Player:Sam Score: 60 Rank: Level 1 Player:Mary Score: 46 Rank: Level 1 Player:Sue Score:49 Rank: Level 1 Game Ended.. The winner is: Player:Joe Score: 61 Rank:Level 1 Game has started Player:ben Score:55 Rank: Level 1 Player:jake Score: 65 Rank:Level 1 Player: rose Score: 45 Rank: Level 1 Player: mike Score:41 Rank: Level 1 Game Ended... The winner is: Player:jake Score: 65 Rank:Level 1 Player.java X Game.java gameDriver.java 47e public void play() 48 { 49 int loopPick = (int) ((Math.random() * (10 - 5)) + 5); 50 while(loopPick 10) 51 { 52 loopPick = (int) ((Math.random() * (10 - 5)) + 5); 53 } 54 1 55 for(int i = 0; i 10) 59 { 60 pick= (int) ((Math.random() * (10 - 5)) + 5); 61 62 setScore(getScore() + pick); 63 64 } 65 668 public String decideRank() 67 68 String r = 69 if(getScore() >= 50) 70 r = "Level 1"; else if (getScore() >= 35 && getScore() = 20 && getScore() 18) 51 * (18 - 5)) + 5); Player.java X Game.java gameDriver.java 47e public void play() 48 49 int loopPick = (int) ((Math.random() * (10 - 5)) + 5); 50 while(loopPick 10) 51 { 52 LoopPick = (int) ((Math.random() * (10 - 5)) + 5); 53 } 54 55 for(int i = 0; i 10) 59 { 60 pick = (int) ((Math.random() * (10 - 5)) + 5); 61 62 setScore(getScore() + pick); 1 63 3 public String decideRank String r = if(getScore() >= 50) r = "Level 1"; else if(getScore() >= 35 && getScore() = 20 && getScore() max) { max = player[i].getScore(): index=1 42 43 44 45 46 return player(indexl; 48 49 50

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_2

Step: 3

blur-text-image_3

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

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Eric Redmond ,Jim Wilson

1st Edition

1934356921, 978-1934356920

More Books

Students also viewed these Databases questions