Skip to content

Instantly share code, notes, and snippets.

@zoglun
Last active August 29, 2015 14:20
Show Gist options
  • Save zoglun/c655bfc704b1d4f154d2 to your computer and use it in GitHub Desktop.
Save zoglun/c655bfc704b1d4f154d2 to your computer and use it in GitHub Desktop.
DVD rental
// Hey, you. following codes are not correct nor complete.
// If you find this on github. Don't copy code. You will lose points.
You are creating a text-based dvd-rental store. Each dvd will contain information for
the DVD title (String), genre (comedy, drama, documentary, horror, romance, musical),
original rental price (double), sale price (double), onSale (boolean),
numberOfTimesRented(integer) and isCurrentlyRented (boolean). While the dvd rental
store program is running, the interface should look like this:
Welcome to the DVD Store! Select an option below:
1) add an DVD
2) remove an DVD
3) display inventory
4) on sale / off sale
5) display genre
6) rent DVD
7) quit
Select an option above:
You will maintain a sorted linked list data structure to hold the store’s information.
For extra credit points, your app will be demonstrated and the code reviewed by two
peers and one course assistant at one of the last lab/sections of the semester. Partial
credit will be given for non-working code. Important: For maximum credit, in addition to
a fully-functioning app, reviewers will be looking for good coding style such as proper
indentation, liberal use of constructors, data encapsulation, a short ‘main’ method and
extensive use of subprograms. Use recursive methods whenever possible. Your code
must also be checked into your subversion archive.
The following app behaviors will be expected for each option:
1) add - The user will be prompted for a title of a new DVD and a price (original price).
The store will add the DVD in the appropriate location in the alphabetically
sorted (by title) inventory, provided the DVD name does not already exist in the
list. If it exists, the user will be prompted for an alternate DVD title.
2) remove - the user will be prompted for a title. The DVD with that title will be
removed from the inventory.
3) display inventory - the current inventory of the store will be displayed in
alphabetical order - DVD title, current rental price and number of times the DVD
was rented. Display information about the DVD only if it is currently NOT
rented. Price displayed is the original rental price unless the DVD is currently
on sale, then display the sale price. As a promotional tool, if the price is 0.00,
display “Currently Free!” next to the DVD listing. If it is on sale, display “On
Sale!” next to the DVD.
4) on sale / off sale - the user will be prompted for a title. The ‘on sale’ status of the
DVD will be toggled. If the ‘on sale’ status of the DVD is now true the user will
be prompted for a sale price. The sale price will be displayed instead of the
original price whenever a DVD is on sale (see 3, above).
5) display genre - the user will be prompted for the genre of movie they are interested
in. The current inventory of the store for the selected genre will be displayed in
alphabetical order - DVD title, current price, and number of times rented. Price
displayed is the original price unless the DVD is currently on sale, then display
the sale price. As a promotional tool, if the price is 0.00, display “Currently
Free!” next to the DVD. If it is on sale, display “On Sale!” next to the DVD.
6) rent DVD - the current store inventory will be displayed in alphabetical order. Then,
the user will be prompted for which DVD he/she would like to rent. A warning
message will be displayed: “Are you sure you would like us to deduct $X from
your credit card?” The user can answer yes, or no. A count of the number of
times each DVD is rented is maintained as part of the store inventory.
7) quit - the user will receive a prompt (“Are you sure you want to quit? - all your data
will be lost.”) If the user replies yes, the app quits.
public class dvdRentalStore {
public static void main(String[] args) {
boolean exit = false;
while (exit != true) {
System.out.print("Welcome to the DVD Store! Select an option below: \n\n 1) add an DVD \n 2) remove an DVD \n 3) display inventory \n 4) on sale / off sale \n 5) display genre \n 6) rent DVD \n 7) quit \n Select an option above:");
int instruction = TextIO.getlnInt();
if (instruction == 1 ){
System.out.println("1) add an DVD");
System.out.println("Type in the Titile:");
String title = TextIO.getln();
System.out.println("Type in the price$:");
double price = TextIO.getlnDouble();
System.out.println("Choice the genre of this DVD form below (type in number): \n 1:comedy, 2:drama, 3:documentary, 4:horror, 5:romance, 6:musical");
int genre = TextIO.getlnInt();
DVDmethod.add(title, price, genre);
}else if (instruction == 2) {
System.out.println("2) remove an DVD");
}else if (instruction == 3) {
System.out.println("3) display inventory");
}else if (instruction == 4) {
System.out.println("4) on sale");
}else if (instruction == 5) {
System.out.println("5) display genre");
}else if (instruction == 6) {
System.out.println("6) rent DVD");
}else if (instruction == 7) { //done
System.out.println("7) quit \n Are you sure you want to quit? - all your data will be lost.");
String checkExit = TextIO.getln();
if (checkExit.equals("yes") ) {System.out.println("Bye~"); System.exit(0); }
}
}
}
}
public class DVDdata { //maintain a sorted linked list data structure (For my point of view this is a very stupid idea. Why not ordered by array number?)
String Titile;
int genre; //here I set the comedy 1, drama 2, documentary 3, horror 4, romance 5, musical 6
double originalRentalPrice;
double salePrice;
boolean onSale;
int numberOfTimesRented;
boolean isCurrentlyRented;
public DVDdata next;
public DVDdata (String T, int g, double oRP, double sP, boolean oS, int nOTR, boolean iCR, DVDdata n) {
this.Titile = T;
this.genre = g;
this.originalRentalPrice = oRP;
this.salePrice = sP;
this.onSale = oS;
this.numberOfTimesRented = nOTR;
this.isCurrentlyRented = iCR;
this.next = n;
}
public class DVDlist {
DVDdata f = new DVDdata( "musicalExample" , 6, 600, 606, false, 6, false, null) ;
DVDdata e = new DVDdata( "romanceExample" , 5, 500, 505, false, 5, false, f) ;
DVDdata d = new DVDdata( "horrorExample" , 4, 400, 404, false, 4, false, e) ;
DVDdata c = new DVDdata( "documentaryExample", 3, 300, 303, false, 3, false, d) ;
DVDdata b = new DVDdata( "dramaExample" , 2, 200, 202, false, 2, false, c) ;
DVDdata a = new DVDdata( "comedyExample" , 1, 100, 101, true, 1, false, b) ;
int DVDcount = 6;
DVDlist dl = new DVDlist();
}
public String getTitile() {
return Titile;
}
public void setTitile(String titile) {
Titile = titile;
}
public int getGenre() {
return genre;
}
public void setGenre(int genre) {
this.genre = genre;
}
public double getOriginalRentalPrice() {
return originalRentalPrice;
}
public void setOriginalRentalPrice(double originalRentalPrice) {
this.originalRentalPrice = originalRentalPrice;
}
public double getSalePrice() {
return salePrice;
}
public void setSalePrice(double salePrice) {
this.salePrice = salePrice;
}
public boolean isOnSale() {
return onSale;
}
public void setOnSale(boolean onSale) {
this.onSale = onSale;
}
public int getNumberOfTimesRented() {
return numberOfTimesRented;
}
public void setNumberOfTimesRented(int numberOfTimesRented) {
this.numberOfTimesRented = numberOfTimesRented;
}
public boolean isCurrentlyRented() {
return isCurrentlyRented;
}
public void setCurrentlyRented(boolean isCurrentlyRented) {
this.isCurrentlyRented = isCurrentlyRented;
}
public DVDdata getNext() {
return next;
}
public void setNext(DVDdata next) {
this.next = next;
}
}
public class DVDmethod {
public static void add(String titile, double price, int genre) {
//add - The user will be prompted for a title of a new DVD and a price (original price).
// The store will add the DVD in the appropriate location in the alphabetically
// sorted (by title) inventory, provided the DVD name does not already exist in the
// list. If it exists, the user will be prompted for an alternate DVD title.
addDVD(titile, price, genre);
System.out.println("successful");
}
public static void addDVD(String title, double price, int genre) { //wrap up
DVDdata referenceToNext = SearchAndInsert();
DVDdata(title, genre, price, price+10, false, 0, false, referenceToNext);
}
public static void SearchAndInsert(DVDdata newDVD) {
DVDdata previous;
while (null != (previous = DVDlist(a).next) {
if (compare(previous.title, newDVD.title ) ) {
System.out.println("Same tiltle exisit, please type in a title");
//re-do this F***ing process.....
}
}
previous.next = newDVD;
}
// public void SearchAndInsert (DVD newDVD) {
// //Do something to find the place, change the upper DVD refer link to this one, and return the next DVD refer link for this one.
// return referenceToNext;
// }
public static void printList() {
if (DVDdata.getNext() == null) {
System.out.println("this.title"); return;
}else {
System.out.println("this.title");
return this.next.printList();
}
}
public static void remove (String title) {
if (DVDdata.getNext() == null ) {} //base case
}
public static void displayInventory() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment