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

Question #233162

NOTE:

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.

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:

1. You should begin by presenting the user with questions that contain answer options that dier based on their political beliefs.

Ex. What should the government do to help the poor?

A. Make it easier to apply for assistance. B. Put more money into schools.

C. Incentivize welfare.

D. Nothing.


1
Expert's answer
2021-09-05T00:32:56-0400
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		String partyA="Democratic";
		String partyB="Republican";
		System.out.println("Answer the following questions: ");
		char c1,c2,c3;
		System.out.println("Are you black, hispanic, or Asian?\nA. Yes\nB. No");
		c1=in.next().charAt(0);
		System.out.println("Do you consider religion important?\nA. Yes\nB. No");
		c2=in.next().charAt(0);
		System.out.println("What should the government do to help the poor?\nA. Make it easier to apply for assistance. \nB. Put more money into schools.\nC. Incentivize welfare.\nD. Nothing.");
		c3=in.next().charAt(0);
		
		String predicted_party=" ";
		if (c1=='A' || c2=='A' || c3=='A'||c3=='B')
		    predicted_party="Republican";
	    else if (c1=='B' || c2=='B' || c3=='C'||c3=='D')
		    predicted_party="Democratic";
		    
		int c;
		String party=" ";
		System.out.println("Which party do you belong to?\n1. Democratic\n2. Republican");
		c=in.nextInt();
		if (c==1)
		    party="Democratic";
		else if (c==2)
		    party="Republican";
		    
		System.out.println("Your party is "+party+" and the predicted party is "+predicted_party);
	}
}

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