// This program calculates the percentage of votes a candidate has received. It is not // a well-structured solution and has a lot of redundancy, so it is not a model // to emulate. import java.util.*; public class ElectionRedundantVersion { public static final int TOTAL_POPULATION = 160; // CSE 142 population public static void main(String[] args) { System.out.println("This program reads in data for two candidates"); System.out.println("and computes their standing in the election"); System.out.println(); Scanner console = new Scanner(System.in); System.out.println("Enter next candidate's information:"); System.out.print("number of votes? "); int votes1 = console.nextInt(); double result1 = (100.0 * votes1 / TOTAL_POPULATION); System.out.println(); System.out.println("Enter next candidate's information:"); System.out.print("number of votes? "); int votes2 = console.nextInt(); double result2 = (100.0 * votes2 / TOTAL_POPULATION); System.out.println(); System.out.println("Candidate #1 has = " + Math.round(result1 * 10.0) / 10.0 + "% of the votes"); if (result1 > 50) { System.out.println("winning"); } else if (result1 < 50) { System.out.println("losing"); } else { // (result1 == 50) System.out.println("stalemate."); } System.out.println("Candidate #2 has = " + Math.round(result2 * 10.0) / 10.0 + "% of the votes"); if (result2 > 50) { System.out.println("winning"); } else if (result2 < 50) { System.out.println("losing"); } else { // (result2 == 50) System.out.println("stalemate."); } } }