Must be written in java. Thank you. This project will have you write a program t
ID: 3681806 • Letter: M
Question
Must be written in java. Thank you.
This project will have you write a program to be used by the Library to keep an online list of all the Album in it'scatalog. The program will present a menu to the user (the librarian) to enable him/her to add aALBUM title, delete aALBUM title, find aALBUM title, and list all the ALBUM titles available. The record for eachALBUM must contain the following information:
The ALBUMAlbum Title (string)
The ALBUM Artist (string)
The number of tracks on the ALBUM (int)
The Library tracking number for the ALBUM (long int)
Number of copies that the library owns
To Do List
Must present a menu to the user to choose from, as shown below.
If ADD is chosen, must ask for the five data items shown, and add the ALBUM record to the list. However:
Before adding aALBUM, must check to see if the library tracking number already exists in a record on the list. If it does, then the program must compare the new album title against the existing record. If they match, then it should just increment the number of copies field in the existing record by adding the number of new copies that the user has just entered to the value in the existing copies field. If the titles don't match, it should give the user an error message telling them that the tracking number is already in use, and NOT add the ALBUM to the list and NOT increment anything.
If the tracking number does not exist on the list at all, then add the new record to the end of the list
Make sure that the tracking number, number of copies and number of tracks are all positive, non-zero integers.
If DELETE is chosen, ask the user for the tracking number to delete. If a record with that tracking number is found, then check its number of copies field. If that field equals 1, then delete the record from the list. If it is greater than one, then ask the user whether to delete only one copy, or to delete all copies of that album. If they choose all, then delete the entire record. If they choose one, then just decrement the number of copies field for that record by one.
If FIND is chosen, then ask the user whether to find by album title, or tracking number. Whichever they choose, then ask them either for the album title or the tracking number to look for. Search the linked list of records for that title or tracking number. If it is not found, then print a message to that effect, such as "AALBUM with tracking number 2494922 cannot be found". If it is found, then print out the information from the ALBUM, as shown in the Operation section below.
If LIST is chosen, write a well-formatted report of all the ALBUMs that are on the linked list to the console. In a real program, we might want to print this list sorted by artist, tracking number, etc., but for this program, you can just print the records in the order that they occur on the list.
If QUIT is chosen, print a nice "goodbye" message to the user, and quit the program. In a real program, you would want to "serialize" the records into a disk file or some other permanent storage, so that they could be read back in the next time you start the program. For now, we'll avoid storing the records and make the poor librarian retype all the ALBUM records every morning when he opens the library and starts the program...
Design
You should write a class called ALBUMRecord that holds the five data items defined above, and a next reference so that it can be used in your linked list. This should be a well-designed class that protects it's data, has good defaults, etc.
You should write aALBUMList class that models a linked list of ALBUMRecord objects. Follow class example.
You will write aALBUMLibrary class that contains the main method that should "drive" the program. It will have an "event loop" that will call methods as required on aALBUMLibrary object to ask the user for input, to process user input, etc. You will have one main function, and a number of other functions that should be used to perform various actions. The main program itself should be fairly short, and will probably have a while loop, with a switch statement inside to process the user's choices by calling functions. Do not make any method in ALBUMLibrary other than main static unless you have a good design reason, and explain that reason in your method comment.
The flow chart below shows the basic decision flow for the requirements discussed in the overview section above.
When you start the program, print out a nice welcome message, and then present the main menu to the user. The figure to the right shows the basic look and feel of the program. This session shows the program startup, and then adding three ALBUM Records and listing them back to the screen. You need to present the menu to the user after each command completes. The user should never have to guess, or remember all the commands because they have scrolled off the screen.
Implementation Notes
a) You are not allowed to use any of the Java library data structure classes to implement the actual linked list, even if you've studied ahead and know how. You must implement your own linked list from scratch.
b) Each operation on the linked list (ADD, DELETE, LIST, etc) must be defined within a separate function. You will probably need other "helper" functions as well.
c) Your main program should be as small and as descriptive as possible. Functions should be reasonably small. Follow the guidance that "A function should do one thing, and do it well".
d) You should trap basic NumberFormatExceptions, as well as other basic input exceptions so that the user cannot crash your program with a simple typo.
e) You need to capture and deal with other types of bad input as well that don't cause exceptions. If the user enters a command that you don't understand (e.g., ZDD instead of ADD), you should notify them, and continue. Do NOT quit the program on these types of errors. You should print an informative error message (for the user) and continue.
f) Comment your code!
j) You MUST follow the order of input in the example above. If I enter "ADD" in your program, I expect to then enter aALBUM title, an artist name, etc, in that order. You should also duplicate the output as shown above as closely as possible. I won't take off for minor spacing differences, but if you do not print nicely formatted menus, prompts, etc., you will lose points. You must use the same capitalization of commands as well.
Explanation / Answer
Project1.java
/*This program uses a Linked List to store CD records for a library.*/
import java.util.Scanner; //for user input
//driver class
public class Project1
{
public static void main(String[] args)
{
Library.printWelcome();
Scanner keyboard = new Scanner(System.in); //for user's menu choice
while(true) //keep program running until user selects quit
{
Library.printMenu();
String input = keyboard.nextLine().toUpperCase();
switch (input)
{
case "ADD":
Library.add();
break;
case "DELETE":
Library.delete();
break;
case "FIND":
Library.find();
break;
case "LIST":
Library.list();
break;
case "QUIT":
keyboard.close();
System.exit(0);
default:
System.out.println("Please enter either ADD, DELETE, FIND, LIST"
+ " or QUIT.");
}
}
}
}
LinkedList.java
/*The LinkedList class is an implementation of a doubly linked list as an abstract
* data type. It can store any type of object. It is also possible to iterate
* through the a objects of the class by implementation of the Iterable interface. */
public class LinkedList<AnyType> implements Iterable<AnyType>
{
private static class ListNode<AnyType>
{
public AnyType data;
public ListNode<AnyType> prev;
public ListNode<AnyType> next;
public ListNode(AnyType d, ListNode<AnyType> p, ListNode<AnyType> n)
{
data = d;
prev = p;
next = n;
}
}
private ListNode<AnyType> first;
private ListNode<AnyType> last;
private int length;
public LinkedList(){
first = new ListNode<AnyType>(null, null, null);
last = new ListNode<AnyType>(null, first, null);
first.next = last;
length = 0;
}
public void add(AnyType d)
{
ListNode<AnyType> toAdd = new ListNode<AnyType>(d, first, first.next);
first.next.prev = toAdd;
first.next = toAdd;
length++;
}
private void remove(ListNode<AnyType> p)
{
p.next.prev = p.prev;
p.prev.next = p.next;
length--;
}
public java.util.Iterator<AnyType> iterator()
{
return new LinkedListIterator(first.next);
}
private class LinkedListIterator implements java.util.Iterator<AnyType>
{
private ListNode<AnyType> current;
public LinkedListIterator(ListNode<AnyType> start)
{
current = start;
}
public boolean hasNext()
{
return (current!=last);
}
public AnyType next()
{
if (current==null)
throw new NullPointerException("Linked list empty.");
AnyType nextItem = current.data;
current = current.next;
return nextItem;
}
public void remove()
{
LinkedList.this.remove(current.prev);
}
}
}
CDRecord.java
/*The CDRecord class is a class that represents the CD records that the librarian
* using the program wishes to represent and store.*/
public class CDRecord
{
private String AlbumTitle;
private String Artist;
private int numOfTracks;
private long libraryTrackingNumber;
private int numOfCopies;
public CDRecord(String title, String artistName, int trackCount,
long libTrackNum, int copyCount)
{
AlbumTitle = title;
Artist = artistName;
numOfTracks = trackCount;
libraryTrackingNumber = libTrackNum;
numOfCopies = copyCount;
}
public String toString(){
return ("Album Title:" + AlbumTitle + " " + "Artist:" + Artist +
" " + "Number of Tracks:" + numOfTracks + " " +
"LibraryTrackingNumber:" + libraryTrackingNumber + " " +
"Number of Copies:" + numOfCopies);
}
public String getTitle()
{
return AlbumTitle;
}
public long getTracking()
{
return libraryTrackingNumber;
}
public int getNumOfCopies()
{
return numOfCopies;
}
public void addCopy()
{
numOfCopies++;
}
public void removeCopy()
{
numOfCopies--;
}
}
sample output
Compile and Execute Java-8 Online
****************************************
Welcome to the Queens Library
CD Database System!
****************************************
Choose from the following:
ADD: Add a new Record to the list.
DELETE : Delete a Record from the list.
FIND : Find an existing Record in the list.
LIST : Print all current Records to the screen.
QUIT : Quit the CD Database System.
Type your choice:ADD
Enter Album Title:song
Enter Artist Name:rahman
Enter Number of Tracks:5
Enter Library Tracking Number:123
Enter Number of Copies:25
Choose from the following:
ADD: Add a new Record to the list.
DELETE : Delete a Record from the list.
FIND : Find an existing Record in the list.
LIST : Print all current Records to the screen.
QUIT : Quit the CD Database System.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.