This is the question - The developers of a free online game named Sugar Smash have asked you to develop a class named SugarSmashPlayer that holds data about a single player. The class contains the following fields: idNumber - the player’s ID number (of type int) name - the player's screen name (of type String) scores - an array of integers that stores the highest score achieved in each of 10 game levels Include get and set methods for each field. The get method for scores should require the game level to retrieve the score for. The set method for scores should require two parameters—one that represents the score achieved and one that represents the game level to be retrieved or assigned. Display an error message if the user attempts to assign or retrieve a score from a level that is out of range for the array of scores. Additionally, no level except the first one should be set unless the user has earned at least 100 points at each previous level. If a user tries to set a score for a level that is not yet available, issue an error message. Create a class named PremiumSugarSmashPlayer that descends from SugarSmashPlayer. This class is instantiated when a user pays $2.99 to have access to 40 additional levels of play. As in the free version of the game, a user cannot set a score for a level unless the user has earned at least 100 points at all previous levels. Code I have - import java.util.*; public class DemoSugarSmash { public static void main(String[] args) { SugarSmashPlayer player1 = new SugarSmashPlayer(); player1.setId(12); player1.setName("Hagemaru"); player1.setScore(2340,1); player1.setScore(400,2); player1.setScore(500,5); System.out.print("\n\t Id : "+player1.getId()+"\n\tName: "+player1.getName() +"\n\tLevel1: "+player1.getScore(1)+"\n\tLevel2: "+player1.getScore(2)); System.out.print("\nDo you wish to pay $2.99 to have access to 40 additional levels of play? (y/n) :"); Scanner s = new Scanner(System.in); char c=s.next().charAt(0); if(c=='y'||c=='Y'){ player1=new PremiumSugarSmashPlayer(); } } } class PremiumSugarSmashPlayer extends SugarSmashPlayer { double[] moreScores= new double[50]; PremiumSugarSmashPlayer(){ super(); int i; for( i=0;i<10;i++){ moreScores[i]=super.scores[i]; } for( ;i<50;i++){ moreScores[i]=0; } } public double getScore(int level){ if(level<0 || level>50) System.out.print("This level not exists!"); else{ return moreScores[level-1]; } return -1; } public void setScore(double score,int level){ if(level<0 || level>50) System.out.print("\nThis level not exists!"); else{ moreScores[level-1]=score; } } } class SugarSmashPlayer { protected int idNumber; protected String name; protected double[] scores= new double[10]; public SugarSmashPlayer(){ idNumber=0; name=""; for(int i=0;i<10;i++) scores[i]=0; } public int getId() { return idNumber; } public String getName() { return name; } public double getScore(int level){ if(level<0 || level>10) System.out.print("This level not exists!"); else return scores[level-1]; return -1; } public void setId(int x) { idNumber=x; } public void setName(String s) { name=s; } public void setScore(double score,int level){ if(level<0 || level>10) System.out.print("\nThis level not exists!"); else{ if(level!=1 && scores[level-2]<100) System.out.print("\nYou can't play for this level untill previos level score is less than 100"); else scores[level-1]=score; } } } Here is a screencapture of one of my errors that the program will not accept at all. I can't show the other three errors due to image limit but hopefully this will help! -
This is the question -
The developers of a free online game named Sugar Smash have asked you to develop a class named SugarSmashPlayer that holds data about a single player. The class contains the following fields:
- idNumber - the player’s ID number (of type int)
- name - the player's screen name (of type String)
- scores - an array of integers that stores the highest score achieved in each of 10 game levels
Include get and set methods for each field. The get method for scores should require the game level to retrieve the score for. The set method for scores should require two parameters—one that represents the score achieved and one that represents the game level to be retrieved or assigned.
Display an error message if the user attempts to assign or retrieve a score from a level that is out of range for the array of scores. Additionally, no level except the first one should be set unless the user has earned at least 100 points at each previous level. If a user tries to set a score for a level that is not yet available, issue an error message.
Create a class named PremiumSugarSmashPlayer that descends from SugarSmashPlayer. This class is instantiated when a user pays $2.99 to have access to 40 additional levels of play. As in the free version of the game, a user cannot set a score for a level unless the user has earned at least 100 points at all previous levels.
Code I have -



Trending now
This is a popular solution!
Step by step
Solved in 2 steps









