//begin videostore ********************************************************************************************* //package videostore1; import java.io.*; import java.util.*; /** * This class implements a DOS application, building a * list of rentables (videos and video games) owned by the store * and available for checkout. *

* It offers the following menu: *

*

* NOTE: the "rentableDat.txt" file must be in the PARENT * directory of this package: videostore1. The text file * contains sample rentable information to be stored in * a rentable list. *

* * @author Kathlea Quebbeman */ public class VideoStore { /** * Reads input from the keyboard. */ BufferedReader keyboard = new BufferedReader( new InputStreamReader(System.in)); /** * List of videos and video games owned by the video store. */ RentableList rentableList = new RentableList(); /** * Default constructor.

* Sets up a data base of videos and video games owned by the store, * reading the list from the text file, "rentableDat.txt".

* Displays a menu of options from which the store * clerk may choose. */ public VideoStore() { int choice; String title="",type,platform; char ch; int num=0; boolean valid = false; Rentable rentable=new Video(); try { createRentableList("rentableDat.txt"); do { displayMenu(); try { choice = Integer.parseInt(keyboard.readLine()); } catch(NumberFormatException nfe) { choice = 0; } System.out.println(); switch(choice) { case 1: System.out.print("Enter V for video, G for game: "); type = keyboard.readLine(); ch = type.charAt(0); valid = false; switch(ch) { case 'v': case 'V': System.out.print("Enter the title: "); title = keyboard.readLine(); rentable = new Video(title,"","","","","",0); valid = true; break; case 'g': case 'G': System.out.print("Enter the title: "); title = keyboard.readLine(); System.out.print("Enter the game platform: "); platform = keyboard.readLine(); rentable = new Game(title,platform,"",0); valid = true; break; default: System.out.println("Not a valid rentable."); } if(valid) { System.out.println(); if(rentableList.contains(rentable)) System.out.println("The store does " + "stock " + rentable.getTitle()); else System.out.println("The store does not " + "stock " + rentable.getTitle()); } break; case 2: System.out.print("Enter V for video, G for game: "); type = keyboard.readLine(); ch = type.charAt(0); valid = false; switch(ch) { case 'v': case 'V': System.out.print("Enter the title: "); title = keyboard.readLine(); System.out.println(); rentable = new Video(title,"","","","","",0); num = 1; valid = true; break; case 'g': case 'G': System.out.print("Enter the title: "); title = keyboard.readLine(); System.out.print("Enter the game platform: "); platform = keyboard.readLine(); System.out.print("Enter the number of copies to rent: "); num = Integer.parseInt(keyboard.readLine()); rentable = new Game(title,platform,"",0); valid = true; break; default: System.out.println("Not a valid rentable."); } if(valid) { try { rentableList.rentableCheckOut(rentable, num); System.out.println("Enjoy " + rentable.getTitle()); } catch(OutOfBoundsException oobe) { System.out.println(oobe.getMessage()); } catch(NoSuchElementException nosee) { System.out.println(nosee.getMessage()); } } break; case 3: System.out.print("Enter V for video, G for game: "); type = keyboard.readLine(); ch = type.charAt(0); valid = false; switch(ch) { case 'v': case 'V': System.out.print("Enter the title: "); title = keyboard.readLine(); System.out.println(); rentable = new Video(title,"","","","","",0); num = 1; valid = true; break; case 'g': case 'G': System.out.print("Enter the title: "); title = keyboard.readLine(); System.out.print("Enter the game platform: "); platform = keyboard.readLine(); System.out.print("Enter the number of copies returned: "); num = Integer.parseInt(keyboard.readLine()); rentable = new Game(title,platform,"",0); valid = true; break; default: System.out.println("Not a valid rentable."); } if(valid) { try { rentableList.rentableCheckIn(rentable, num); System.out.println("Thank you for returning " + rentable.getTitle()); } catch(OutOfBoundsException oobe) { System.out.println(oobe.getMessage()); } catch(NoSuchElementException nosee) { System.out.println(nosee.getMessage()); } } break; case 4: System.out.print("Enter V for video, G for game: "); type = keyboard.readLine(); ch = type.charAt(0); valid = false; switch(ch) { case 'v': case 'V': System.out.print("Enter the title: "); title = keyboard.readLine(); System.out.println(); rentable = new Video(title,"","","","","",0); valid = true; break; case 'g': case 'G': System.out.print("Enter the title: "); title = keyboard.readLine(); System.out.print("Enter the game platform: "); platform = keyboard.readLine(); rentable = new Game(title,platform,"",0); valid = true; break; default: System.out.println("Not a valid rentable."); } if(valid) { try { if(rentableList.isRentableAvailable(rentable)) System.out.println(title + " is available for checkout"); else System.out.println(title + " is not available for checkout."); } catch(NoSuchElementException nosee) { System.out.println(nosee.getMessage()); } } break; case 5: System.out.println("This store owns the " +"following rentable titles:"); //System.out.println(rentableList.titleCopiesToString());//******************************* break; case 6: System.out.println("This store owns the " +"following rentable videos/games:"); System.out.println(rentableList.toString()); break; case 9: break; default: System.out.println("Invalid selection"); }//end switch }while(choice != 9); }//end try catch(InputMismatchException ime) { System.out.println(ime.toString()); } catch(NumberFormatException nfe) { System.out.println(nfe.toString()); } catch(FileNotFoundException fnfe) { System.out.println(fnfe.toString()); } catch(IOException ioe) { System.out.println(ioe.toString()); } catch(OutOfBoundsException oobe) { System.out.println(oobe.toString()); } } /** * Sets up data base of rentables owned by the store, * reading the rentable records from the text file * who's pathname is specified as a String. * * @param rentableFile String with pathname of text * file containing records of the rentables owned by * the store.

* each record: * @throws IOException if file not found or cannot * be read. */ public void createRentableList(String rentableFile) throws IOException { BufferedReader inFile = new BufferedReader(new FileReader(rentableFile)); String rentType,title,s1,s2,s3,s4,productionCo; int inStock; Rentable newVideo = new Video(); Rentable newGame = new Game(); rentType = inFile.readLine(); while(rentType != null) { title = inFile.readLine(); s1 = inFile.readLine(); s2 = inFile.readLine(); s3 = inFile.readLine(); s4 = inFile.readLine(); productionCo = inFile.readLine(); inStock = Integer.parseInt(inFile.readLine()); try { if(rentType.charAt(0) == 'V') { newVideo = new Video(title,s1,s2,s3,s4,productionCo,inStock); rentableList.add(newVideo); } else if(rentType.charAt(0) == 'G') { newGame = new Game(title,s1,productionCo,inStock); rentableList.add(newGame); } } catch(OutOfBoundsException oobe) { System.err.println(oobe.getMessage()); } rentType = inFile.readLine(); }//end while loop inFile.close(); }//end createVideoList /** * Displays a menu of options from which the store * clerk may choose.

* @menu

*/ public void displayMenu() { String str = "\nSelect one of the following:\n"; str += "\n1: To check if a particular video/game " + "is owned by the store\n"; str += "2: To check out a video/game\n"; str += "3: To check in a video/game\n"; str += "4: To see if a particular video/game " + "is available for checkout\n"; str += "5: To print the titles of all videos/games owned " + "by the store\n"; str += "6: To print a list of all the videos/games owned " + "by the store\n"; str += "9: To exit\n"; str += "\nChoice: "; System.out.print(str); } } // end videostore************************************************************************************************ //begin video**************************************************************************************** //package videostore1; /** * This class stores information about one video:

*

*

* @author Kathlea Quebbeman */ public class Video implements Cloneable, Rentable { /*------------Instance Variables-----------------*/ /** * Stores the title of the video */ private String videoTitle; /** * Stores the first star */ private String movieStar1; /** * Stores the second star */ private String movieStar2; /** * Stores the producer */ private String movieProducer; /** * Stores the director */ private String movieDirector; /** * Stores the production company */ private String movieProductionCo; /** * Stores the # of copies available for rent */ private int copiesInStock; /** * Stores the # of copies owned by the store */ private int copiesOwned; /*------------constructors-----------------------*/ /** * Default constructor.

* Instance variables are initialized to default * values: *