Question & Answer: Write a command-line utility called cddb to maintain a flat-file database of album information. You will…..

Write a command-line utility called cddb to maintain a flat-file database of album information. You will allow the user to view album info, add a new entry, or delete an entry, where each entry is an album w/all of the track information, as follows:

Options, and Descriptions

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: Write a command-line utility called cddb to maintain a flat-file database of album information. You will…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay

-l — List album

Display an enumerated, alphabetical list of artists

You will allow the user to choose an artist by entering the number, or to quit by entering a q

You will then list all albums, by release date, enumerated

Allow the user to choose an album, by #, or return to the menu above (artists) by entering a

If an album is entered, list all songs in that album, by track order. Prompt for input to return to the previous (i.e., the album) menu

-d — Delete album. Similar to above, display menus allowing a user to choose an album to delete

-a — Add album. You’ll prompt for artist, album name, release date, and finally the track list. You may assume that they are entered in track order.
You’ll want to check that the album doesn’t already exist before adding it

-h — Show usage msg and quit

You may assume that all names are entered exactly. That is, do not worry about inconsistencies in spelling or capitalisation. E.g., Led ZeppelinLedZeppelin, and led zeppelin are 3 different groups for this assignment.

If no argument is supplied, a bad argument is supplied, or multiple arguments, print a usage message and exit.

File Format

Album information will be stored in a flat file w/the format shown in sample.db:

To simplify things, the filename (location of the DB) will be stored in an exported environment variable, $CDDB .

Target Language

You can do this in any language you choose, including Bash or AWK. The language must be currently hosted on the tux machines.

If you, e.g., do this in Java, then you’ll need to supply a shell script called cddb that invokes your program, the JRE, whatever, w/the arguments.

Expert Answer

 

Please comment if you need more help. This is Java Programme

How to Run :-

—————————————-

1. Crate a new Folder , copy all files here only

2.Crate Java files Album.java , AlbumManager.java and AlbumDemo.java with any Text Editor and Copy paste the Source code below in Respective Java file

3. Create a file “MyPlayList.sh” in any text editor (Script to run is mentioned below please check)

copy script file text into it and save

4. If you are using Linux machine

4.1 Open Terminal

4.2 CD to your folder

4.3 run command sh ./MyPlayList.sh

your programme will run

 

Script file for execution :

———————————————-

#!/bin/bash
javac Album.java
javac AlbumManager.java
javac AlbumDemo.java
java AlbumDemo

Album.java file :-

————————————————-

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/*
* This class represents a album
* Contains Artist, Album Name , Release Date and Track list
*/
public class Album implements Comparable{
String artist,albumName;
Date releaseDate;
List<String> trackList = new ArrayList<String>();

public int compareTo(Object arg0) {
// TODO Auto-generated method stub
Album album = (Album)arg0;
return this.releaseDate.compareTo(album.releaseDate);
}

}

AlbumManager.java file :-

————————————————-

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

/*
* This class manages all activities of Albums
* Add / Remove/ Get Album ….
*/
public class AlbumManager {

//Album List
private List<Album> albumList = new ArrayList<Album>();
//Java Comporator to sort the list simply
Comparator<Album> albumListComporator = new Comparator<Album>() {

public int compare(Album album1, Album album2) {
// Compare release dates of Albumes , based on this Java will sort the list
return album1.releaseDate.compareTo(album2.releaseDate);
}
};
Scanner sc=new Scanner(System.in);

public void getAlbum(){
Album album = new Album();
//ask user artist
System.out.println(“Enter artist”);
album.artist = sc.next();
if(album.artist == null || album.artist.trim().equals(“”)){
System.out.println(“Enter valid artist”);
album = null;
//Stop application
System.exit(0);
}

//ask user album name
System.out.println(“Enter album name”);
album.albumName = sc.next();
if(album.albumName == null || album.albumName.trim().equals(“”)){
System.out.println(“Enter valid album name”);
album = null;
//Stop application
System.exit(0);
}
if(checkAlbumExist(album.albumName)){
album = null;
return;
}
//ask user date
System.out.println(“Enter album creation Date in yyyy-MM-dd format”);
//If user enters wrong date then Exception will come and Programme should terminate
try{
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”);
Date date1 = sdf.parse(sc.next());
album.releaseDate = date1;
}
catch(Exception e){
System.out.println(“Enter valid Date”);
album = null;
//Stop application
System.exit(0);
}

//Ask user for Track list , user will enter a name or ‘quit’ to quit

while(true){
System.out.println(“Enter artist or ‘quit’ to stop entering”);
String track = sc.next();
if(track == null || track.trim().equals(“”)){
System.out.println(“Enter valid track name”);
album = null;
//Stop application
System.exit(0);
}
else if (track.trim().equalsIgnoreCase(“quit”)){
albumList.add(album);
break;
}
else{
album.trackList.add(track);
}

}

}

public boolean checkAlbumExist(String name){
boolean found = false;
for(int i = 0 ; i < albumList.size() ; i++){
if(albumList.get(i).albumName.equalsIgnoreCase(name)){
found = false;
break;
}
}
return found;
}

public void showAlbums(){
System.out.println(“Sno    |   Atrist       |    Album Name       |   Release Date   “);
Collections.sort(albumList);
for(int i = 0 ; i < albumList.size() ; i++){
System.out.println(Integer.toString(i+1) + “. ” + albumList.get(i).artist +” ” + albumList.get(i).albumName + ” ” + albumList.get(i).releaseDate.toString());
}

}

public void showTracks(int albumNum){
for(int i = 0 ; i < albumList.get(albumNum).trackList.size() ; i++){
System.out.println(   albumList.get(albumNum).trackList.get(i));
}
}

public void deleteAlbum(int albumNum){
albumList.remove(albumNum);
}

public int getAlbumSize(){
return albumList.size();
}

}

AlbumDemo.java file (Main Method) :-

—————————————————————

import java.util.Scanner;

public class AlbumDemo {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
AlbumManager manager = new AlbumManager();
Scanner sc=new Scanner(System.in);

while(true){
System.out.println(“Enter your option or ‘-h’ for help”);

String option = sc.next();

if(option == null || option.trim().equals(“”)){
System.out.println(“Enter Valid option”);
continue;
}
if(option.equals(“-h”)){
System.out.println(“-a — Add album”);
System.out.println(“-l — List album”);
System.out.println(“-d — Delete album”);
}
else if(option.equals(“-a”)){
manager.getAlbum();
}
else if(option.equals(“-l”)){
if(manager.getAlbumSize() == 0){
System.out.println(“No Albums found in Database”);
continue;
}
manager.showAlbums();
System.out.println(“Enter Album Number to select or ‘q’ to quit”);
String achoice = sc.next();
if(achoice == null || achoice.trim().equals(“”)){
System.out.println(“Enter Valid option”);
System.exit(0);
}
if(achoice.trim().equals(“q”)){
System.exit(0);
}
else{
int albumNum = 0;
try{
albumNum = Integer.parseInt(achoice);
}
catch(Exception e){
System.out.println(“Enter Valid option”);
System.exit(0);
}

manager.showTracks(albumNum-1);
System.out.println(“Enter ‘a’ to return next menu”);
achoice = sc.next();
if(achoice == null || achoice.trim().equals(“”)){
System.out.println(“Enter Valid option”);
System.exit(0);
}
else if(achoice.trim().equals(“a”)){
continue;
}
else{
System.out.println(“Enter Valid option”);
System.exit(0);
}

}
}
else if(option.equals(“-d”)){
if(manager.getAlbumSize() == 0){
System.out.println(“No Albums found in Database”);
continue;
}
System.out.println(“Enter Album Number to delete”);
String achoice = sc.next();
if(achoice == null || achoice.trim().equals(“”)){
System.out.println(“Enter Valid option”);
System.exit(0);
}
int albumNum = 0;
try{
albumNum = Integer.parseInt(achoice);
}
catch(Exception e){
System.out.println(“Enter Valid option”);
System.exit(0);
}
manager.deleteAlbum(albumNum-1);
}
}

}

}

Sample Output :-

—————————————

Enter your option or '-h' for help
-a
Enter artist
Ram
Enter album name
RamAlbum
Enter album creation Date in yyyy-MM-dd format
2017-09-23
Enter artist or 'quit' to stop entering
Ar1
Enter artist or 'quit' to stop entering
Ar2
Enter artist or 'quit' to stop entering
Ar3
Enter artist or 'quit' to stop entering
quit
Enter your option or '-h' for help
-l
Sno     |       Atrist            |           Album Name                    |   Release Date    
1.      Ram     RamAlbum       Sat Sep 23 00:00:00 IST 2017
Enter Album Number to select or 'q' to quit
1
Ar1
Ar2
Ar3
Enter 'a' to return next menu
a
Enter your option or '-h' for help
-h
-a — Add album
-l — List album
-d — Delete album
Enter your option or '-h' for help
-d
Enter Album Number to delete
1

Grand Paper Writers
Order NOW For A 10% Discount!
Pages (550 words)
Approximate price: -

Our Advantages

Plagiarism Free Papers

All papers are written by the best professional writers to ensure 100% originality. We always provide plagiarism reports whenever we deliver completed papers.

Free Revisions

All papers by Grand Paper Writers are completed and submitted on time. This timely delivery of papers gives you time to go through the paper before the official deadline.

Title-page

As an additional service, we will provide a title page that precedes the contents of your paper. Here, you will provide your personal details.

Bibliography

We also ensure that we provide an extra page for the references or bibliographies following referencing rules.

Originality & Security

At Grandpaperwriters.com, we guarantee students for the provision of security and original work. All your personal information is handled with confidentiality and is not shared with third parties. Additionally, we ensure that we provide original content with accompanying plagiarism reports to show originality.

24/7 Customer Support

Our customer support team is always available 24/7 to provide instant responses to any queries raised by students.

Try it now!

Calculate the price of your order

We'll send you the first draft for approval by at
Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

Grandpaperwriters.com has the best professional essay writers for quality services.

Pricing

Flexible Pricing

Here, a Grandpaperwriters.com, we do not compromise on the time of our clients. We always deliver all completed papers on or before the deadlines.

Communication

Admission Help & Client-Writer Contact

Grandpaperwriters.com provides an interactive portal where students can communicate directly to their writers.

Deadlines

Paper Submission

Here, a Grandpaperwriters.com, we do not compromise on the time of our clients. We always deliver all completed papers on or before the deadlines.

Reviews

Customer Feedback

Grandpaperwriters.com appreciates feedback from our clients to help us improve the delivery of essay writing services. As such, we are constantly changing our policies to ensure maximum customer and writer satisfaction.