Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The goal is for the program to be able to guess the user's political party before they reach the end of the survey. Prepare 4
The goal is for the program to be able to guess the user's political party before they reach the end of the survey. 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 exclusive
End
Please fix this feedback that was given:
Data Files and Storage: You need to create at least four political party storages that will store answers from the user.
Obtaining Data: You need to make a way of storing the users answers to create a program that will accurately survey users and guess their political affiliations.
Additionally, the last question should ask which political party they affiliate with. Also, the amount of data is not enough to accurately guess the users political affiliate.
Program Specifications: Your code produces the result of its guess. However, the result is not based on machine learning. It needs to weigh answers with differing levels of intensity depending on which parties they correspond best with.
Good PracticeEfficiency: As your program doesnt use machine learning, its impossible to determine if your code is efficient.
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