Question
Objectives Use LinkedList to create a wrapper class. Make sure to read the sample output. Create Class: Magazine Magazine will be a simple class consisting
Objectives
Use LinkedList to create a wrapper class.
Make sure to read the sample output.
Create Class: Magazine
Magazine will be a simple class consisting of four fields:
name: string representing the name of the magazine, such as Fashion
edition: int representing the edition number of the magazine such as 10
publishYear: int representing the year the magazine has been published such as 2019
pages: int number of pages of the magazine such as 50
Your Magazine class should have the following methods:
Magazine (name, edition, publishYear,pages) throws InvalidMagazineException // Constructor
String getName(): // Returns a Magazines name
int getEdition(): // Returns a Magazines edition
int getPublishYear()://Returns a Magazines publish year
int getPages() : //Returns a Magazines pages
@Override
public String toString(){
return "Name: " + name + " Edition: " + edition + " Publish Year: "+ publishYear+
" Pages: " + pages;
}
The constructor should throw an InvalidMagazineException if any of the following are true:
The name is an empty string.
The edition is less than 1
The publishYear is less than equal to 2000
The pages is less than equal to zero.
Heres something important to remember: no methods should use standard input or output. They should neither pause to read in input or display any output.
Nodes
The Node class must be represented as a generic class.
The Node class will require these private fields.
T data: The data to hold in the Node
Node
Node
This class must implement setter/getter for the three variables (3 setter methods and 3 getter methods)
This class must implement three constructors to initialize the variables based on the given values:
public Node(T value)
public Node(T value, Node
public Node(T value, Node
Linked List
This class will require the following fields:
Node
Node
int size: Keeps a count of the number of Nodes in the chain
Your LinkedList class must also support the following public methods.
LinkedList(): A default constructor sets both pointers to null and sets the size to 0.
int size(): Returns the size of the LinkedList.
void push_back(T): Creates a new Node and assigns it to the end of the list of Nodes while updating the size by 1.
void push_front(T): Creates a new Node and assigns it to the front of the list of Nodes while updating the size by 1.
T pop_back() throws ListEmptyException: Deletes the Node at the end of the list (or throws a ListEmptyException if this is not possible). Decreases size by 1. Returns the deleted element.
T pop_front() throws ListEmptyException: Deletes the Node at the front of the list (or throws a ListEmptyException if this is not possible). Decreases size by 1. Returns the deleted element.
T at(int) throws ListException: Returns the element stored at the specified index. If the index is out-of-bounds (either for being negative or greater than/equal the size of the list), throw a ListException with the message "Index out of bounds. This method should operate at for accessing the first or last element in a list and at for any element other than the first or the last.
T front() throws ListEmptyException: Returns the first element (throws a ListEmptyException if the list is empty)
T back() throws ListEmptyException : Returns the last element (throws a ListEmptyException if the list is empty)
void printAll(): prints all the nodes in the LinkedList
Create Wrapper Class: Library
Write a wrapper class called Library for a listing of magazines. This wrapper class will maintain a list of all magazines and will return which magazine has the highest number of pages. A wrapper class is a class that acts as decoration for another class (in this case, class LinkedList). Theres only one field to this class:
magazines: LinkedList of type Magazine
Your Library should have the following methods:
public Library() : the constructor that initializes the magazines variable
void addMagazine(Magazine): Adds a magazine to the listing of magazines
int getCount():Returns the number of magazines currently in this data structure
Magazine getMagazineWithHighestNumberOfPages(): Returns the Magazine with the highest number of pages. If there is a tie among multiple Magazines, return the Magazine that was entered first. If the list is empty, throw a ListEmptyException.
Magazine get(int i): Returns the Magazine which is at position i.
int getNumberOfMagazinesHavePagesMoreThan(int pages): Counts and returns the number of Magazines in the data structure that have more pages that the passed parameter.
void printAllMagazines(): calls the methods printAll from the magazines object.
Like the previous class file, this class should not read in any input or display any output. The methods in this class may call the methods of class LinkedList. For example, when inside the method addMagazine you may call the pushback function of the class LinkedList. The methods in this class must catch the exceptions thrown by the Magazine class.
Create the Driver Application
Create a driver application that demonstrates that each of the components of your program work. This class is called LibraryManagement and must contain the main method. Create an empty Library structure with which to work. Create an interactive menu that gives the user the following choices and then performs that choice:
Add Magazine. The program will prompt the user for a name, an edition, a publish year, and a number of pages. The program will create that object and pass it to the data structure via a call to addMagazine.
Get count. Prints to the screen the number of Magazines in the data structure.
Get the Magazine with the highest number of pages. Prints to the screen the name, edition, publish year and pages of the current Magazine with the highest number of pages in the data structure.
Get number of Magazines have the number of pages more than N. Asks the user for an integer and then returns the number of Magazines have the number of pages more than that integer entered. (Entering a length of 0 should return the count of all Magazines.)
Print All magazines: prints all the added magazines
Quit. Quits the application.
What to turn in.
Zip up your Java files with these files:
Magazine.java
Library.java
LinkedList.java
Node.java
LibraryManagement.java
ListException.java
ListEmptyException.java
InvalidMagazineException.java
All your exception classes must inherit from class Exception.
Classes LinkedList.java, Node.java must be in a package called linkedlist
Classes Magazine.java, Library.java, LibraryManagement.java must be in a package called library
Classes ListException.java, ListEmptyException.java, InvalidMagazineException.java must be in a package called linkedlist.exception
A Sample output:
Welcome to my library management system
Choose an option from 1 to 6
1.Add magazine
2.Get magazines count
3.Get the Magazine with the highest number of pages
4.Get number of Magazines have the number of pages more than ?
5.Print all magazines
6.Quit
1
Enter magazine's name: Science Journal
Enter magazine's edition: 25
Enter magazine's publish year: 2020
Enter magazine's pages: 200
The magazine added successfully
Choose an option from 1 to 6
1.Add magazine
2.Get magazines count
3.Get the Magazine with the highest number of pages
4.Get number of Magazines have the number of pages more than ?
5.Print all magazines
6.Quit
1
Enter magazine's name: Chemistry Journal
Enter magazine's edition: 45
Enter magazine's publish year: 2019
Enter magazine's pages: 300
The magazine added successfully
Choose an option from 1 to 6
1.Add magazine
2.Get magazines count
3.Get the Magazine with the highest number of pages
4.Get number of Magazines have the number of pages more than ?
5.Print all magazines
6.Quit
1
Enter magazine's name:
Enter magazine's edition: 20
Enter magazine's publish year: 2009
Enter magazine's pages: 200
Cannot have empty name
Choose an option from 1 to 6
1.Add magazine
2.Get magazines count
3.Get the Magazine with the highest number of pages
4.Get number of Magazines have the number of pages more than ?
5.Print all magazines
6.Quit
2
Number of magazines in the library: 2
Choose an option from 1 to 6
1.Add magazine
2.Get magazines count
3.Get the Magazine with the highest number of pages
4.Get number of Magazines have the number of pages more than ?
5.Print all magazines
6.Quit
3
Name: Chemistry Journal Edition: 45 Publish Year: 2019 Pages: 300
Choose an option from 1 to 6
1.Add magazine
2.Get magazines count
3.Get the Magazine with the highest number of pages
4.Get number of Magazines have the number of pages more than ?
5.Print all magazines
6.Quit
4
Enter the page count:
200
There are 1 magazine(s) having number of the pages more than 200
Choose an option from 1 to 6
1.Add magazine
2.Get magazines count
3.Get the Magazine with the highest number of pages
4.Get number of Magazines have the number of pages more than ?
5.Print all magazines
6.Quit
4
Enter the page count:
100
There are 2 magazine(s) having number of the pages more than 100
Choose an option from 1 to 6
1.Add magazine
2.Get magazines count
3.Get the Magazine with the highest number of pages
4.Get number of Magazines have the number of pages more than ?
5.Print all magazines
6.Quit
4
Enter the page count:
600
There are 0 magazine(s) having number of the pages more than 600
Choose an option from 1 to 6
1.Add magazine
2.Get magazines count
3.Get the Magazine with the highest number of pages
4.Get number of Magazines have the number of pages more than ?
5.Print all magazines
6.Quit
5
Name: Science Journal Edition: 25 Publish Year: 2020 Pages: 200
Name: Chemistry Journal Edition: 45 Publish Year: 2019 Pages: 300
Choose an option from 1 to 6
1.Add magazine
2.Get magazines count
3.Get the Magazine with the highest number of pages
4.Get number of Magazines have the number of pages more than ?
5.Print all magazines
6.Quit
7
Wrong choice! Try again
Choose an option from 1 to 6
1.Add magazine
2.Get magazines count
3.Get the Magazine with the highest number of pages
4.Get number of Magazines have the number of pages more than ?
5.Print all magazines
6.Quit
6
Thank you for using the library system
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