-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAug- (Java OPA) _code.java
111 lines (101 loc) · 2.38 KB
/
Aug- (Java OPA) _code.java
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import java.util.*;
import java.util.Arrays;
public class Main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
Player[] player=new Player[4];
for(int i=0;i<4;i++)
{
int playerId=sc.nextInt();sc.nextLine();
String playerName=sc.nextLine();
int score1=sc.nextInt();
int score2=sc.nextInt();
int score3=sc.nextInt();
player[i]=new Player(playerId,playerName,score1,score2,score3);
}
int number=findTotalHundredsCount(player);
System.out.println(number);
Player player1= getTopPlayer(player);
System.out.println(player1.getPlayerId()+" "+player1.getPlayerName());
}
public static int findTotalHundredsCount(Player[] player){
int count=0;
for(int j=0;j<4;j++)
{
if(player[j].getScore1()>=100)
{
count=count+1;
}
if(player[j].getScore2()>=100)
{
count=count+1;
}
if(player[j].getScore3()>=100)
{
count=count+1;
}
}
return count;
}
public static Player getTopPlayer(Player[] player){
Player player2= new Player(0,null,0,0,0);
int con=0;
int sum=player[0].getScore1()+player[0].getScore2()+player[0].getScore3();
player2=player[0];
for(int i=1;i<player.length;i++)
{
con=player[i].getScore1()+player[i].getScore2()+player[i].getScore3();
if(con>sum)
{
player2=player[i];
sum=con;
}
}
return player2;
}
}
class Player{
private int playerId;
private String playerName;
private int score1;
private int score2;
private int score3;
public int getPlayerId() {
return playerId;
}
public void setPlayerId(int playerId) {
this.playerId = playerId;
}
public String getPlayerName() {
return playerName;
}
public void setPlayerName(String playerName) {
this.playerName = playerName;
}
public int getScore1() {
return score1;
}
public void setScore1(int score1) {
this.score1 = score1;
}
public int getScore2() {
return score2;
}
public void setScore2(int score2) {
this.score2 = score2;
}
public int getScore3() {
return score3;
}
public void setScore3(int score3) {
this.score3 = score3;
}
public Player(int playerId, String playerName, int score1, int score2, int score3) {
super();
this.playerId = playerId;
this.playerName = playerName;
this.score1 = score1;
this.score2 = score2;
this.score3 = score3;
}
}