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

Question #232004
You will be tasked to write this program in either C++ or Java, whichever you feel more comfortable with.
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:

3. As you gain more data on each political party, you should have a way of storing this information to create a program that will use this data to accurately survey users and guess their political libations.
1
Expert's answer
2021-09-01T23:57:26-0400
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] questions = {
                "Do you support BLM?",
                "Do you support LGBTQ+?",
                "Do you support the carrying of personal weapons?"
        };
        String[] answers = {"n", "n", "y"};
        String answer;
        int democrat = 0;
        int republican = 0;
        System.out.println("Answer 'y' or 'n' on questions.");
        for (int i = 0; i < questions.length; i++) {
            System.out.println(questions[i]);
            answer = in.nextLine();
            if (answer.equalsIgnoreCase("y") || answer.equalsIgnoreCase("n")) {
                if (answers[i].equalsIgnoreCase(answer)) {
                    republican++;
                } else {
                    democrat++;
                }
            }
        }
        System.out.println(republican > democrat ? "You are a republican." :
                (republican < democrat ? "You are a democrat." : "Take the survey again."));
    }
}

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