For questions (1) through (10,1 Turn in ONLY page 2 with your answers on the she
ID: 3709970 • Letter: F
Question
For questions (1) through (10,1 Turn in ONLY page 2 with your answers on the sheet! yVen below. credit. Make SURE your name in led in for class Player private String name; private int val; public Playerc) (name - "Sammy"; val ;) public Player(String t) ( name t;) public void setName(String t) ( name public String getame) ( return name; public void setvalue(int v) val v; public int getvalue) ( return val; public static void main(Stringl] args) Player playl new Player); Player play2 - new Player("Samantha"); play1.setName("Stephen"); play2.getName(); play2.setValue (200); play1.setValue (100); string pi- "Player 1 " play1.getName"It"play1.getvalue() System.out.println(p1); String p2 e "player 2 play2.getName() System.out.printin(p2); +play2.getvalue)i play1.setValue (300); play2.setValue(500); int score (play1.getvalue() + play2.getvalue)i , systen.out.println("ntotal score: "+score)iExplanation / Answer
1. play1 and play2 are the objects of type Player that were initialized
2. Player() and Player("Samanth") are two contructor methods
3. Player 1 Stephen 100
4.
total score: 800
5. Player play1 = new Player();
Default constructor is called here. which initializes name to Sammy and value to 0
So,
output :
Sammy
0
6. mutator methods are setName(string) and setValue(val)
7. Accessor method are getName() and getValue()
8. void setName(String t){name = t;}
In this name of the parameter that is local to this methdo is 't'
9. void setValue(int v){val = v;}
In this, the data member being used is 'val'
10.
Player() is default constructor
Player(String t) is an overloaded constructor
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.