Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Now that you have successfully created Trivia objects, you will continue 6B by creating a linked list of trivia objects. Add the linked list code

Now that you have successfully created Trivia objects, you will continue 6B by creating a linked list of trivia objects. Add the linked list code to the Trivia class. Your linked list code should include the following: a TriviaNode class with the attributes: 1. trivia game - Trivia object 2. next- TriviaNode 3. write the constructor, accessor, mutator and toString methods. A TriviaLinkedList Class which should include the following attributes: 1. head - TriviaNode 2. number of items integer 3. write the code for the constructor, accessor and mutator, and toString methods. 4. methods to insert a triviaNode on the list - You may assume inserts always insert as the first node in the list. 5. write a method to delete a node by passing the node id of the game to delete. Take into consideration that the game may not exist in the list. Your method should let the user know that the node was successfully deleted or not. Write a client to test all aspects - creating trivia objects, inserting the objects as nodes to the list, deleting a node by passing the id of the trivia game. Print out the list every time you make a change such as adding a node and deleting a node. You should create at least 5 objects to be inserted to your list, then delete at least 1. Also, test deleting an object that is not in the list.

public class Game { //game class private String description; public Game(String description) { this.description = description; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } @Override public String toString() { return "Game [description=" + description + "]"; } }

public class TriviaGame extends Game { private int id; private double ultimatePriceMoney; private int numberOfquesToWin; public TriviaGame(int id, double ultimatePriceMoney, int numberOfquesToWin) { super(" ================= My Trivia Game ==========="); this.id = id; this.ultimatePriceMoney = ultimatePriceMoney; this.numberOfquesToWin = numberOfquesToWin; } //getters and setters for triviagame public int getId() { return id; } public void setId(int id) { this.id = id; } public double getUltimatePriceMoney() { return ultimatePriceMoney; } public void setUltimatePriceMoney(double ultimatePriceMoney) { this.ultimatePriceMoney = ultimatePriceMoney; } public int getNumberOfquesToWin() { return numberOfquesToWin; } public void setNumberOfquesToWin(int numberOfquesToWin) { this.numberOfquesToWin = numberOfquesToWin; } @Override public String toString() { return "TriviaGame [id=" + id + ", ultimatePriceMoney=" + ultimatePriceMoney + ", numberOfquesToWin=" + numberOfquesToWin + "]"; } }

import java.util.ArrayList;////////playgame import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Scanner; public class PlayGame { List questions = new LinkedList<>(); Map questionAnswerMap = new HashMap<>(); List answers = new ArrayList<>(); public void initializeQuestionAnswers() { //series of questions that the user needs to answer correctly to win questions.add("1. " + "How many countries are in the UN? " + " " + "A. 158 " + "B. 193 " + "C. 64 " + "D. 123"); questions.add(" " + "If you wanted to take a gondola ride down the Grand Canal, what city would you have to visit? " + " " + "A. Paris, France " + "B. Venice, Italy " + "C. Moon, Space " + "D. Nile, Egypt"); questions.add("3. " + "Which of the following is used in pencils? " + " " + "A. Copper " + "B. Calcium " + "C. Iron " + "D. Graphite"); questions.add("4. " + "You are looking at the famous painting Starry Night. Who is the artist? " + " " + "A. Vincent van Gogh " + "B. Pablo Picasso " + "C. Leonardo da Vinci " + "D. Jackson Pollock"); questions.add("5. " + "Which Russian town suffered an infamous nuclear disaster in 1986? " + " " + "A. Kazan " + "B. Moscow " + "C. Chernobyl " + "D. Tula"); questionAnswerMap.put("1", "B"); questionAnswerMap.put("2", "B"); questionAnswerMap.put("3", "D"); questionAnswerMap.put("4", "A"); questionAnswerMap.put("5", "C"); } public void startQuestionAnswer() { } public static void main(String[] args) { TriviaGame triviaGame = new TriviaGame(1,5000,3); System.err.println(triviaGame.getDescription()); System.err.println("Enter your answer and press the enter key "); PlayGame g = new PlayGame(); g.initializeQuestionAnswers(); int count = 1; for(String question: g.questions) { System.out.println(question); System.out.println(" "); Scanner s = new Scanner(System.in); String answer = s.nextLine(); if(g.questionAnswerMap.get(String.valueOf(count)).equalsIgnoreCase(answer)) { g.answers.add(answer); } count++; } if(g.answers.size()>=triviaGame.getNumberOfquesToWin()) { System.out.println(" \t\t\t You won!\t \t \t "); System.out.println("Congratulations you answered "+g.answers.size()+" questions corrctly. "); System.out.println("Prize money : "+triviaGame.getUltimatePriceMoney()); } else { System.err.println("You lost the game. Please try again."); } } }

//sorry for repeat i was running out of time

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

Recommended Textbook for

Big Data Systems A 360-degree Approach

Authors: Jawwad ShamsiMuhammad Khojaye

1st Edition

0429531575, 9780429531576

More Books

Students also viewed these Databases questions

Question

Bring out the limitations of planning.

Answered: 1 week ago

Question

Why should a business be socially responsible?

Answered: 1 week ago

Question

Discuss the general principles of management given by Henri Fayol

Answered: 1 week ago

Question

Detailed note on the contributions of F.W.Taylor

Answered: 1 week ago