Question: DemoSugarSmash.java, SugarSmashPlayer.java, and PremiumSugarSmashPlayer.java The developers of a free online game named Sugar Smash have asked you to develop a class named SugarSmashPlayer that holds

DemoSugarSmash.java, SugarSmashPlayer.java, and PremiumSugarSmashPlayer.java

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:

the players integer ID number

a String screen name

the players integer points

In your default constructor, assign default values of your choice to integer ID number and String screen name. Give the player a starting value of 0 points. Include get and set methods for each field. In the earnPoints() method, increment the amount of points by 100. Write the class PremiumSugarSmashPlayer that descends from SugarSmashPlayer. This special player will be able to use boosters to increase their score by 500. The class contains the players integer booster field. The player will start with 3 boosters when created. Override the earnPoints() method so that the player earns 500 points and adds it to their current points. Within the same method, decrement the number of boosters by 1. If the player tries to earn points but has no more boosters, then print: Out of boosters! (without the quotations) and will earn 100 points instead. When the player buys boosters, increment boosters by 3.

Run DemoSugarSmash.java to demonstrate the methods pass all 5 tests.

DemoSugarSmash.java

public class DemoSugarSmash { public static void main(String[] args) { //Test 1  System.out.println("Test 1"); SugarSmashPlayer ssPlayer = new SugarSmashPlayer(); ssPlayer.setIdNumber(1111); ssPlayer.setName("Alex"); ssPlayer.earnPoints(); ssPlayer.earnPoints(); System.out.println(ssPlayer.getName() + "(playerID: " + ssPlayer.getIdNumber() + ") has scored " + ssPlayer.getPoints() + " points."); System.out.println(); //Test 2  System.out.println("Test 2"); ssPlayer.setPoints(123456789); System.out.println(ssPlayer.getName() + "(playerID: " + ssPlayer.getIdNumber() + ") has hacked the game and set their score to " + ssPlayer.getPoints() + "!"); System.out.println(); //Test 3  System.out.println("Test 3"); PremiumSugarSmashPlayer pssPlayer = new PremiumSugarSmashPlayer(); pssPlayer.setIdNumber(2222); pssPlayer.setName("Cory"); pssPlayer.earnPoints(); pssPlayer.earnPoints(); pssPlayer.earnPoints(); System.out.println(pssPlayer.getName() + "(playerID: " + pssPlayer.getIdNumber() + ") has scored " + pssPlayer.getPoints() + " points."); System.out.println(); //Test 4  System.out.println("Test 4"); pssPlayer.earnPoints(); System.out.println(pssPlayer.getName() + "(playerID: " + pssPlayer.getIdNumber() + ") has scored " + pssPlayer.getPoints() + " points."); System.out.println(); //Test 5  System.out.println("Test 5"); pssPlayer.buyBoosters(); pssPlayer.earnPoints(); System.out.println(pssPlayer.getName() + "(playerID: " + pssPlayer.getIdNumber() + ") has scored " + pssPlayer.getPoints() + " points."); System.out.println(); } } 

SugarSmashPlayer.java

public class SugarSmashPlayer { private int idNumber; private String name; private int points; public SugarSmashPlayer() { idNumber = 0; points = 0; name = ""; } public void setIdNumber(int num) { this.idNumber = idNumber; } public void setName(String player) { this.name = name; } public void setPoints(int pts) { this.points = points; } public void earnPoints() { points = points + 100; } public int getIdNumber() { return idNumber; } public String getName() { return name; } public int getPoints() { return points; } } 

PremiumSugarSmashPlayer.java

public class PremiumSugarSmashPlayer extends SugarSmashPlayer { private int points; private int boosters; public PremiumSugarSmashPlayer() { points = 0; boosters = 3; } // override (public!) earnPoints() method here  @Override public void earnPoints() { super.earnPoints + 500; get.setPoints; } public void buyBoosters() { } } } 

The code I have for SugarSmashPlayer.java and PremiumSugarSmashPlayer.java is probably wrong and I need help on that as well. The DemoSugarSmash.java was provided.

Thank You!

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!