PHC-SUIYOBI
Eternal Poster
paps, gumana sya kaso yung mga ibang codes na ginamit mo, ngayon ko lang na encounter paps, wala naman po naituro paps. 


import java.util.Scanner;
public class ProjectMo {
public static void main(String[] args) {
//input data.
Scanner input = new Scanner (System.in);
//storage for candidates
String [] names = new String [3];
//storage for votes
int [] votes = new int [3];
//storage for total number of votes
double total = 0;
// the current highest vote.
double temp = votes[0];
//Act as a signal for draw.
int count = 0;
// array index of the winner.
int WinnerIndex = 0;
//set the value of names and votes for each candidates
for(int i =0; i<names.length;i++){
//Candidate name.
System.out.print("Enter name: ");
names[i] = input.nextLine();
//Candidate votes.
System.out.print("Enter votes: ");
votes[i] = input.nextInt();
//adding total votes.
total += votes[i];
//Preventing Scanner nextLine error.
input.nextLine();
//design purposes.
System.out.println("------------------------");
}
//temp value set to the votes of the first candidate.
temp = votes[0];
//for printing candidates and thier votes
for(int i = 0; i<names.length; i++){
//Percent finder
double percent = (votes[i]/total)*100;
//print names
System.out.print(names[i]+" ");
//print votes.
System.out.print(votes[i]+" ");
//print percent(2 decimals value).
System.out.printf("%.2f",percent);
//for line/spacing.
System.out.println();
}
//finding the winner
for(int i = 0; i<names.length; i++){
//if current votes is > the current highest vote.
if(votes[i]>temp){
//update index.
WinnerIndex = i;
//update for the current highest vote.
temp = votes[i];
}else if(votes[i] == temp){
//coinditon for draw
//update count.
count++;
/*
kapag ang count ay equals sa number of candidates
ibig sabihin silang lahat ay mayroong same number
of votes.
*/
}
}
//print total.
System.out.println("Total: "+(int)total);
//Condition Winner or draw.
if(count == names.length){
System.out.println("Winner: It's a draw");
}else{
System.out.println("Winner is: "+names[WinnerIndex]);
}
/*
Sample lang to sir. pag aralan mo nalang 🙂.
baka may logical error test mo nalang.
paki double check sa percentage baka my logical error
dun. Nag copy lang ako sa Google ng formula Hahaha.
*/
}
}
