Question

Need help with the program

Instructions DemoSugarSmash.java PremiumSugarSmas... SugarSmash Player.ja... + 1 public class PreniunSugar SmashPlayer 3 // D

Programming Exercise 10-5 Tasks DemoSugarSmash.java PremiumSugarSmas... SugarSmashPlayer.ja... + Define setIdNumber and getId

DemoSugarSmash.java

import java.util.*;
public class DemoSugarSmash
{
public static void main(String[] args)
{
// Complete the demo program here
}
}

PremiumSugarSmashPlayer.java

public class PremiumSugarSmashPlayer
{
// Define the PremiumSugarSmashPlayer class here
}

PremiumSugarSmashPlayer.java

public class SugarSmashPlayer {


private int playerID;

private String screenName;

private int[] scoresArray ;


public SugarSmashPlayer() {

this.scoresArray = new int[10];

}


public SugarSmashPlayer(int levels) {

this.scoresArray = new int[levels];

}


public int getIdNumber() {

return playerID;

}

public void setIdNumber(int playerID) {

this.playerID = playerID;

}

public String getName() {

return screenName;

}

public void setName(String screenName) {

this.screenName = screenName;

}

public int getScore(int level) {


if(level>= scoresArray.length) {

System.err.println("Invalid level!!");

return -1;

}


else {

return scoresArray[level];

}

}

public void setScore(int score, int level) {


if(level == 0) {

scoresArray[level] = score;

}


else if(scoresArray[level - 1] >= 100 && level<scoresArray.length){

scoresArray[level] = score;

}


else {

System.err.println("Invalid value!! Can't set score");

}

}


public int getLevels() {

return scoresArray.length;

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;
public class DemoSugarSmash
{
public static void main(String[] args)
{
// Complete the demo program here
//object for premium Sugar Smash Player
PremiumSugarSmashPlayer p = new PremiumSugarSmashPlayer(40);//object created when user paid additional money //with extra 40 levels
  
  
}
}


class PremiumSugarSmashPlayer extends SugarSmashPlayer
{
// Define the PremiumSugarSmashPlayer class here
//method for additional scores
int newScores[];
PremiumSugarSmashPlayer(int levels)
{
//constructor
newScores = new int [10+levels];//creating with additional levels
}
  
//getter and setter methods for scores
public int getScore(int level) {


if(level>= newScores.length) {

System.err.println("Invalid level!!");

return -1;

}


else {

return newScores[level];

}

}

public void setScore(int score, int level) {


if(level == 0) {

newScores[level] = score;

}


else if(newScores[level - 1] >= 100 && level<newScores.length){

newScores[level] = score;

}


else {

System.err.println("Invalid value!! Can't set score");

}

}


public int getLevels() {

return newScores.length;

}

  
}

class SugarSmashPlayer {


private int playerID;

private String screenName;

private int[] scoresArray ;


public SugarSmashPlayer() {

this.scoresArray = new int[10];

}


public SugarSmashPlayer(int levels) {

this.scoresArray = new int[levels];

}


public int getIdNumber() {

return playerID;

}

public void setIdNumber(int playerID) {

this.playerID = playerID;

}

public String getName() {

return screenName;

}

public void setName(String screenName) {

this.screenName = screenName;

}

public int getScore(int level) {


if(level>= scoresArray.length) {

System.err.println("Invalid level!!");

return -1;

}


else {

return scoresArray[level];

}

}

public void setScore(int score, int level) {


if(level == 0) {

scoresArray[level] = score;

}


else if(scoresArray[level - 1] >= 100 && level<scoresArray.length){

scoresArray[level] = score;

}


else {

System.err.println("Invalid value!! Can't set score");

}

}


public int getLevels() {

return scoresArray.length;

}

}

Add a comment
Know the answer?
Add Answer to:
Need help with the program DemoSugarSmash.java import java.util.*; public class DemoSugarSmash { public static void main(String[]...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {   ...

    import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {        Student s1 = new Student();         Student s2 = new Student("Smith", "123-45-6789", 3.2);         Student s3 = new Student("Jones", "987-65-4321", 3.7);         System.out.println("The name of student #1 is ");         System.out.println("The social security number of student #1 is " + s1.toString());         System.out.println("Student #2 is " + s2);         System.out.println("the name of student #3 is " + s3.getName());         System.out.println("The social security number...

  • Write a full class definition for a class named Player , and containing the following members: A data member name of t...

    Write a full class definition for a class named Player , and containing the following members: A data member name of type string . A data member score of type int . A member function called setName that accepts a parameter and assigns it to name . The function returns no value. A member function called setScore that accepts a parameter and assigns it to score . The function returns no value. A member function called getName that accepts no...

  • Override toString() for the class HighScores. It should return a String that contains all of the...

    Override toString() for the class HighScores. It should return a String that contains all of the high scores in entries, formatted nicely. Note that toString is already implemented for the Score class. Then, write a driver program (in a file named Main.java) that thoroughly tests HighScores (i.e. add and remove scores from the list, add scores to an already full list, make sure the list remains sorted, etc). Score.java public class Score { protected String name; // name of the...

  • Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp {    public static void main(String[] args)...

    Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp {    public static void main(String[] args) { displayWelcomeMessage(); // create the Scanner object Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // generate the random number and invite user to guess it int number = getRandomNumber(); displayPleaseGuessMessage(); // continue until the user guesses the number int guessNumber = 0; int counter = 1; while (guessNumber != number) { // get a valid int from user guessNumber...

  • For Java please.Artwork. javaimport java.util.Scanner;public class ArtworkLabel {public static void main(String[] args)...

     Given main(). define the Artist class (in file Artist java) with constructors to initialize an artist's information, get methods, and a printlnfo() method. The default constructor should initialize the artist's name to "None' and the years of birth and death to 0. printinfo() should display Artist Name, born XXXX if the year of death is -1 or Artist Name (XXXX-YYYY) otherwise. Define the Artwork class (in file Artwork.java) with constructors to initialize an artwork's information, get methods, and a printinfo() method. The constructor should...

  • Priority Queue Demo import java.util.*; public class PriorityQueueDemo {    public static void main(String[] args) {...

    Priority Queue Demo import java.util.*; public class PriorityQueueDemo {    public static void main(String[] args) {        //TODO 1: Create a priority queue of Strings and assign it to variable queue1               //TODO 2: Add Oklahoma, Indiana, Georgia, Texas to queue1                      System.out.println("Priority queue using Comparable:");        //TODO 3: remove from queue1 all the strings one by one        // with the "smaller" strings (higher priority) ahead of "bigger"...

  • This is for a java program public class Calculation {    public static void main(String[] args)...

    This is for a java program public class Calculation {    public static void main(String[] args) { int num; // the number to calculate the sum of squares double x; // the variable of height double v; // the variable of velocity double t; // the variable of time System.out.println("**************************"); System.out.println(" Task 1: Sum of Squares"); System.out.println("**************************"); //Step 1: Create a Scanner object    //Task 1. Write your code here //Print the prompt and ask the user to enter an...

  • Write a program in Java that prompts a user for Name and id number. and then...

    Write a program in Java that prompts a user for Name and id number. and then the program outputs students GPA MAIN import java.util.StringTokenizer; import javax.swing.JOptionPane; public class Main {    public static void main(String[] args) {                       String thedata = JOptionPane.showInputDialog(null, "Please type in Student Name. ", "Student OOP Program", JOptionPane.INFORMATION_MESSAGE);        String name = thedata;        Student pupil = new Student(name);                   //add code here       ...

  • Cant figure out how to fix error Code- import java.io.File; import java.io.IOException; import java.util.*; public class Program8 {    public static void main(String[] args)throws IOException{       ...

    Cant figure out how to fix error Code- import java.io.File; import java.io.IOException; import java.util.*; public class Program8 {    public static void main(String[] args)throws IOException{        File prg8 = new File("program8.txt");        Scanner reader = new Scanner(prg8);        String cName = "";        int cID = 0;        double bill = 0.0;        String email = "";        double nExempt = 0.0;        String tExempt = "";        int x = 0;        int j = 1;        while(reader.hasNextInt()) {            x = reader.nextInt();}        Customers c1 [] = new Customers [x];        for (int...

  • Need Help....Java MyProgram.java: public class MyProgram { public static void main(String[] args) { } } House.java:...

    Need Help....Java MyProgram.java: public class MyProgram { public static void main(String[] args) { } } House.java: public class House { private String address; private double cost; private double interst; private int mortgageTime; private double monthPayment; } As you consider your life before you, one thing you may consider is buying a house in the future. In this assignment, you will explore concepts of this amazing opportunity and create a program that may be of benefit to you in the future!...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT