Question

Write a class named ScoreBoard containing: An instance variable named score of type integer. A constructor...

  1. Write a class named ScoreBoard containing:
    • An instance variable named score of type integer.
    • A constructor that accepts an integer parameter, whose value is used to initialize the score instance variable.
    • A method named addScores that accepts a variable-length parameter list of int named scores and returns the total score of the score instance variable plus the scores in the variable length paremeter list named scores.
    • A method named bonusPoints that accepts an integer parameter. The value of score is increased by the value of the parameter.
    • A toString method that returns the string of a ScoreBoard object.

Java

Homework Answers

Answer #1

Answer: Hey! Dear student, kindly find your solution here. If you have any queries, feel free to ask me, would be very happy to resolve them. Thanks.

import java.io.*;
import java.lang.*;
class Scoreboard
{
   public static int score,totalScore=0; //variable static declared for using static methods
   String str;
   Scoreboard(int num) //constructor initailize score variable
   {
       score = num;
   }
   public static void bonusPoints(int bonus) //bonnus points method that assepts an integer
   {
       score = score+ bonus; //increase the value of score variable
   }
  
   public static int addScores(int scores) //addScore method to add score and return total
   {
       totalScore = scores*score;
       return totalScore;
      
      
   }
  
public static void main(String[]args) //main method
{
   Scoreboard str = new Scoreboard(20); //call constructor
   str.bonusPoints(10); //call method
   System.out.println(str.addScores(5)); //returninh object compiler will write here str.toString() here
}
}

  

Know the answer?
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
Similar Questions
Write the Game class, Java lanuage. A Game instance is described by three instance variables: gameName...
Write the Game class, Java lanuage. A Game instance is described by three instance variables: gameName (a String), numSold (an integer that represents the number of that type of game sold), and priceEach (a double that is the price of each of that type of Game). I only want three instance variables!! The class should have the following methods: A constructor that has two parameter – a String containing the name of the Game and a double containing its price....
Please show fully functioning java code and outputs. Design a Java Animal class (assuming in Animal.java...
Please show fully functioning java code and outputs. Design a Java Animal class (assuming in Animal.java file) and a sub class of Animal named Cat (assuming in Cat.java file).   The Animal class has the following protected instance variables: boolean vegetarian, String eatings, int numOfLegs and the following public instance methods: constructor without parameters: initialize all of the instance variables to some default values constructor with parameters: initialize all of the instance variables to the arguments SetAnimal: assign arguments to all...
public class Bicycle { // Instance variables (fields) private String ownerName; private int licenseNumber; // Constructor...
public class Bicycle { // Instance variables (fields) private String ownerName; private int licenseNumber; // Constructor public Bicycle( String name, int license ) { ownerName = name;    licenseNumber = license; } // Returns the name of the bicycle's owner public String getOwnerName( ) { return ownerName; } // Assigns the name of the bicycle's owner public void setOwnerName( String name ) { ownerName = name; } // Returns the license number of the bicycle public int getLicenseNumber( ) {...
Create a class called Employee that should include four pieces of information as instance variables—a firstName...
Create a class called Employee that should include four pieces of information as instance variables—a firstName (type String), a lastName (type String), a mobileNumber (type String) and a salary (type int). Your class (Employee) should have a full argument constructor that initializes the four instance variables. Provide a set and a get method for each instance variable. The validation for each attribute should be like below: mobileNumber should be started from “05” and the length will be limited to 10...
Java... Write a class named TestScores. The class constructor should accept an array of test scores...
Java... Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException. Demonstrate the class in a program (create a Driver class in the same file). The program should ask the user to input the number of test scores to...
Assume that the supermarket class contains an instance variable named storage whose type is double. Write...
Assume that the supermarket class contains an instance variable named storage whose type is double. Write a constructor for this class that initializes the storage to 2300.00
In Java: Assume the existence of a Window class with int instance variables width, height, xPos...
In Java: Assume the existence of a Window class with int instance variables width, height, xPos and yPos. Define the method toString for the Window class. The String representation of a Window object should be of the form "A 'width'x'height' window at ('xPos','yPos')" where the values within the apostrophes are replaced by the actual values of the corresponding instance variables. For example, given a Window object whose width is 80, height is 20, xPos is 0 and yPos is 30,...
For the following class Book: 1- Write a default constructor to give default values (title= Intro...
For the following class Book: 1- Write a default constructor to give default values (title= Intro to Programming and price = 20) to the class’s variables. 2 - Write a parameterized constructor to allow the user to initialize the class variables. 3- Write getter & setter for each variable of this class. 4- Then write a main code to create an instance of this class using parameterized constructor, ask user for inputs to initialize the variables of this instance and...
The following is for a Java Program Create UML Class Diagram for these 4 java classes....
The following is for a Java Program Create UML Class Diagram for these 4 java classes. The diagram should include: 1) All instance variables, including type and access specifier (+, -); 2) All methods, including parameter list, return type and access specifier (+, -); 3) Include Generalization and Aggregation where appropriate. Java Classes description: 1. User Class 1.1 Subclass of Account class. 1.2 Instance variables __ 1.2.1 username – String __ 1.2.2 fullName – String __ 1.2.3 deptCode – int...
Modify the Employee9C superclass so that is an abstract superclass with a constructor to set its...
Modify the Employee9C superclass so that is an abstract superclass with a constructor to set its variables (firstName and lastName). It should contain an abstract method called payPrint. Below is the source code for the Employee9C superclass: public class Employee9C {    //declaring instance variables private String firstName; private String lastName; //declaring & initializing static int variable to keep running total of the number of paychecks calculated static int counter = 0;    //constructor to set instance variables public Employee9C(String...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT