make a code for this in java encapsulation and data hiding player class Step 1: Create a
Fantastic news! We've Found the answer you've been seeking!
Question:
make a code for this in java encapsulation and data hiding player class
Transcribed Image Text:
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 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.
Expert Answer:
Answer rating: 100% (QA)
Heres the code for the Player class including the constructors getter and setter methods java public ... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
The fraud examiner's report should have what characteristics? a. Accuracy and clarity b. Relevant and material information c. Should not contain opinions or prejudices of fraud examiner. d. All of...
-
In the special report, "Bitter Pill: Why Medical Bills Are Killing Us" (TIME, Vol. 181, No. 8, 2013), S. Brill presented an in-depth investigation of hospital billing practices that reveals why U.S....
-
Consider the following problem. Maximize Z = 8x1 + 24x2, Subject to And x1 ¥ 0, x2 ¥ 0. Suppose that Z represents profit and that it is possible to modify the objective function somewhat by...
-
An effective way to learn how companies respond to the competing pressures to be globally integrated and locally responsive is to study them in action. Referring back to Exhibit 6.3, search online...
-
Juan Morales Company had the following account balances at year-end: Cost of Goods Sold $60,000; Inventory $15,000; Operating Expenses $29,000; Sales Revenue $115,000; Sales Discounts $1,200; and...
-
3. The length of the biceps muscle increases 1.7cm over the course of an overhead softball throw. The stiffness constant for the biceps is 225,000 N/cm. Calculate the strain potential energy (in Nm)...
-
The CyClon project team has started gathering information necessary to develop a project network-predecessor activities and activity time in days. The results of their meeting are found in the...
-
Corp Inc. is expected to experience a turnaround period during which its current dividends per share of $1.80 will be reduced by 40% annually for the next two years, and then to grow at 50% annually...
-
The communication method that is used for large audiences or large volumes of information and requires recipients to access the content at their own discretion, is called communication. a. push b....
-
Why is an Agile project planned in detail just one iteration at a time? Give an example of a project that would work well using Agile scheduling and another example of a project for which traditional...
-
Give an example of what is given up in a project when it is crashed and when it is fast-tracked and an appropriate time to use each.
-
What is the purpose of an order of magnitude cost estimate?
-
What are the two techniques used to compress a project schedule?
-
On January 1, 2021, Brooks Corporation exchanged $1,255,500 fair-value consideration for all of the outstanding voting stock of Chandler, Inc. At the acquisition date, Chandler had a book value equal...
-
If (x) 0 on the interval [a, b], the definite integral gives the exact area under the curve between x = a and x = b.
-
Quince Interests is a partnership with a tax year that ends September 30, 2012. During that year, Potter, a partner, received $3,000 per month as a guaranteed payment, and his share of partnership...
-
During 2012, Palo Fiero purchases the following property for use in his manufacturing business: Palo uses the accelerated depreciation method under MACRS, if available, and does not make the election...
-
Van makes an investment in a partnership in 2012. Van's capital contributions to the partnership consisted of $30,000 cash and a building with an adjusted basis of$70,000, subject to a nonrecourse...
-
A leading financial publication reported that the average baby boomer credit user will pay approximately $1,200 in interest annually. If, instead of paying interest, this amount was saved every year,...
-
With the availability of free credit reports, consumers are encouraged to check their report every 4 months-one report from each of the three major bureaus. In the past, consumers also were...
-
Working in a small group, collect credit card marketing information or the summary of account information sent to cardholders for three to five different cards. Be sure to protect the identity of the...
Study smarter with the SolutionInn App