Answered step by step
Verified Expert Solution
Link Copied!

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 4 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 main(String[] args){
// define questions with answer options
String[] questions ={
"What should the government do to help the poor?",
"What is your opinion on same-sex 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.put("Republican", getRandomScore());
partyScores.put("Democratic", getRandomScore());
partyScores.put("Libertarian", getRandomScore());
partyScores.put("Green", getRandomScore());
// loop through questions and gather user input
Scanner scanner = new Scanner(System.in);
for (int i =0; i < questions.length; i++){
System.out.println(questions[i]);
for (int j =0; j < answers[i].length; j++){
System.out.println((j +1)+"."+ answers[i][j]);
}
int userAnswer;
do {
System.out.print("Your choice (1-"+ answers[i].length +"): ");
userAnswer = scanner.nextInt();
} while (userAnswer <1|| userAnswer > answers[i].length);
// update party scores based on user answer
String selectedParty = "Republican"; // Replace with the actual party selected by the user
partyScores.put(selectedParty, partyScores.get(selectedParty)+1);
}
// guess user's political party based on party scores
int maxScore =0;
String guessedParty ="";
for (Map.Entry entry : partyScores.entrySet()){
String party = entry.getKey();
int score = entry.getValue();
if (score > maxScore){
maxScore = score;
guessedParty = party;
}
}
System.out.println("Based on your answers, we guess that you are a "+ guessedParty +".");
scanner.close();
}
// Method to get a random score between 0 and 20
private static int getRandomScore(){
Random random = new Random();
return random.nextInt(21); // Generates a random integer between 0(inclusive) and 21(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 Practice/Efficiency: 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Describe brands, brand names, brand marks, and service marks.

Answered: 1 week ago

Question

Discuss all branches of science

Answered: 1 week ago

Question

1. Describe the types of power that effective leaders employ

Answered: 1 week ago