1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Anni [7]
3 years ago
12

Modify the following class so that the two instance variables are private and there is a getter method and a setter method for e

ach instance variable:
public class Player {
String name;
int score;
}
Computers and Technology
1 answer:
Gnoma [55]3 years ago
3 0

Answer:

The program to this question can be given as follows:

Program:

class player//defining class player

{

//defining variable name and score.

String name;

int score;

String get_Name() //defining method get_Name

{

return name; //return value.

}

void set_Name(String name) //defining method set_Name

{

//using this keyword to hold variable value

this.name = name; //hold value

}

int get_Score() //defining method get_Score

{

return score; //return value

}

void set_Score(int score) //defining method set_Score

{

//using this keyword to hold variable value

this.score = score; //return value

}

}

public class Main //defining class Main

{

public static void main (String[] args) //defining main method

{

//defining variable

int x;

String n;

player ob= new player(); //creating player class Object

ob.set_Name("data"); //calling function set_Name and pass the value.

ob.set_Score(10); //calling function set_Score and pass the value.

n=ob.get_Name(); //holding value

x=ob.get_Score();//holding value

System.out.println(n+"\n"+x); //print value.

}

}

Output:

data

10

Explanation:

In the above java program, the class player is defined, which contains two-variable "name and score" in which the name is a string type and score is an integer type.

  • In the next line, the getter and setter method is used, which is set is used to set the values and get is used to return the values.
  • Then the Main class is declared inside the class the main method is defined that creates a player class object and call the function.
You might be interested in
State 10 differences between video conferencing and teleconferencing​
mr_godi [17]
Answer:
Teleconferencing is voice-only or audio and video communication, while video conferencing supports the conference by providing both video and voice, so you can fully see the person when you are listening to the communicator,

Teleconferencing is capable of transmitting the data during the conference, either using traditional PBX systems or VoIP, while video conferencing offers VoIP services. The formal requires less bandwidth, while the latter is highly dependent on network bandwidth.


6 0
3 years ago
In Python please:
g100num [7]

Answer:

def compute_pay(number_of_hours, rate_of_pay):

   if number_of_hours > 40:

       pay_for_week = (40*rate_of_pay)+((number_of_hours-40)*\

                                                (rate_of_pay+rate_of_pay*0.5))

   else:

       pay_for_week = number_of_hours*rate_of_pay

   if pay_for_week >= 375:

       print("Paying %d by direct deposit" % pay_for_week)

   else:

       print("Paying %d by mailed check" % pay_for_week)

Explanation:

  1. We define the computer pay function that receives the number of hours worked in a week and the rate of pay
  2. From the test cases we deduce that if a worker works more than 40 hours a week an extra payment is given, you can calculated it as follow: (40 * rate_of_pay) + ((number_of_hours - 40) * (rate_of_pay + rate_of_pay * 0.5))
  3. If a worker works less than 40 hours the payment is calculated as follow: pay_for_week = number_of_hours * rate_of_pay
  4. If the pay for week is equal or greater than 375 we print a payment by direct deposit otherwise we print payment by mailed check

3 0
3 years ago
What is the complete predicate in the sentence below? Looking up from his computer monitor, Jason mopped his brow, exhaled sharp
frozen [14]

Answer:

A. mopped his brow, exhaled sharply, and picked up his phone.

Explanation:

Predicate in a sentence talks about the actions relating to the subject of the sentence, Here, The complete predicate is option A.mopped his brow, exhaled sharply, and picked up his phone. because they were the actions performed by the subject (John) the subject in a sentence usually refers to the person, place, thing, etc (Noun).

3 0
3 years ago
Which of the following is an input device on a toaster?
iragen [17]
The electrical outlet
3 0
3 years ago
Read 2 more answers
Who is the CEO of Epic Games?​
slavikrds [6]

Answer:

it's tim sweeney....

Explanation:

hope it helps

4 0
3 years ago
Read 2 more answers
Other questions:
  • Where can you find additional commands to include in menu options?
    12·1 answer
  • Which command group does a user need to access the Formula dialog box?
    11·1 answer
  • Why have the 'taskmasters' been answering questions so long but they're still only at the ambitious rank?
    14·1 answer
  • What tab should you choose to locate the copy and paste tool?
    10·2 answers
  • Why is fluency in information technology becoming increasingly important for many college majors?
    6·1 answer
  • What is one advantage of top-down programming design?
    8·1 answer
  • What is the missing line?
    5·1 answer
  • Mention the usage of crop concept in ms-word​
    13·2 answers
  • Write a python program to print the square of all numbers from 0 to 10.
    15·2 answers
  • A _________ attack is an attack on a computer system or network that causes a loss of service to users.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!