Answer to Question #233446 in Java | JSP | JSF for Zia

Question #233446

This question has been answered by someone else before but was not complete so kindly this time answer this in full and also when you write classes do send the code as well with the answer.

Question:

You will be tasked to write this program in Java.

The goal is for the program to be able to guess the user's political party before they reach the end of the survey. This will require your program to gather a substantial amount of data before it can make accurate guesses. In particular:

2. The last question should ask which political party they affiliate with. This way you will be able to gather and store data corresponding to the results you acquire. Create at least 4 political party storage.


1
Expert's answer
2021-09-06T00:17:23-0400
import java.util.Scanner;


public class Main
{
    
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
	
		int republican = 0, democratic=0, libertarian=0, green = 0;
		System.out.println("a. Do you support abortion in any case?");
		System.out.println("1= Yes, because it will provide protection to the mothers.");
		System.out.println("2= No, because it is morally wrong and it is against the will of God");
		System.out.println("3= I don't want to say");
	   System.out.println("4= I dont know the answer\n\n");
	   
	   	int choice1 = scan.nextInt();
	   	if(choice1==1){
			republican++;
		}
		else if(choice1==2){
			democratic++;
		}
		else if(choice1==3){
			libertarian++;
		}
		else if(choice1==4){
			green++;
		}
 	System.out.println("b. Are you in support of gay rights?");
 	System.out.println("1= No, marriage should be between man and woman.");
 	 System.out.println("2= Yes, people should have freedom to love who they like.");
 	System.out.println("3= I don't want to say");
	System.out.println("4= I dont know the answer\n\n");
	int choice2;
	choice2 = scan.nextInt();
	if(choice2==1){
			republican++;
		}
		else if(choice2==2){
			democratic++;
		}
		else if(choice2==3){
			libertarian++;
		}
		else if(choice2==4){
			green++;
		}
 	System.out.println("c. Is enviroment more benefecial than business?");
System.out.println("1= No");
 	 System.out.println("2= Yes");
 	System.out.println("3= I don't want to say");
	System.out.println("4= I dont know the answer\n\n");
	int choice3;
	choice3 = scan.nextInt();
	if(choice3==1){
			republican++;
		}
		else if(choice3==2){
			democratic++;
		}
		else if(choice3==3){
			libertarian++;
		}
		else if(choice3==4){
			green++;
		}


		
		
		System.out.println("d. Should there be more restrictions and strict laws on gun?");
System.out.println("1= No");
 	 System.out.println("2= Yes");
 	System.out.println("3= I don't want to say");
	System.out.println("4= I dont know the answer\n\n");
	int choice4;
	choice4 = scan.nextInt();
	if(choice4==1){
			republican++;
		}
		else if(choice4==2){
			democratic++;
		}
		else if(choice4==3){
			libertarian++;
		}
		else if(choice4==4){
			green++;
		}
int [] choices = {republican,democratic,libertarian,green};
String [] choices_string= {"Democratic", "Republican", "Libertarian" , "Green" };
int max = choices[0];
int index = 0;
for (int i=0; i<4 ; i++ ){
    if(choices[i]>max){
        max = choices[i];
        index = i;
    }
    
} 
System.out.println("The political party you are affiliating to is: "+choices_string[index]);


		


	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS