-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolymorphismOverloading.java
More file actions
89 lines (50 loc) · 1.73 KB
/
Copy pathPolymorphismOverloading.java
File metadata and controls
89 lines (50 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
public class PolymorphismOverloading {
public static void main (String [] args) {
playerRating PR = new playerRating();
PR.playerDetails(1, " Beckham");
PR.calculateRating(9f, 9.9f);
PR.calculateCategory();
PR.display();
playerRating PR1 = new playerRating();
PR1.playerDetails(1, " Oscar");
PR1.calculateRating(1f, 1f, 1f);
PR1.calculateCategory();
PR1.display();
}
}
class playerRating{
public int playerPosition;
public String playerName;
public float citricRate1;
public float citricRate2;
public float citricRate3;
public float averageRating;
public char playerCategory;
public void playerDetails( int playerPositions , String playerNames ) {
playerPosition = playerPositions;
playerName = playerNames;
}
public void calculateRating(float citricRate1, float citricRate2 ) {
averageRating = (citricRate1 + citricRate2)/2;
}
public void calculateRating(float citricRate1 , float citricRate2 , float citricRate3) {
averageRating = (citricRate1 + citricRate2 + citricRate3)/3;
}
public void calculateCategory() {
if (averageRating > 8) {
playerCategory = 'A';
} else if (averageRating > 5) {
playerCategory = 'B';
} else if (averageRating >= 0) {
playerCategory = 'C';
} else {
playerCategory = 'U'; // U for undefined (negative rating)
}
}
public void display() {
System.out.println("player Name : " + playerName);
System.out.println(" player postion :" + playerPosition);
System.out.println("player rating : " + averageRating);
System.out.println("player category :" + playerCategory);
}
}