Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Inheritance The developers of a free online game named Sugar Smash have asked you to develop a class named SugarSmashPlayer that holds data about a

Inheritance

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

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 and set methods for the scores should each require two parametersone 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.

Write the class 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.

Open DemoSugarSmash.java and click the "Run Code" button to test and demonstrate the methods.

We were already provided with the code for DemoSugarSmash

import java.util.*; public class DemoSugarSmash { public static void main(String[] args) { SugarSmashPlayer ssPlayer = new SugarSmashPlayer(); ssPlayer.setIdNumber(1111); ssPlayer.setName("Alex"); System.out.println(" At start"); display(ssPlayer); ssPlayer.setScore(200, 0); System.out.println(" After setting first score"); display(ssPlayer); System.out.println("Trying to set fifth score too soon"); ssPlayer.setScore(30, 4); System.out.println(" After setting second score"); ssPlayer.setScore(30, 1); display(ssPlayer); System.out.println(" Trying to set third score when second is too low"); ssPlayer.setScore(100, 2); display(ssPlayer); System.out.println(" After setting second, third, fourth, and fifth scores"); ssPlayer.setScore(100, 1); ssPlayer.setScore(300, 2); ssPlayer.setScore(400, 3); ssPlayer.setScore(10, 4); display(ssPlayer); System.out.println(" Trying to set eleventh score"); ssPlayer.setScore(100, 10);

PremiumSugarSmashPlayer pssPlayer = new PremiumSugarSmashPlayer(); pssPlayer.setIdNumber(2222); pssPlayer.setName("Cory"); System.out.println(" At start"); display(pssPlayer); pssPlayer.setScore(200, 0); System.out.println(" After setting first score"); display(pssPlayer); System.out.println("Trying to set fifth score too soon"); pssPlayer.setScore(30, 4); System.out.println(" After setting second score"); pssPlayer.setScore(30, 1); display(pssPlayer); System.out.println(" Trying to set third score when second is too low"); pssPlayer.setScore(100, 2); display(pssPlayer); System.out.println(" After setting second through tenth scores"); for(int x = 1; x < 10; ++x) pssPlayer.setScore(130, x); display(pssPlayer); System.out.println(" Trying to set eleventh score"); pssPlayer.setScore(100, 10); display(pssPlayer); System.out.println(" Trying to set 51st score"); pssPlayer.setScore(100, 50); display(pssPlayer); } public static void display(SugarSmashPlayer p) { System.out.println(" ID #" + p.getIdNumber() + " Name: " + p.getName()); for(int x = 0; x < p.getLevels(); ++x) System.out.print(" " + p.getScore(x)); System.out.println(); } }

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

Step: 3

blur-text-image

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

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago