Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.14 KB | None | 0 0
  1. package main;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Iterator;
  5. import java.util.Scanner;
  6.  
  7. import javax.xml.ws.spi.Invoker;
  8.  
  9. import model.Game;
  10. import model.Inventory;
  11. import model.Item;
  12. import model.Movie;
  13.  
  14. public class Store {
  15.    
  16.     public static Scanner in;
  17.     public static Inventory inventory;
  18.     public static int day = 1;
  19.    
  20.     public static void main(String[] args) {
  21.         String command;
  22.         in = new Scanner(System.in);
  23.         inventory = new Inventory();
  24.        
  25.         while (true) {
  26.             showMenu();
  27.             command = in.next();
  28.  
  29.             System.out.println();
  30.            
  31.             switch (command) {
  32.                 case "L":
  33.                     listItemMenu();
  34.                     break;
  35.                 case "AG":
  36.                     addGameMenu();
  37.                     break;
  38.                 case "AM":
  39.                     addMovieMenu();
  40.                     break;
  41.                 case "RG":
  42.                     rentGameMenu();
  43.                     break;
  44.                 case "RM" :
  45.                     rentMovieMenu();
  46.                     break;
  47.                 case "GG" :
  48.                     returnGameMenu();
  49.                     break;
  50.                 case "GM" :
  51.                     returnMovieMenu();
  52.                     break;
  53.                 case "BG" :
  54.                     buyGameMenu();
  55.                     break;
  56.                 case "E":
  57.                     System.out.println("Program terminated");
  58.                     System.exit(0);
  59.                     break;
  60.                 case "T":
  61.                     timePassingMenu();
  62.                     break;
  63.                 default:
  64.                     System.out.println("Invalid command.");
  65.                     break;
  66.             }
  67.            
  68.             System.out.println();
  69.         }
  70.     }
  71.    
  72.     private static void showMenu(){
  73.         System.out.println("########################################");
  74.         System.out.println("Video Store Menu (Day " + day + ")");
  75.         System.out.println("########################################");
  76.         System.out.println("AG)\tAdd game\tAM)\tAdd movie");
  77.         //System.out.println("AM)\tAdd movie");
  78.         System.out.println("RG)\tRent game\tRM)\tRent movie");
  79.         //System.out.println("RM)\tRent movie");
  80.         System.out.println("GG)\tReturn game\tGM)\tReturn movie");
  81.         //System.out.println("GM)\tReturn movie");
  82.         System.out.println("BG)\tBuy game\tL)\tList all items");
  83.         System.out.println("T)\tTime passing\tE)\tExit");
  84.         System.out.println("----------------------------------------");
  85.         System.out.print("Enter input command : ");
  86.     }
  87.    
  88.     private static void listItemMenu() {
  89.         // TODO Auto-generated method stub
  90.         System.out.println("----------------------------------------");
  91.         System.out.println("List all items in inventory");
  92.         System.out.println("----------------------------------------");
  93.         System.out.println("Game (Total " + inventory.getTotalGames() + "):");
  94.         System.out.println("----------------------------------------");
  95.        
  96.         inventory.listGames();
  97.        
  98.         System.out.println("----------------------------------------");
  99.         System.out.println("Movie (Total " + inventory.getTotalMovies() + "):");
  100.         System.out.println("----------------------------------------");
  101.        
  102.         inventory.listMovies();
  103.     }
  104.    
  105.     private static void addGameMenu() {
  106.         // TODO Auto-generated method stub
  107.         System.out.println("----------------------------------------");
  108.         System.out.println("Add game to inventory");
  109.         System.out.println("----------------------------------------");
  110.         int rand = (int)(Math.random() * 9);
  111.         System.out.println("Name  : " + Inventory.gameNames[rand]);
  112.         System.out.println("Rate  : " + Inventory.gameRatings[rand]);
  113.         System.out.println("Price : " + Inventory.gamePrices[rand]);
  114.         inventory.addItem(new Game(Inventory.gameNames[rand],Inventory.gameRatings[rand],Inventory.gamePrices[rand]));
  115.         inventory.sortItems();
  116.  
  117.     }
  118.    
  119.     private static void addMovieMenu() {
  120.         // TODO Auto-generated method stub
  121.         System.out.println("----------------------------------------");
  122.         System.out.println("Add movie to inventory");
  123.         System.out.println("----------------------------------------");
  124.         int rand = (int)(Math.random() * 9);
  125.         System.out.println("Name  : " + Inventory.movieNames[rand]);
  126.         System.out.println("Rate  : " + Inventory.movieRatings[rand]);
  127.         System.out.println("Price : " + Inventory.moviePrices[rand]);
  128.         inventory.addItem(new Movie(Inventory.movieNames[rand],Inventory.movieRatings[rand],Inventory.moviePrices[rand]));
  129.         inventory.sortItems();
  130.     }
  131.    
  132.     private static void rentGameMenu(){
  133.         System.out.println("----------------------------------------");
  134.         System.out.println("Rent game");
  135.         System.out.println("----------------------------------------");
  136.        
  137.         String gameName;
  138.         String renterName;
  139.         int rentOption;
  140.        
  141.         // TODO Fill Code
  142.         System.out.println("Enter game name : ");
  143.         gameName = in.next();
  144.         int index = inventory.searchForRentableGame(gameName);
  145.         Game t = null;
  146.         if(index != -1) {
  147.             t = (Game) Inventory.items.get(index);
  148.             System.out.println("Choose the rental options from 1-4 : ");
  149.             System.out.println("1) $3.00 for 1 week");
  150.             System.out.println("2) $5.40 for 2 weeks");
  151.             System.out.println("3) $7.00 for 3 weeks");
  152.             System.out.println("4) $9.00 for 4 weeks");
  153.             System.out.println("Enter your option : ");
  154.             rentOption = in.nextInt();
  155.             System.out.println("Enter your name : ");
  156.             renterName = in.next();
  157.             System.out.println("You rented the game successfully. The game ID is "+t.getId()+".");
  158.             System.out.println("Please inform the game ID when you return it.");
  159.             System.out.println("Please return the game within Day "+(rentOption*7+1)+"."+ " Late fee is "+t.getLateFeePerDay()+ "/days.");
  160.             t.rent(renterName, rentOption);
  161.         }
  162.         else {
  163.             System.out.println("The game is not available to rent. Back to menu.");
  164.         }
  165.     }
  166.    
  167.     private static void rentMovieMenu(){
  168.         System.out.println("----------------------------------------");
  169.         System.out.println("Rent movie");
  170.         System.out.println("----------------------------------------");
  171.        
  172.         String movieName;
  173.         String renterName;
  174.        
  175.         // TODO Fill Code
  176.         System.out.println("Enter movie name : ");
  177.         movieName = in.next();
  178.         int index = inventory.searchForRentableGame(movieName);
  179.         Movie t = (Movie) Inventory.items.get(index);
  180.         if(index != -1) {
  181.             System.out.println("Enter your name : ");
  182.             renterName = in.next();
  183.             System.out.println("You rented the movie successfully. The movie ID is "+t.getId()+".");
  184.             System.out.println("Please inform the movie ID when you return it.");
  185.             t.rent(renterName, 0);
  186.         }
  187.         else {
  188.             System.out.println("The movie is not available to rent. Back to menu.");
  189.         }
  190.     }
  191.    
  192.     private static void returnGameMenu(){
  193.         System.out.println("----------------------------------------");
  194.         System.out.println("Return Game");
  195.         System.out.println("----------------------------------------");
  196.        
  197.         int gameID;
  198.        
  199.         // TODO Fill Code
  200.         System.out.println("Enter game ID : ");
  201.         gameID = in.nextInt();
  202.         Game t = null;
  203.         for(int i=0;i<Inventory.items.size();++i) {
  204.             if(Inventory.items.get(i) instanceof Game && Inventory.items.get(i).getId()==gameID) {
  205.                 t = (Game) Inventory.items.get(i);
  206.                 break;
  207.             }
  208.         }
  209.         if(t!=null) {
  210.             if(day-t.getGiveBackDate()<=0) {
  211.                 System.out.println("The rental fee is $"+t.giveBack()+".");
  212.             }
  213.             else {
  214.                 System.out.println("The rental fee is $"+t.giveBack()+". (Late "+(day-t.getGiveBackDate())+" days)");
  215.             }
  216.         }
  217.         else {
  218.             System.out.println("the game is not rented. Back to menu.");
  219.         }
  220.     }
  221.    
  222.     private static void returnMovieMenu(){
  223.         System.out.println("----------------------------------------");
  224.         System.out.println("Return movie");
  225.         System.out.println("----------------------------------------");
  226.        
  227.         int movieID;
  228.        
  229.         // TODO Fill Code
  230.         System.out.println("Enter movie ID : ");
  231.         movieID = in.nextInt();
  232.         Movie t = null;
  233.         for(int i=0;i<Inventory.items.size();++i) {
  234.             if(Inventory.items.get(i) instanceof Game && Inventory.items.get(i).getId()==movieID) {
  235.                 t = (Movie) Inventory.items.get(i);
  236.                 break;
  237.             }
  238.         }
  239.         if(t!=null) {
  240.             System.out.println("The rental fee is $"+t.giveBack()+".");
  241.  
  242.         }
  243.         else {
  244.             System.out.println("the movie is not rented. Back to menu.");
  245.         }
  246.     }
  247.    
  248.     private static void buyGameMenu(){
  249.         System.out.println("----------------------------------------");
  250.         System.out.println("Buy Game");
  251.         System.out.println("----------------------------------------");
  252.        
  253.         String gameName;
  254.         String buyerName;
  255.        
  256.         // TODO Fill Code
  257.         System.out.println("Enter game name : ");
  258.         gameName = in.next();
  259.         int index = inventory.searchForRentableGame(gameName);
  260.         Game t = (Game) Inventory.items.get(index);
  261.         if(index != -1) {
  262.             System.out.println("Enter your name : ");
  263.             buyerName = in.next();
  264.             System.out.println("The price is $"+t.getPrice()+".");
  265.             System.out.println("Thank you for buying");
  266.         }
  267.         else {
  268.             System.out.println("The game is not available to buy. Back to menu.");
  269.         }
  270.     }
  271.    
  272.     private static void timePassingMenu() {
  273.         // TODO Auto-generated method stub
  274.             System.out.println("----------------------------------------");
  275.             System.out.println("Simulate Time Passing");
  276.             System.out.println("----------------------------------------");
  277.            
  278.             System.out.print("Enter the number of days passing : ");
  279.            
  280.             try{
  281.                 int days = in.nextInt();
  282.                
  283.                 if (days <= 0)
  284.                 {
  285.                     System.out.println("The number of days should be more than 0.");
  286.                 }
  287.                 else
  288.                 {
  289.                     Store.day += days;
  290.                     System.out.println("Now is Day " + Store.day + ".");
  291.                 }
  292.             }
  293.             catch(Exception e)
  294.             {
  295.                 System.out.println("The input should be an integer.");
  296.             }
  297.            
  298.             in.next(); // For '\n' from pressing enter;
  299.     }
  300.  
  301. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement