-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathFindTheWinner.java
More file actions
36 lines (33 loc) · 1.07 KB
/
FindTheWinner.java
File metadata and controls
36 lines (33 loc) · 1.07 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
package com.dtcc.exams.part7;
public class FindTheWinner {
public FindTheWinner(){
}
public String winner(Integer[] leon,Integer[] wilhelm,String input){
String winner=null;
Integer player1=0;
Integer player2=0;
if(input.equalsIgnoreCase("even")){
for(int i=0;i<leon.length;i++){
if(i%2==0) {
player1 += leon[i] - wilhelm[i];
player2 += wilhelm[i] - leon[i];
}
}
if(player1>player2){ winner="Zan"; }
else if(player2> player1){ winner="Brian"; }
else {winner="Tie";}
}
else if(input.equalsIgnoreCase("odd")){
for(int i=0;i<leon.length;i++){
if(i%2==1) {
player1 += leon[i] - wilhelm[i];
player2 += wilhelm[i] - leon[i];
}
}
if(player1>player2){ winner="Zan"; }
else if(player2> player1){ winner="Brian"; }
else {winner="Tie";}
}
return winner;
}
}