Discussion Section 5: Instance Variables
Due: 10pm Tuesday February 20
Purpose: In this
discussion section, you will define methods, and set and use
instance variables in objects. You will also use an array of objects.
Let's start a survival game
Player 1, what is your name? Jane Smith
Player 2, what is your name? John Smith
Pick a value from 0 to 10
Jane Smith, what's your value? 1
John Smith, what's your value? 7
Jane Smith
LP: ****
John Smith
LP: **
Pick a value from 0 to 10
Jane Smith, what's your value? 1
John Smith, what's your value? 0
Jane Smith
LP: ****
John Smith
LP:
Jane Smith wins!!
Your goal is to implement the class Player to complete the SurvivalGame program. Download the template for Player: Player.java and the SurvivalGame: SurvivalGame.java by right-clicking on each link. Choose "Save Target(Link) As..." and store it. (To add the files to your project in BlueJ either use the import feature or cut and paste.) Implement each constructor and method specified by the Player class. Note that you need to replace three return statements in getName, getLifePoints, and toString.
There are two design choices you need to make:
1) Default life points (in constructors)
2) Printing of life points (in toString method)
Try different default life points and see how long the game becomes.
Use your imagination for printing the life points. (Hint: You need not
print one star for every life point, but that is a good place to start!)
Read over the main routine in SurvivalGame which shows an example of declaring and using arrays of objects.
Your program should be internally correct (sound logic) and externally correct (following Java style guideline).