Question
I wanted to create the output shown in one of the pictures shown but not sure where to start . Im not sure if my
I wanted to create the output shown in one of the pictures shown but not sure where to start . Im not sure if my programming is right to get the output shown . Is there anyway to help compile my code? using the player class
code :
public class ArrayStack
private int top;
private T [] stack;
private final static int DEFAULT_CAP = 3;
public ArrayStack (int size) {
stack = (T[]) (new Object [size]);
top = 0;
}
public ArrayStack() {
this (DEFAULT_CAP);
}
@Override
public void push(T element) {
if (stack.length == top) {
expandCapacity();
}
stack [top] = element;
top++;
}
private void expandCapacity() {
}
@Override
public T pop() throws StackException {
return null;
}
@Override
public T peek() throws StackException {
return null;
}
@Override
public int size() {
return 0;
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}
}
public interface StackInterface
public void push(T element);
public T pop() throws StackException;
public T peek() throws StackException;
public int size();
public boolean isEmpty();
public String toString();
}
public class Player {
// creating variables
private String playersName;
private int score;
private String rank;
// players methods
public Player()
{
this.playersName = "";
this.score = 0;
this.rank = "Level 1";
}
public Player(String name) {
this.playersName = name;
this.score = 0;
this.rank = "Level 1";
}
//accessors
public String getName() { return playersName;}
public int getScore() {return score;}
public String getRank() { return rank;}
//mutators
public void setName(String name) { this.playersName = name;}
public void setScore(int score) { this.score = score;}
public void setRank(String rank) { this.rank = rank;}
public void play()
{
// generating a random number for players score
setScore((int)(Math.random() * 100 % 70));
}
//deciding rank of player depending on score
public String decideRank()
{
String rank = "";
if(getScore() >= 50)
rank = "Level 1";
else if(getScore() >= 35 && getScore()
rank = "Level 2";
else if(getScore() >= 20 && getScore()
rank = "Level 3";
else if(getScore()
rank = "Level 4";
setRank(rank);
return rank;
}
// creating a toString method to print players information
@Override
public String toString()
{
return("Player: " + getName()
+ " Score: " + getScore() + " Rank: "
+ decideRank());
}
}
public class stackDriver {
public static void main(String[] args) {
StackInterface
}
}
6 7 3 import java.util.Random; 4 5 public class Player { 1/ creating variables private String playersName: 8 private int score; 9 private String rank; 10 11 // players methods 129 public player() 13 14 this.playersName = ""; 15 this.score = 0; 16 this.rank = "Level 1"; 17 2 18 190 public player(String nane) { 20 this.playersName = name; 21 this.score = 0; 22 this.rank = "Level 1": 23 } 24 25 //accessors 26 public String getNane() { return playersName:) 27 public int getScore() (return score:) 28 public String getRank() { return ranka) 29 30 //mutators 31 public void setName(String nane) { this.playersante none;) public void setScorelint score) (this.score = score;} public void setRank(String rank) { this.rank = rank;) 35 360 public void play 37 38 1/ generating a randon number for players score 39 setscoret(int) (Math.random()10070)); 40 } 33 34 42 49 1/deciding rank of player depending on score public String decideRank String rank = "" if(getScore() >= 58) rank - "Level 1: else ifigetScorel) > 35 66 getScore() 20 65 getScorel) = 50) rank = "Level 1"; else if(getScore() >= 35 && getScore() = 20 66 getScorel) { 4 public void push(element); 6 public T pop() throws Stackexception; public T peek() throws Stackexception; public int size(); public boolean isEmpty(); 10 public String toString(); 11 12 ) 13 7 8 9 } public class ArrayStack
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started