Question: make a code for this in java encapsulation and data hiding player class Step 1: Create a class 'Player'. Step 2: Declare four (4X) fields/variables

Step 1: Create a class 'Player'. Step 2: Declare four (4X) fields/variables names as private: playerName as string, age as number, and gameType as string. Step 3: Create four (4X) constructors with the following arguments: 1st constructor: playerName as string. 2nd constructor: age as number. 3nd constructor: playerName as string, age as number. 4th constructor: playerName as string, age as number, and gameType as string. Step 4: Create a public getter method for each private variable. Step 5: Create a public setter method for each private variable and provide its argument. Step 6: Create a test class Player Test. Step 7: In main method, create four (4X) different objects of a class Player by instantiating with the use of new keyword: 1st object: obj1 passing the playerName "Player 1" 2nd object: obj2 passing the age 21 3rd object: obj3 passing the playerName "Player 2" and age 33 4th object: obj4 passing the playerName "Player 3", age 29, and gameType "Single Player" Step 8: Call the setter method for playerName of obj1 and change its playerName to "Dave" Step 9: Using System.out.println, call the getter method for playerName of obj1. This should print "Dave". Step 10: Using System.out.println, call the getter method for age of obj2. This should print 21. Step 11: Call the setter method for age of obj2 and change its age to 25 Step 12: Using System.out.println, call the getter method for age of obj2. This should print 25. Step 13: Call the setter method for age of obj3 and change its age to 30 Step 14: Using System.out.println, call the getter method for age of obj3. This should print 30. Step 15: Call the setter method for gameType of obj4 and change its gameType to "Multi Player". Step 16: Using System.out.println, call the getter method for game Type of obj4. This should print "Multi Player". Step 17: Using System.out.println, call the getter method for age of obj4. This should print 29.
Step by Step Solution
There are 3 Steps involved in it
Heres the code for the Player class including the constructors getter and setter methods java public ... View full answer
Get step-by-step solutions from verified subject matter experts
