Solution Review: Design a PlayStation
Explore how to design and implement Java classes through a detailed PlayStation game example. Learn to create classes, constructors, accessor and mutator methods, and understand object references to manage game and player data effectively. This lesson prepares you to handle real-world coding problems in AP Computer Science.
We'll cover the following...
The Game class
Rubric criteria
Rubric-wise explanation
Point 1:
-
At line 1, we declare the header of the
Gameclass. The class ispublic. We can’t declare a top level class asprotectedorprivate. It will always give an error. -
According to the problem statement, we only need three
privatedata members:name: Name of the gamelevels: Total levels in a gamescorePerLevel: Score assigned upon level completion
Point 2:
- Then, we make a constructor. Look at line 9. We declare a -parameter constructor that accepts three values for
name,scorePerLevel, andlevels.
Now we create some methods. It may not make sense right now as to why we make them, but it will later on.
Point 3:
- Look at line 17. We create an accessor method:
getTotalLevels(). It returnslevel, a private instance of theGameclass.
Point 4:
-
Now we have three mutator methods, all with the same name:
updateGame. This is allowed as long as they are overloading each other.