You are on page 1of 2

Exercise (Create a Concrete Class):

Preparation:
1. Create an application folder in the D drive called “D:\My Documents\StudentNumber\Exercise\”, where StudentNumber
is your actual student number.
2. Create a new file in Notepad++ called Open the “TennisPlayer.java” file in NotePad++ and complete the question as
instructed below.

The question:
Write a Java concrete class named TennisPlayer that can be used to present a tennis player and to determine the win percentage of
the player before he/she plays a tennis match. Complete the TennisPlayer class as described in the UML class diagram (Table 1.1)
and description (Table 1.2) below.

TennisPlayer
- surname: String
- worldRanking: int
- gender: char
- age: int
- weeks: int
+ TennisPlayer()
+ TennisPlayer(String, int, char, int, int)
+ setSurname(String): void
+ setWorldRankings(int): void
+ setGender(char): void
+ setAge(int): void
+ setWeeks(int): void
+ getSurname(): String
+ getWorldRankings(): int
+ getGender(): char
+ getAge(): int
+ getWeeks(): int
+ winPercentage(int): double
Table 1.1: UML Class Diagram (TennisPlayer)
Attribute/Method Description Marks
surname These are all instance data members that is used to describe a tennis player. A tennis player will have
worldRanking a surname, must have a world ranking (worldRanking), is either a male or female (gender), has an
gender age, and must know how many weeks it has been since his/her last won a match. 4
age
weeks
TennisPlayer() The default constructor will assign the default values of 100 and 10 to the data member’s
3
worldRanking and weeks respectively.
TennisPlayer(String, int, char, int, int) The overloaded parameterized constructor will receive the values to be assigned to the data
300
members as parameters.
setSurname(String) Mutator methods.
setWorldRankings(int)
setGender(char) 5
setAge(int)
setWeeks(int)
getSurname() Accessor methods.
getWorldRankings()
getGender() 5
getAge()
getWeeks()
winPercentage(int)  The method will be used to determine and return the winning percentage of
the tennis player before a tennis match.
This method will receive as parameter the world ranking of the opponent.
 The tennis player will have a 20% possibility of winning the match if he/she
has a world ranking higher than the opponent.
9
 The winning percentage increase a lot if the player’s world ranking is lower
than the opponent based on the form the player is currently in.
o If the number of weeks is more than 5 since the last time the player
won a game, the then winning percentage is 60%, otherwise the
winning percentage is 80%.
Table 1.2: Class Description (TennisPlayer)

You might also like