// This program calculates the percentage of votes a candidate has received. import java.util.*; public class ElectionChainedVersion { public static final int TOTAL_POPULATION = 150; // CSE 142 population public static void main(String[] args) { intro(); Scanner console = new Scanner(System.in); person(console); } public static void intro() { System.out.println("This program reads in data for two candidates"); System.out.println("and computes their standing in the election"); System.out.println(); } public static void person(Scanner console) { System.out.println("Enter next candidate's information:"); System.out.print("number of votes? "); int votes = console.nextInt(); System.out.println(); getPercentage(console, votes); } public static void getPercentage(Scanner console, int votes) { double percentage = 100.0 * votes / TOTAL_POPULATION; reportResults(console, percentage); } public static void reportResults(Scanner console, double result) { System.out.println("Candidate #1 has = " + Math.round(result * 10.0) / 10.0+ "% of the votes"); if (result > 50) { System.out.println("winning"); } else if (result < 50) { System.out.println("losing"); } else { // result == 50 System.out.println("stalemate"); } } }