You will need to first create an object class encapsulating a Trivia Game which INHERITS from Game.
Game is the parent class with the following attributes:
Trivia is the subclass of Game with the additional attributes:
1. trivia game id - integer
2. ultimate prize money - double
3. number of questions that must be answered to win - integer.
4. write the accessor, mutator, constructor, and toString methods.
Write a client class to test creating 5 Trivia objects. Once you have successfully created Trivia objects, you will continue 6B by adding a linked list of trivia objects to the Trivia class.
Lab Assignment 6B
In 6A, you created an object class encapsulating a Trivia Game which INHERITS from Game.
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.
Done. Have a look and incase of any doubt please leave a comment.
CODE:
//////////////////////////////////////////////Game.java/////////////////////////////////////////////////////////////////////
public class Game {
private String description;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public String toString() {
return "Game [description=" + description + "]";
}
public Game(String description) {
this.description = description;
}
}
/////////////////////////////////////////////ENd
Game.java//////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////TriviaGame.java/////////////////////////////////////////////////////////////////////
public class TriviaGame extends Game {
private int gameId;
private double priceMoney;
private int numOfQuestion;
// Constructor
public TriviaGame(String description, int gameId, double
priceMoney, int numOfQuestion) {
super(description);
this.gameId = gameId;
this.priceMoney = priceMoney;
this.numOfQuestion = numOfQuestion;
}
public int getGameId() {
return gameId;
}
public double getPriceMoney() {
return priceMoney;
}
public int getNumOfQuestion() {
return numOfQuestion;
}
public void setGameId(int gameId) {
this.gameId = gameId;
}
public void setPriceMoney(double priceMoney) {
this.priceMoney = priceMoney;
}
public void setNumOfQuestion(int numOfQuestion) {
this.numOfQuestion = numOfQuestion;
}
@Override
public String toString() {
return "Trivia [gameId=" + gameId + ", price Money=" + priceMoney +
", num of Question=" + numOfQuestion
+ ", Description=" + getDescription() + "]";
}
// Override equals to compare to TriviaGame objects. Comparison is
done on the
// basis of GameId. This is used in the deletion of object in
TriviaLinkedList
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TriviaGame other = (TriviaGame) obj;
if (gameId != other.gameId)
return false;
return true;
}
}
/////////////////////////////////////////////////////End
TriviaGame.java/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////TriviaNode.java///////////////////////////////////////////////////////////////////////
public class TriviaNode {
private TriviaGame triviaObject; // TriviaGame object
private TriviaNode nextNode; // Pointer to the next node in the
list
// constructor
public TriviaNode(TriviaGame obj) {
triviaObject = obj;
nextNode = null;
}
@Override
public String toString() {
return "TriviaNode [triviaObject=" + triviaObject + ", nextNode=" +
nextNode + "]";
}
public TriviaGame getTriviaObject() {
return triviaObject;
}
public TriviaNode getNextNode() {
return nextNode;
}
public void setTriviaObject(TriviaGame triviaObject) {
this.triviaObject = triviaObject;
}
public void setNextNode(TriviaNode nextNode) {
this.nextNode = nextNode;
}
}
////////////////////////////////////////////////End
TriviaNode.java////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////TriviaLinkedList.java/////////////////////////////////////////////////////////////
public class TriviaLinkedList {
private TriviaNode head;
private int numberOfItems;
// counter to maintain number of items added in the
linkedList
private int counter = 1;
public TriviaLinkedList(TriviaNode head, int numberOfItems) {
super();
this.head = head;
this.numberOfItems = numberOfItems;
}
public void insertNode(TriviaNode newNode) {
// Add new element only if the linkedList has not reached the size
defined by
// NumberOfItems
if (!(counter >= numberOfItems)) {
newNode.setNextNode(head);
head = newNode;
counter++;
} else {
System.out.println("Can not add more items. Reacher max Number of
items");
return;
}
}
public void deleteNode(int id) {
// Store head node
TriviaNode tempNode = head, prev = null;
TriviaGame gameNode = new TriviaGame("", id, 0, 0);
// If head node itself holds the key to be deleted
if (tempNode != null &&
tempNode.getTriviaObject().equals(gameNode)) {
head = tempNode.getNextNode(); // Changed head
System.out.println("Node deleted successfully");
return;
}
// Search for the key to be deleted, keep track of the
// previous node as we need to change temp.next
while (tempNode != null &&
!(tempNode.getTriviaObject().equals(gameNode))) {
prev = tempNode;
tempNode = tempNode.getNextNode();
}
// If key was not present in linked list
if (tempNode == null) {
System.out.println("Cant find the node with the gameid=" +
id);
return;
}
// Unlink the node from linked list
prev.setNextNode(tempNode.getNextNode());
}
public TriviaNode getHead() {
return head;
}
public int getNumberOfItems() {
return numberOfItems;
}
public void setHead(TriviaNode head) {
this.head = head;
}
public void setNumberOfItems(int numberOfItems) {
this.numberOfItems = numberOfItems;
}
@Override
public String toString() {
return "TriviaLinkedList [head=" + head + ", numberOfItems=" +
numberOfItems + "]";
}
public void printList() {
TriviaNode tnode = head;
while (tnode != null) {
System.out.println(tnode.getTriviaObject() + " ");
tnode = tnode.getNextNode();
}
}
}
/////////////////////////////////////////////////End
TriviaLinkedList.java/////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////TriviaGameDriver.java//////////////////////////////////////////////////////////
public class TriviaGameDriver {
public static void main(String args[]) {
TriviaGame triviaObject1 = new TriviaGame("Math Quiz", 12, 250.0,
4);
TriviaGame triviaObject2 = new TriviaGame("Science Quiz", 13,
350.0, 5);
TriviaGame triviaObject3 = new TriviaGame("English Quiz", 14,
150.0, 3);
TriviaGame triviaObject4 = new TriviaGame("French Quiz", 15, 150.0,
3);
TriviaNode node1 = new TriviaNode(triviaObject1);
TriviaNode node2 = new TriviaNode(triviaObject2);
TriviaNode node3 = new TriviaNode(triviaObject3);
TriviaNode node4 = new TriviaNode(triviaObject4);
OUTPUT:

#Could you please leave me THUMBS UP for my work...
You will need to first create an object class encapsulating a Trivia Game which INHERITS from...
In 6A, you created an object class encapsulating a Trivia Game which INHERITS from Game. 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...
In JAVA, please In this module, you will combine your knowledge of class objects, inheritance and linked lists. You will need to first create an object class encapsulating a Trivia Game which INHERITS from Game. Game is the parent class with the following attributes: 1. description - which is a string 2. write the constructor, accessor, mutator and toString methods. Trivia is the subclass of Game with the additional attributes: 1. trivia game id - integer 2. ultimate prize money...
Write a class encapsulating the concept of a vendor, if a vendor has the following attributes: company name, id, array of quarterly purchase order totals (4 double elements). Include a constructor, accessor, mutator, and toString methods. Also code the following methods: one returning the total purchase orders (total all array elements) and a method to modify an array element (change the value of an array element). Write a client class to create 2 vendor objects and test all your methods.
Write a class encapsulating a music store, which inherits from Store. A music store has the following additional attributes: the number of titles it offers and its address. Code the constructor and the toString method of the new class. You also need to include a client class (with the main method) to test your code.
In Java, Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following additional attributes: how many people are served every year and the average price per person. code the constructor, accessors, mutators, toString and equals method of the new subclass; also code a method returning the average taxes per year. You also need to include a client class to test your code for both the parent class and the subclass. Code for Store below(Super class aka...
Write a class Store which includes the attributes: store name, city. Write another class encapsulating an Art Gallery, which inherits from Store. An Art Gallery has the following additional attributes: how many paintings are sold every year and the number of artists submitting artwork. Code the constructor, accessors, mutators, toString and equals method of the super class Store. Code the constructor, accessors and mutators for the subclass Art Gallery. In the Art Gallery class, also code a method returning the...
Create the following program in java please Write a class Store which includes the attributes: store name and sales tax rate. Write another class encapsulating a Book Store, which inherits from Store. A Book Store has the following additional attributes: how many books are sold every year and the average price per book. Code the constructor, accessors, mutators, toString and equals method of the super class Store and the subclass Book Store; In the Book Store class, also code a...
Using Java Write a class encapsulating the concept of student grades (50 elements) on a test, assuming student grades are composed of a list of integers between 0 and 100. Write the following methods: A constructor with just one parameter, the number of students; all grades can be randomly generated Accessor, mutator, toString, and equals methods A method returning the highest grade A method returning the average grade A method returning the lowest grade Write a client class to test...
IN JAVA Write a class Store which includes the attributes: store name, city. Write another class encapsulating an Art Gallery, which inherits from Store. An Art Gallery has the following additional attributes: how many paintings are sold every year and the number of artists submitting artwork. Code the constructor, accessors, mutators, toString and equals method of the super class Store. Code the constructor, accessors and mutators for the subclass Art Gallery. In the Art Gallery class, also code a method...
Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...