package com.explain; import java.util.Scanner; class Election{ public static void main(String[] args) { int votesForPolly; int votesForErnest; int totalErnest; String responce; Scanner scan = new Scanner(System.in); System.out.println(); System.out.println("Election Day Vite Counting Program"); SystRead more
package com.explain;
import java.util.Scanner;
class Election{
public static void main(String[] args) {
int votesForPolly;
int votesForErnest;
int totalErnest;
String responce;
Scanner scan = new Scanner(System.in);
System.out.println();
System.out.println("Election Day Vite Counting Program");
System.out.println();
int x;
votesForPolly =0;
votesForErnest=0;
totalErnest=0;
while(true){
totalErnest++;
System.out.println("Whom do you want?\n1.Polly\n2.Ernest\n(1/2):");
x = scan.nextInt();
if(x==1){
votesForPolly++;
}
else if (x==2) {
votesForErnest++;
}
System.out.println("Are there more precincts to report(y/n):");
responce = scan.next();
if(responce.toUpperCase().equals("N")){
break;
}
}
System.out.println("Total votes for Polly:"+votesForPolly);
System.out.println("Total votes for Ernest:"+votesForErnest);
System.out.println("Total votes :"+totalErnest);
float ernestPer = (votesForErnest*100/totalErnest);
float pollyPer = (votesForPolly*100/totalErnest);
System.out.println("Ernest:"+ernestPer+"%");
System.out.println("Polly:"+pollyPer+"%");
if(votesForErnest>votesForPolly){
System.out.println("Ernest won by:"+(votesForErnest-votesForPolly)+"more precincts/votes");
}
else if (votesForErnest<votesForPolly) {
System.out.println("Polly won by:"+(votesForPolly-votesForErnest)+"more precincts/votes");
}
else if(votesForErnest==votesForPolly){
System.out.println("It was a tie with 50% for both");
}
}
}
Differentiate between Error control and flow control mechanism.
answer !
answer !
See lessElection day
package com.explain; import java.util.Scanner; class Election{ public static void main(String[] args) { int votesForPolly; int votesForErnest; int totalErnest; String responce; Scanner scan = new Scanner(System.in); System.out.println(); System.out.println("Election Day Vite Counting Program"); SystRead more