Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Prompt 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
Prompt
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.
You should begin by presenting the user with questions that contain answer options that differ based on their political beliefs.
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 political party storages.
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 affiliations.
Some answers to questions correspond with more than one political party. Find a way to make your program advanced enough so that it can weigh answers with differing levels of intensity depending on which parties they correspond best with.
Overall, you will prepare data storage files, obtain and store data through the usage of questions, and then write code using machine learning to create a survey that will accurately guess a user's political party before they complete the survey.
Here is my code written in Java:
Main.Java
Start
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.Scanner;
public class Main
public static void mainString args
define questions with answer options
String questions
"What should the government do to help the poor?",
"What is your opinion on samesex marriage?",
"What should be done to reduce income inequality?",
"What is your stance on gun control?",
"What is your opinion on abortion?"
;
String answers
Make it easier to apply for assistance.", "Put more money into schools.", "Incentivize welfare.",
"Nothing."
Support it fully.", "Support it with some reservations.", "Oppose it with some reservations.",
"Oppose it fully."
Increase taxes on the wealthy.", "Increase funding for education and job training programs.",
"Encourage job creation and economic growth.", Do nothing."
Implement stricter regulations and background checks.",
"Support the Second Amendment, but with some restrictions.",
"Support the Second Amendment without any restrictions.", "Repeal existing gun control laws."
Abortion should always be legal.", "Abortion should be legal in most cases.",
"Abortion should be illegal in most cases.", "Abortion should always be illegal."
;
define political parties and their respective random initial scores
Map partyScores new HashMap;
partyScores.putRepublican getRandomScore;
partyScores.putDemocratic getRandomScore;
partyScores.putLibertarian getRandomScore;
partyScores.putGreen getRandomScore;
loop through questions and gather user input
Scanner scanner new ScannerSystemin;
for int i ; i questions.length; i
System.out.printlnquestionsi;
for int j ; j answersilength; j
System.out.printlnj answersij;
int userAnswer;
do
System.out.printYour choice answersilength : ;
userAnswer scanner.nextInt;
while userAnswer userAnswer answersilength;
update party scores based on user answer
String selectedParty "Republican"; Replace with the actual party selected by the user
partyScores.putselectedParty partyScores.getselectedParty;
guess user's political party based on party scores
int maxScore ;
String guessedParty ;
for MapEntry entry : partyScores.entrySet
String party entry.getKey;
int score entry.getValue;
if score maxScore
maxScore score;
guessedParty party;
System.out.printlnBased on your answers, we guess that you are a guessedParty ;
scanner.close;
Method to get a random score between and
private static int getRandomScore
Random random new Random;
return random.nextInt; Generates a random integer between inclusive and exclusiv
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started