├── .classpath ├── .project ├── .settings └── org.eclipse.jdt.core.prefs ├── README.md ├── bin └── partc │ ├── Admin.class │ ├── Book.class │ ├── Item.class │ ├── Member.class │ ├── NonMember.class │ ├── Software.class │ ├── TechStore.class │ └── User.class └── src └── partc ├── Admin.java ├── Book.java ├── Item.java ├── Member.java ├── NonMember.java ├── Software.java ├── TechStore.java └── User.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Assignment2_initial 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.6 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.source=1.6 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Java-assignments 2 | You are required to implement a basic Java program using Java (SE 5.0 or later). This assignment is designed to help you: 1. Practise your knowledge of class design in Java; 2. Practise the implementation of different kinds of OO constructs in Java; 3. Practise the use of polymorphism; 4. Practise error handling in Java; 5. Develop a reasonable sized application in Java. General Implementation Details  All input data should be read from the standard input and all output data should be printed to the standard output. Do not use files at all.  If the input is formatted incorrectly, that input should be ignored and an appropriate error message should be displayed.  Marks will be allocated to your class design. You are required to modularise classes properly---i.e., to use multiple methods as appropriate. No method should be longer than 50 lines.  Marks will be allocated to proper documentation and coding layout and style. Your coding style should be consistent with standard coding conventions  . Overall Specification You will build out the system from Assignment 1 to manage multiple users purchasing different types of items, including discounts for multiple items. Items to be Purchased The TechStore has been extended to sell Software as well as Books. Like Books, Software can be sold as a (physical) CD or as an online item (i.e., download). As in Assignment 1, a Book can also be sold as a physical copy or as an ebook. You need to keep track of the physical copies of Books and CDs, and whether or not a title is available as an online item. Books have a title and an author; Software items have a title and a publisher. Each item is individually priced---i.e., the price depends on the title and whether it is a physical copy or ebook/software-download. Purchasing Items A User can buy any number of items (books, software, or a mix), adding one item at a time to their Shopping Cart. However, a User can only purchase up to a total of $100, unless they are a Member—if a non-Member User tries to add an item to their Shopping Cart that takes the total over their maximum then this is blocked. A Member has no limit. Items can be added and removed from a Shopping Cart until Checkout. When an Item is added to the Shopping Cart, the system checks that there are enough copies of it available; if an Item is added or removed from the Shopping Cart, the number of copies available must be updated. Checkout clears the Shopping Cart. Users Users can add Items to their Cart, up to their allowed limit (i.e., their Shopping Cart cannot store a total greater than the limit). A User has an id (must be unique) and password (you do NOT need to make these encrypted or secure), as well as a name and email address. A Member is a special kind of user: a Member has no limit on value they can store in their Cart. Once a User has spent a total of 10% more than their limit in total (this obviously must be over multiple Checkouts), then they are offered to become a Member—this offer is made straight after they Checkout with the items that takes them to 10% over their limit. An Administrator is a User that can perform special functions:  add to the number of copies of a (physical) Book or Software CD;  change the price of an item;  print sales statistics: i.e., number of sales (physical and electronic) of each Item;  add a new user—the system must checked that the new id is unique. Other Users do not have these options on their menu. A user must keep track of their previous purchases, grouped by Transaction—a Transaction is the set of items purchased at Checkout time. Users can log in and out—they do not need to Checkout before logging out. However, only one user can be logged in at a time—the system must allow something like “change user”. If a User logs back in, their Shopping Cart holds the same contents as before they logged out. Recommended Items and Discounts Each item can store a list of “if you liked this” recommendations. If a User adds an Item to their Shopping Cart, then the system suggests other titles they may like. Only similar types of things are recommended—i.e., when a Book is added, other Books (not Software) are suggested. At the time when a list of Recommended titles is given, the user has the option to add one of the recommended titles to their Shopping Cart. If a user adds the title, then they receive a discount of 15% off that second title (the first one is still full price); the User can add multiple recommended titles for 15% off each of them. If a Member adds the recommended title, then they get 25% discount off all the recommendations added. Note: when a recommended title is added, its recommendations are also shown, and are discounted if purchased at that time. You are NOT required to handle the special case of updating discounts when a User removes recommendations from their Cart. However, there is a Bonus Mark for this. Sample menus The menu for a standard User (i.e., a Shopper) should include the following options: 1. Add item to shopping cart 2. View shopping cart 3. Remove item from shopping cart 4. Checkout 5. List all items 6. Print previous purchases 7. Logout (change user) 0. Quit The menu for an Administrator should include the following options: 1. List all items (this option can include purchase statistics for each title) 2. Add copies to item 3. Change price of item 4. Add new user 5. Logout (change user) 0. Quit * SAMPLE RUNS and TEST DATA will be posted to Blackboard * Program Development When implementing large programs, especially using object-oriented style, it is highly recommended that you build your program incrementally. This assignment proposes a specific incremental implementation process: this is designed to both help you think about building large programs, and to help ensure good progress! You are not strictly required to follow the structure below, but it will help you manage complexity. Part A (2 marks): Extend Assignment 1 Start by extending your Assignment 1 solution (a sample solution will be made available): 1. Rename your main class to TechStore if necessary; 2. Extend your Book class (if necessary) to contain all data and operations it needs for Assignment 2, and appropriate classes for other types of Items to be sold; 3. Define Exceptions to handle problems/errors; in particular, you must handle invalid menu options or inputs. Part B (1 marks): Class Design Define all the classes and any interfaces needed for the described system. In particular, you should try to encapsulate all the appropriate data and operations that a class needs. This may mean some classes refer to each other (e.g., the way Account refers to Customer). At this point, you may just want to think about the data and operations and just write the definitions, not all the code. Part C (3 marks): Main Program Your main program should be in the TechStore class. (Of course, any class can contain a main(); this is useful for testing that class.) The main program will contain a menu that offers all the required options (these can be different for different Users!). The system will allow a User to login by typing their id and password and will check that these match: if it does not then the menu prints an error; if they do match, then the system prints a welcome message with the user’s name and shows them the appropriate menu. The system must keep a list of all its Users: this list must be efficient to look-up by User id.  Week 7 Demo (2 marks): You will be required to demonstrate your main program and design (with only bare functionality) by Week 7 at the latest. You must also submit to the associated WebLearn project by the Week 7 lecture. Part D (4 marks): Implement Core Functionality Implement the core functionality of the TechStore system described above, except for the recommendations, members, and discounts. You should be able to implement the rest of the TechStore functionality described above, and run and test your system. Part E (4 marks): Implement Recommendations , Members, Discounts Implement the functionality of providing recommendations, users becoming and being members, and discounts. Other (4 marks) As always, marks will be awarded for coding style, documentation/comments, code layout and clarity, meaningful error and other messages, proper error handling, choice of data structures and other design decisions. You are encouraged to discuss such issues with your tutors and lab assistants, or with the coding mentors. Bonus (2 marks) Note: There will be no hints or help offered on Bonus tasks.  1 bonus mark for early demonstration of Parts A,B,C in Week 6  1 bonus mark for correctly handling removal of recommended books from Cart—e.g., if a Member removes the first item then the 15/25% should be added back to the price of the recommended title, unless there are multiple recommendations linked to that title. Submission Instructions Full assignment submission will be via Weblearn, by 9AM, Tues April 28, 2015. You can submit your assignment as many times as you want before the due date. Each submission will overwrite any previous submissions. 1. You need to submit a class diagram (in pdf, gif or jpeg format). 2. You are required to submit your .java files weekly via Weblearn. Your progress will be taken into consideration if you need an extension. 3. There will be a separate WebLearn submission for Part A,B,C—you must submit to this before the Week 7 lecture to qualify for the 2 marks for Week 7 demo. 4. You must include a README file. This should describe how to run your program, what extra functionality you implemented, any standard functionality you know does not work, and any problems or assumptions. If the tutors have any problem running your program and the README does not help then you will lose marks. 5. For the code submission, you must include only the source files in your submission (do not submit any *.class files!). As always, your code must run on CSIT machines. 6. You must submit a single ZIP file—use zip/WinZIP to zip your files before submitting---do NOT submit rar or zipx files!! 7. If you use packages, it is your responsibility that these unpack properly into the correct folders and that your program compiles correctly. 3 | You are required to implement a basic Java program using Java (SE 5.0 or later). This assignment is designed to help you: 1. Practise your knowledge of class design in Java; 2. Practise the implementation of different kinds of OO constructs in Java; 3. Practise the use of polymorphism; 4. Practise error handling in Java 4 | -------------------------------------------------------------------------------- /bin/partc/Admin.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mitulmanish/Java-assignments/305a2c0b8b820b15d3cdf41e6038ba53167daf72/bin/partc/Admin.class -------------------------------------------------------------------------------- /bin/partc/Book.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mitulmanish/Java-assignments/305a2c0b8b820b15d3cdf41e6038ba53167daf72/bin/partc/Book.class -------------------------------------------------------------------------------- /bin/partc/Item.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mitulmanish/Java-assignments/305a2c0b8b820b15d3cdf41e6038ba53167daf72/bin/partc/Item.class -------------------------------------------------------------------------------- /bin/partc/Member.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mitulmanish/Java-assignments/305a2c0b8b820b15d3cdf41e6038ba53167daf72/bin/partc/Member.class -------------------------------------------------------------------------------- /bin/partc/NonMember.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mitulmanish/Java-assignments/305a2c0b8b820b15d3cdf41e6038ba53167daf72/bin/partc/NonMember.class -------------------------------------------------------------------------------- /bin/partc/Software.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mitulmanish/Java-assignments/305a2c0b8b820b15d3cdf41e6038ba53167daf72/bin/partc/Software.class -------------------------------------------------------------------------------- /bin/partc/TechStore.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mitulmanish/Java-assignments/305a2c0b8b820b15d3cdf41e6038ba53167daf72/bin/partc/TechStore.class -------------------------------------------------------------------------------- /bin/partc/User.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mitulmanish/Java-assignments/305a2c0b8b820b15d3cdf41e6038ba53167daf72/bin/partc/User.class -------------------------------------------------------------------------------- /src/partc/Admin.java: -------------------------------------------------------------------------------- 1 | //package partc; 2 | 3 | public class Admin extends User { 4 | private String id; 5 | private String password; 6 | private String name; 7 | private String email; 8 | Admin(String id,String password,String name,String email){ 9 | super(id,password,name,email); 10 | } 11 | public void show_member(){ 12 | System.out.println("Name "+getName()+" Email "+getEmail()); 13 | } 14 | 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/partc/Book.java: -------------------------------------------------------------------------------- 1 | //package partc; 2 | 3 | public class Book extends Item { 4 | private String title; 5 | private String author; 6 | private boolean ebook; 7 | private double b_cost; 8 | private double e_cost; 9 | private boolean ebook_issue=false; 10 | private boolean physical_book_issue=false; 11 | private int number_of_copies; 12 | private int book_sold=0; 13 | 14 | private int ebook_sold=0; 15 | 16 | boolean m_rec_book=false; 17 | boolean m_rec_ebook=false; 18 | boolean nm_rec_book=false; 19 | boolean nm_rec_ebook=false; 20 | 21 | 22 | public Book( int item_id,String add_date,String title,String author,boolean ebook,double b_cost,double e_cost,int number_of_copies) 23 | { super(item_id,add_date); 24 | this.title=title; 25 | this.author=author; 26 | this.ebook=ebook; 27 | this.b_cost=b_cost; 28 | this.e_cost=e_cost; 29 | this.number_of_copies=number_of_copies; 30 | } 31 | 32 | 33 | 34 | 35 | public void show_book(){ 36 | System.out.print(" "+title +" by "+ author+" | ebook available: " + ebook_available()+ 37 | " | number of copies available: "+get_number_of_copies()); 38 | } 39 | 40 | public void cart_for_ebook(){ 41 | 42 | if(get_m_rec_ebook()){ 43 | System.out.print(" "+title +" by "+ author+" in physical book format" + " $ "+m_dis_ebook()); 44 | } 45 | else if(get_nm_rec_ebook()){ 46 | System.out.print(" "+title +" by "+ author+" in physical book format" + " $ "+nm_dis_ebook()); 47 | } 48 | else 49 | System.out.print(" "+title +" by "+ author+" in ebook book format" + " $ "+get_ebook_cost()); 50 | } 51 | 52 | public void cart_for_book(){ 53 | 54 | if(get_m_rec_book()){ 55 | System.out.print(" "+title +" by "+ author+" in physical book format" + " $ "+m_dis_book()); 56 | } 57 | else if(get_nm_rec_book()){ 58 | System.out.print(" "+title +" by "+ author+" in physical book format" + " $ "+nm_dis_book()); 59 | } 60 | else 61 | System.out.print(" "+title +" by "+ author+" in physical book format" + " $ "+get_book_cost()); 62 | } 63 | 64 | public void ebook_sales(){ 65 | System.out.print(" "+title +" by "+ author+" in ebook book format" + " $ "+get_ebook_cost()+" "+getEbook_sold()); 66 | } 67 | 68 | public void book_sales(){ 69 | System.out.print(" "+title +" by "+ author+" in physical book format" + " $ "+get_book_cost()+" "+getBook_sold()); 70 | } 71 | 72 | public void show_my_cart(){ 73 | System.out.print(" "+title +" by "+ author ); 74 | } 75 | public void show_details(){ 76 | System.out.print(title +" "+ author); 77 | } 78 | 79 | public String ebook_available() 80 | { 81 | if(ebook) 82 | return "Yes"; 83 | else{ 84 | return "No"; 85 | } 86 | } 87 | 88 | public void set_ebook_issue(boolean ebook_issue){ 89 | this.ebook_issue=ebook_issue; 90 | setEbook_sold(); 91 | } 92 | 93 | public void set_physical_book_issue(boolean physical_book_issue){ 94 | this.physical_book_issue=physical_book_issue; 95 | } 96 | public boolean get_ebook_issue(){ 97 | return this.ebook_issue; 98 | } 99 | 100 | public boolean get_physical_book_issue(){ 101 | return this.physical_book_issue; 102 | } 103 | public double get_ebook_cost(){ 104 | return e_cost; 105 | } 106 | 107 | public double get_book_cost(){ 108 | return b_cost; 109 | } 110 | 111 | public String get_title(){ 112 | return title.toLowerCase(); 113 | } 114 | 115 | public String get_author(){ 116 | return author.toLowerCase(); 117 | } 118 | 119 | public int get_number_of_copies() 120 | { 121 | return number_of_copies; 122 | } 123 | 124 | public void reduce_copies() 125 | { 126 | this.number_of_copies--; 127 | setBook_sold(); 128 | } 129 | public boolean check_ebook_available(){ 130 | return ebook; 131 | } 132 | 133 | public void add_copies(){ 134 | number_of_copies++; 135 | 136 | } 137 | public int getEbook_sold() { 138 | return ebook_sold; 139 | } 140 | public void setEbook_sold() { 141 | ebook_sold++; 142 | } 143 | public int getBook_sold() { 144 | return book_sold; 145 | } 146 | public void setBook_sold() { 147 | book_sold++; 148 | } 149 | 150 | public double m_dis_book(){ 151 | return (b_cost-((0.25)*(b_cost))); 152 | 153 | } 154 | public double m_dis_ebook(){ 155 | return (e_cost-((0.25)*(e_cost))); 156 | 157 | } 158 | 159 | public double nm_dis_book(){ 160 | return (b_cost-((0.15)*(b_cost))); 161 | 162 | } 163 | public double nm_dis_ebook(){ 164 | return (e_cost-((0.15)*(e_cost))); 165 | 166 | } 167 | 168 | public void set_m_rec_book_issue(boolean b){ 169 | m_rec_book=b; 170 | } 171 | public void set_m_rec_ebook_issue(boolean b){ 172 | m_rec_ebook=b; 173 | } 174 | public void set_nm_rec_book_issue(boolean b){ 175 | nm_rec_book=b; 176 | } 177 | public void set_nm_rec_ebook_issue(boolean b){ 178 | m_rec_ebook=b; 179 | } 180 | 181 | public boolean get_m_rec_book(){ 182 | return m_rec_book; 183 | } 184 | public boolean get_m_rec_ebook(){ 185 | return m_rec_ebook; 186 | } 187 | public boolean get_nm_rec_book(){ 188 | return nm_rec_book; 189 | } 190 | public boolean get_nm_rec_ebook(){ 191 | return nm_rec_ebook; 192 | } 193 | 194 | 195 | 196 | 197 | 198 | } 199 | 200 | -------------------------------------------------------------------------------- /src/partc/Item.java: -------------------------------------------------------------------------------- 1 | //package partc; 2 | 3 | abstract public class Item { 4 | private int item_id; 5 | private String add_date; 6 | 7 | Item(int item_id,String add_date){ 8 | this.setItem_id(item_id); 9 | this.setAdd_date(add_date); 10 | 11 | } 12 | 13 | public int getItem_id() { 14 | return item_id; 15 | } 16 | 17 | public void setItem_id(int item_id) { 18 | this.item_id = item_id; 19 | } 20 | 21 | public String getAdd_date() { 22 | return add_date; 23 | } 24 | 25 | public void setAdd_date(String add_date) { 26 | this.add_date = add_date; 27 | } 28 | 29 | 30 | 31 | } 32 | ///read about the -------------------------------------------------------------------------------- /src/partc/Member.java: -------------------------------------------------------------------------------- 1 | //package partc; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Iterator; 5 | import java.util.Scanner; 6 | 7 | public class Member extends User { 8 | private int login_count=0; 9 | 10 | private ArrayList mycart=new ArrayList(); 11 | Member(String id,String password,String name,String email){ 12 | super(id,password,name,email); 13 | } 14 | 15 | 16 | public void addItems(Item i){ 17 | mycart.add(i); 18 | } 19 | public void show_my_thing(){ 20 | if(mycart.size()==0){ 21 | System.out.println("Cart Empty"); 22 | return; 23 | } 24 | Iterator itr = mycart.iterator(); 25 | int cart_index=1; 26 | while(itr.hasNext()){ 27 | Item element = (Item) itr.next(); 28 | if(element instanceof Book){ 29 | if(((Book) element).get_ebook_issue()){ 30 | System.out.print("\n"+cart_index+" "); 31 | ((Book) element).cart_for_ebook(); 32 | cart_index++; 33 | } 34 | if(((Book) element).get_physical_book_issue()){ 35 | System.out.print("\n"+cart_index+" "); 36 | ((Book) element).cart_for_book(); 37 | cart_index++; 38 | } 39 | } 40 | if(element instanceof Software){ 41 | if(((Software) element).get_download_issue()){ 42 | System.out.print("\n"+cart_index+" "); 43 | ((Software) element).cart_for_download(); 44 | cart_index++; 45 | } 46 | else if(((Software) element).isCd_issue()){ 47 | System.out.print("\n"+cart_index+" "); 48 | ((Software) element).cart_for_cd(); 49 | cart_index++; 50 | } 51 | 52 | 53 | } 54 | } 55 | } 56 | public void remove_items(){ 57 | show_my_thing(); 58 | if(mycart.size()==0){ 59 | //System.out.println("Cart Empty"); 60 | return; 61 | } 62 | System.out.println("Which item you wish to remove?\n"); 63 | Scanner in= new Scanner(System.in); 64 | int remove_index=in.nextInt(); 65 | remove_index--; 66 | mycart.remove(remove_index); 67 | 68 | } 69 | 70 | public void show_member(){ 71 | System.out.println("Name "+getName()+" Email "+getEmail()); 72 | } 73 | 74 | 75 | public int getLogin_count() { 76 | return login_count; 77 | } 78 | 79 | 80 | public void setLogin_count() { 81 | login_count=login_count+1;; 82 | } 83 | 84 | 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/partc/NonMember.java: -------------------------------------------------------------------------------- 1 | //package partc; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Iterator; 5 | import java.util.Scanner; 6 | 7 | public class NonMember extends User { 8 | private int log_count=0; 9 | private ArrayList mycart=new ArrayList(); 10 | NonMember(String id,String password,String name,String email){ 11 | super(id,password,name,email); 12 | } 13 | public void addItems(Item i) { 14 | 15 | mycart.add(i); 16 | } 17 | public void show_my_thing(){ 18 | if(mycart.size()==0){ 19 | System.out.println("Cart Empty"); 20 | return; 21 | } 22 | Iterator itr = mycart.iterator(); 23 | int cart_index=1; 24 | while(itr.hasNext()){ 25 | Item element = (Item) itr.next(); 26 | if(element instanceof Book){ 27 | if(((Book) element).get_ebook_issue()){ 28 | System.out.print("\n"+cart_index+" "); 29 | ((Book) element).cart_for_ebook(); 30 | cart_index++; 31 | } 32 | if(((Book) element).get_physical_book_issue()){ 33 | System.out.print("\n"+cart_index+" "); 34 | ((Book) element).cart_for_book(); 35 | cart_index++; 36 | } 37 | } 38 | if(element instanceof Software){ 39 | if(((Software) element).get_download_issue()){ 40 | System.out.print("\n"+cart_index+" "); 41 | ((Software) element).cart_for_download(); 42 | cart_index++; 43 | } 44 | else if(((Software) element).isCd_issue()){ 45 | System.out.print("\n"+cart_index+" "); 46 | ((Software) element).cart_for_cd(); 47 | cart_index++; 48 | } 49 | 50 | 51 | } 52 | } 53 | } 54 | 55 | public void remove_items(){ 56 | show_my_thing(); 57 | System.out.println("Which item you wish to remove?\n"); 58 | Scanner in= new Scanner(System.in); 59 | int remove_index=in.nextInt(); 60 | remove_index--; 61 | mycart.remove(remove_index); 62 | 63 | } 64 | public void show_member(){ 65 | System.out.println("Name "+getName()+" Email "+getEmail()); 66 | } 67 | public int get_count() { 68 | return log_count; 69 | } 70 | public int set_count() { 71 | return log_count++; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/partc/Software.java: -------------------------------------------------------------------------------- 1 | //package partc; 2 | 3 | public class Software extends Item { 4 | 5 | private boolean download; 6 | private double cd_price; 7 | private double download_price; 8 | private boolean cd_issue=false; 9 | private boolean download_issue=false; 10 | private int number_of_cd; 11 | private String title; 12 | private String pub; 13 | boolean m_rec_cd=false; 14 | boolean m_rec_down=false; 15 | boolean nm_rec_cd=false; 16 | boolean nm_rec_down=false; 17 | 18 | 19 | private int cd_sold=0; 20 | 21 | private int download_sold=0; 22 | 23 | 24 | 25 | Software(int item_id,String add_date,String title,String pub,boolean download,double cd_price,double download_price,int number_of_cd){ 26 | super(item_id,add_date); 27 | this.title=title; 28 | this.pub=pub; 29 | this.download=download; 30 | this.cd_price=cd_price; 31 | this.download_price=download_price; 32 | this.number_of_cd=number_of_cd; 33 | 34 | } 35 | public String get_title() { 36 | 37 | return title; 38 | } 39 | public void show_software(){ 40 | System.out.print(" "+get_title() +" by "+ get_publisher()+" | download available: " + download_available()+ 41 | " | number of cds available: "+get_number_of_cd()); 42 | } 43 | 44 | 45 | 46 | public void cart_for_download(){ 47 | if(get_m_rec_down()){ 48 | System.out.print(" "+get_title() +" by "+ get_publisher()+" in cd format" + " $ "+m_dis_down()); 49 | } 50 | else if(get_nm_rec_down()){ 51 | System.out.print(" "+get_title() +" by "+ get_publisher()+" in cd format" + " $ "+nm_dis_down()); 52 | } 53 | else 54 | System.out.print(" "+get_title() +" by "+ get_publisher()+" in download format" + " $ "+get_download_cost()); 55 | } 56 | 57 | public void cart_for_cd(){ 58 | if(get_m_rec_cd()){ 59 | System.out.print(" "+get_title() +" by "+ get_publisher()+" in cd format" + " $ "+m_dis_cd()); 60 | } 61 | else if(get_nm_rec_cd()){ 62 | System.out.print(" "+get_title() +" by "+ get_publisher()+" in cd format" + " $ "+nm_dis_cd()); 63 | } 64 | else 65 | System.out.print(" "+get_title() +" by "+ get_publisher()+" in cd format" + " $ "+get_cd_cost()); 66 | } 67 | public void download_sales(){ 68 | System.out.print(" "+get_title() +" by "+ get_publisher()+" in download format" + " $ "+get_download_cost()+" "+getDownload_sold()); 69 | } 70 | 71 | public void cd_sales(){ 72 | System.out.print(" "+get_title() +" by "+ get_publisher()+" in cd format" + " $ "+get_cd_cost()+" "+getCd_sold()); 73 | } 74 | 75 | public void show_my_cart(){ 76 | System.out.print(" "+get_title() +" by "+ get_publisher() ); 77 | } 78 | public void show_details(){ 79 | System.out.print(get_title() +" "+ get_publisher()); 80 | } 81 | 82 | public String download_available() 83 | { 84 | if(download) 85 | return "Yes"; 86 | else{ 87 | return "No"; 88 | } 89 | } 90 | public void add_copies(){ 91 | number_of_cd++; 92 | } 93 | 94 | public String get_publisher(){ 95 | return pub; 96 | } 97 | 98 | public int get_number_of_cd() 99 | { 100 | return number_of_cd; 101 | } 102 | 103 | public void reduce_copies() 104 | { 105 | this.number_of_cd--; 106 | setCd_sold(); 107 | } 108 | public boolean check_download_available(){ 109 | return download; 110 | } 111 | public double get_download_cost(){ 112 | return download_price ; 113 | 114 | } 115 | 116 | public double get_dis_memeber_download_cost(){ 117 | return download_price-(1) ; 118 | 119 | } 120 | 121 | public double get_cd_cost(){ 122 | return cd_price ; 123 | 124 | } 125 | public void set_download_issue(boolean b) { 126 | // TODO Auto-generated method stub 127 | download_issue=b; 128 | setDownload_sold(); 129 | } 130 | public boolean get_download_issue() { 131 | // TODO Auto-generated method stub 132 | return download_issue; 133 | } 134 | public boolean isCd_issue() { 135 | return cd_issue; 136 | } 137 | public void setCd_issue(boolean cd_issue) { 138 | this.cd_issue = cd_issue; 139 | } 140 | 141 | public int getCd_sold() { 142 | return cd_sold; 143 | } 144 | public void setCd_sold() { 145 | cd_sold++; 146 | } 147 | 148 | public int getDownload_sold() { 149 | return download_sold; 150 | } 151 | public void setDownload_sold() { 152 | download_sold++; 153 | } 154 | 155 | public double m_dis_cd(){ 156 | return (cd_price-((0.25)*(cd_price))); 157 | 158 | } 159 | public double m_dis_down(){ 160 | return (download_price-((0.25)*(download_price))); 161 | 162 | } 163 | 164 | public double nm_dis_cd(){ 165 | return (cd_price-((0.15)*(cd_price))); 166 | 167 | } 168 | public double nm_dis_down(){ 169 | return (download_price-((0.15)*(download_price))); 170 | 171 | } 172 | public void set_m_rec_cd_issue(boolean b){ 173 | m_rec_cd=b; 174 | } 175 | public void set_m_rec_down_issue(boolean b){ 176 | m_rec_down=b; 177 | } 178 | public void set_nm_rec_cd_issue(boolean b){ 179 | nm_rec_cd=b; 180 | } 181 | public void set_nm_rec_down_issue(boolean b){ 182 | m_rec_down=b; 183 | } 184 | 185 | public boolean get_m_rec_cd(){ 186 | return m_rec_cd; 187 | } 188 | public boolean get_m_rec_down(){ 189 | return m_rec_down; 190 | } 191 | public boolean get_nm_rec_cd(){ 192 | return nm_rec_cd; 193 | } 194 | public boolean get_nm_rec_down(){ 195 | return nm_rec_down; 196 | } 197 | 198 | 199 | } 200 | 201 | -------------------------------------------------------------------------------- /src/partc/TechStore.java: -------------------------------------------------------------------------------- 1 | //package partc; 2 | 3 | /** 4 | 5 | * Working of the program 6 | 7 | 1. The TechStore class implements an application for purchasing books and Software via a Computer System.The books can be in the form of physical 8 | 9 | book and e-book format and the software can be purchased in the form of CD and the download format. 10 | 11 | 2.A book/software can be purchased by simply entering the initials of the book.The input string traverses through all the different 12 | 13 | objects of the item array . 14 | 15 | 3.The program shows all the matching items in the item array and prompts the user to enter the choice. 16 | 17 | 4.The user is given the option of selecting the item out of all the matching items. 18 | 19 | 5.The user gets the option of either selecting the item or cancel and go back to the main menu. 20 | 21 | 6.If the Item is only available in the physical/CD format,the user is prompted to buy the physical/CD. 22 | 23 | 7.If the item is available in both the format,the user is given the option of either buying a physical copy or CD or to buy a ebook/download. 24 | 25 | 8.According to the item selected users are presented with the recommendations.Users have option of either buying a recommended item or canceling it. 26 | 27 | 9.If a user buys a recommended title,the user is presented with more recommendations related to the last purchase. 28 | 29 | * 30 | 31 | * This program is the original work of Mitul Manish(s3499818). 32 | 33 | * Email- mitul.manish@gmail.com 0451754624 34 | 35 | * 36 | 37 | */ 38 | 39 | 40 | 41 | import java.util.*; 42 | 43 | 44 | 45 | public class TechStore { 46 | 47 | static ArrayListsales= new ArrayList(); 48 | 49 | static ArrayList list= new ArrayList(); 50 | 51 | //static ArrayList rec_holder= new ArrayList(); 52 | 53 | static HashMap> recommend=new HashMap>(); 54 | 55 | static ArrayList user_list= new ArrayList(); 56 | 57 | static ArrayList rec_list1= new ArrayList(); 58 | 59 | static ArrayList rec_list2= new ArrayList(); 60 | 61 | static ArrayList rec_list3= new ArrayList(); 62 | 63 | static ArrayList rec_list4= new ArrayList(); 64 | 65 | static ArrayList rec_list5= new ArrayList(); 66 | 67 | static ArrayList rec_list6= new ArrayList(); 68 | 69 | 70 | 71 | private static double user_balance=0; 72 | 73 | static int count=-1; 74 | 75 | static Scanner input = new Scanner(System.in); 76 | 77 | 78 | 79 | public static void main(String[] args){ 80 | 81 | boolean change_user=false; 82 | 83 | //System.out.println("beginning of main"); 84 | 85 | initial(); 86 | 87 | int my_user=authenticate(count); 88 | 89 | 90 | 91 | System.out.println(my_user); 92 | 93 | //testlbl: 94 | 95 | main_activity(my_user); 96 | 97 | } 98 | 99 | 100 | 101 | public static Item find_my_book(String item_name,int user_index){ 102 | 103 | //System.out.println("inside of find my book block"); 104 | 105 | int ebook_option = 0; 106 | 107 | ArrayList item_holder= new ArrayList(); 108 | 109 | //System.out.println("reached find my book----------"); 110 | 111 | Scanner buy=new Scanner(System.in); 112 | 113 | int counter=0; 114 | 115 | int i=1; 116 | 117 | boolean found=false; 118 | 119 | 120 | 121 | Iterator itr = list.iterator(); 122 | 123 | while(itr.hasNext()) { 124 | 125 | // System.out.println("inside iterator----------"); 126 | 127 | Item element = (Item) itr.next(); 128 | 129 | 130 | 131 | if(element instanceof Book){ 132 | 133 | if(((Book) element).get_title().startsWith(item_name.toLowerCase())){ 134 | 135 | found=true; 136 | 137 | item_holder.add((Book)element); 138 | 139 | System.out.print((i)+ ". "); 140 | 141 | 142 | 143 | ((Book) item_holder.get(counter)).show_book(); 144 | 145 | 146 | 147 | System.out.println(); 148 | 149 | counter++; 150 | 151 | i++; 152 | 153 | 154 | 155 | 156 | 157 | } 158 | 159 | } 160 | 161 | else if(element instanceof Software){ 162 | 163 | if(((Software) element).get_title().toLowerCase().startsWith(item_name.toLowerCase())){ 164 | 165 | found=true; 166 | 167 | item_holder.add((Software)element); 168 | 169 | 170 | 171 | System.out.print((i)+ ". "); 172 | 173 | 174 | 175 | ((Software) item_holder.get(counter)).show_software(); 176 | 177 | 178 | 179 | 180 | 181 | System.out.println(); 182 | 183 | counter++; 184 | 185 | i++; 186 | 187 | 188 | 189 | 190 | 191 | } 192 | 193 | } 194 | 195 | } 196 | 197 | 198 | 199 | if (found){ 200 | 201 | 202 | 203 | System.out.println("Press 99 to return to main menu"); 204 | 205 | System.out.println("Which number item do you wish to purchase:"); 206 | 207 | int item_number = buy.nextInt(); 208 | 209 | if (item_number==99){ 210 | 211 | return null; 212 | 213 | } 214 | 215 | item_number--; 216 | 217 | System.out.println("item number::"+item_number); 218 | 219 | if (item_holder.get(item_number) instanceof Book){ 220 | 221 | System.out.println("item number::"+item_number); 222 | 223 | if(((Book) item_holder.get(item_number)).check_ebook_available()){ 224 | 225 | Scanner read = new Scanner(System.in); 226 | 227 | book_option(); 228 | boolean loop=true; 229 | 230 | 231 | do{ 232 | 233 | try{ 234 | System.out.println("\n Enter the option"); 235 | ebook_option=read.nextInt(); 236 | switch (ebook_option){ 237 | 238 | case 5: 239 | loop=false; 240 | break; 241 | 242 | case 1: 243 | loop=false; 244 | System.out.println("Do you want to buy the ebook version of the book ?"); 245 | 246 | System.out.println("Press 1 to buy the book"); 247 | 248 | System.out.println("Press 0 to cancel"); 249 | 250 | int option = buy.nextInt(); 251 | 252 | 253 | 254 | switch(option){ 255 | 256 | case 1: 257 | 258 | 259 | 260 | System.out.println("found and added to cart"); 261 | 262 | System.out.println("item number::"+item_number); 263 | 264 | ((Book) item_holder.get(item_number)).set_ebook_issue(true); 265 | 266 | 267 | 268 | //System.out.println("item_holder size"+item_holder.size()); 269 | 270 | user_balance=user_balance+((Book) item_holder.get(item_number)).get_ebook_cost(); 271 | 272 | //System.out.println(user_balance); 273 | 274 | if (user_list.get(user_index)instanceof Member){ 275 | 276 | ((Member) user_list.get(user_index)).addItems(item_holder.get(item_number)); 277 | 278 | ((Member) user_list.get(user_index)).setBalance(((Book) item_holder.get(item_number)).get_ebook_cost()); 279 | 280 | System.out.println(((Member) user_list.get(user_index)).getBalance()); 281 | 282 | find_recommendation(item_holder.get(item_number).getItem_id(),user_index);} 283 | 284 | else if (user_list.get(user_index)instanceof NonMember){ 285 | 286 | ((NonMember) user_list.get(user_index)).addItems(item_holder.get(item_number)); 287 | 288 | ((NonMember) user_list.get(user_index)).setBalance(((Book) item_holder.get(item_number)).get_ebook_cost()); 289 | 290 | System.out.println(((NonMember) user_list.get(user_index)).getBalance()); 291 | 292 | find_recommendation(item_holder.get(item_number).getItem_id(),user_index);} 293 | 294 | return(item_holder.get(item_number)); 295 | 296 | case 0: 297 | 298 | return null; 299 | 300 | } 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | case 3: 309 | loop=false; 310 | System.out.println("Checking out"); 311 | 312 | break; 313 | 314 | case 2: 315 | loop=false; 316 | 317 | if (((Book) item_holder.get(item_number)).get_number_of_copies()>0){ 318 | 319 | // System.out.println("item number::"+item_number); 320 | 321 | System.out.println("Do you want to buy the physical copy of the book ?"); 322 | 323 | System.out.println("Press 1 to buy the book"); 324 | 325 | System.out.println("Press 0 to cancel"); 326 | 327 | 328 | 329 | int option1 = buy.nextInt(); 330 | 331 | 332 | 333 | switch(option1){ 334 | 335 | case 1: 336 | 337 | 338 | 339 | System.out.println("found and added to cart"); 340 | 341 | ((Book) item_holder.get(item_number)).set_physical_book_issue(true); 342 | 343 | ((Book) item_holder.get(item_number)).reduce_copies(); 344 | 345 | user_balance=user_balance+((Book) item_holder.get(item_number)).get_book_cost(); 346 | 347 | 348 | 349 | //System.out.println(user_balance); 350 | 351 | if (user_list.get(user_index)instanceof Member){ 352 | 353 | ((Member) user_list.get(user_index)).addItems(item_holder.get(item_number)); 354 | 355 | ((Member) user_list.get(user_index)).setBalance(((Book) item_holder.get(item_number)).get_book_cost()); 356 | 357 | System.out.println(((Member) user_list.get(user_index)).getBalance()); 358 | 359 | find_recommendation(item_holder.get(item_number).getItem_id(),user_index);} 360 | 361 | else if (user_list.get(user_index)instanceof NonMember){ 362 | 363 | ((NonMember) user_list.get(user_index)).addItems(item_holder.get(item_number)); 364 | 365 | ((NonMember) user_list.get(user_index)).setBalance(((Book) item_holder.get(item_number)).get_book_cost()); 366 | 367 | System.out.println(((NonMember) user_list.get(user_index)).getBalance()); 368 | 369 | find_recommendation(item_holder.get(item_number).getItem_id(),user_index);} 370 | 371 | return(item_holder.get(item_number)); 372 | 373 | case 0: 374 | 375 | return null; 376 | 377 | } 378 | 379 | 380 | 381 | } 382 | 383 | else{ 384 | 385 | System.out.println("no copies available"); 386 | 387 | return null;} 388 | 389 | default: 390 | 391 | System.out.println("That's not a valid input"); 392 | 393 | return null; 394 | 395 | } 396 | } catch (InputMismatchException e) { 397 | System.out.print("Enter the correct option"); 398 | } 399 | read.nextLine(); 400 | }while(loop); 401 | 402 | } 403 | 404 | 405 | 406 | 407 | 408 | else 409 | 410 | System.out.println("This book is only available in the physical format"); 411 | 412 | if (((Book) item_holder.get(item_number)).get_number_of_copies()>0){ 413 | 414 | System.out.println("item number::"+item_number); 415 | 416 | System.out.println("Do you want to buy the physical copy of the book ?"); 417 | 418 | System.out.println("Press 1 to buy the book"); 419 | 420 | System.out.println("Press 0 to cancel"); 421 | 422 | int option = buy.nextInt(); 423 | 424 | 425 | 426 | switch(option){ 427 | 428 | case 1: 429 | 430 | 431 | 432 | System.out.println("found and added to cart"); 433 | 434 | ((Book) item_holder.get(item_number)).set_physical_book_issue(true); 435 | 436 | System.out.println(((Book) item_holder.get(item_number)).get_physical_book_issue()); 437 | 438 | ((Book) item_holder.get(item_number)).reduce_copies(); 439 | 440 | System.out.println(((Book) item_holder.get(item_number)).get_book_cost()); 441 | 442 | user_balance=user_balance+((Book) item_holder.get(item_number)).get_book_cost(); 443 | 444 | if (user_list.get(user_index)instanceof Member){ 445 | 446 | ((Member) user_list.get(user_index)).addItems(item_holder.get(item_number)); 447 | 448 | ((Member) user_list.get(user_index)).setBalance(((Book) item_holder.get(item_number)).get_book_cost()); 449 | 450 | System.out.println(((Member) user_list.get(user_index)).getBalance()); 451 | 452 | find_recommendation(item_holder.get(item_number).getItem_id(),user_index);} 453 | 454 | else if (user_list.get(user_index)instanceof NonMember){ 455 | 456 | ((NonMember) user_list.get(user_index)).addItems(item_holder.get(item_number)); 457 | 458 | ((NonMember) user_list.get(user_index)).setBalance(((Book) item_holder.get(item_number)).get_book_cost()); 459 | 460 | System.out.println(((NonMember) user_list.get(user_index)).getBalance()); 461 | 462 | find_recommendation(item_holder.get(item_number).getItem_id(),user_index);} 463 | 464 | //System.out.println(user_balance); 465 | 466 | return(item_holder.get(item_number)); 467 | 468 | case 0: 469 | 470 | return null; 471 | 472 | } 473 | 474 | } 475 | 476 | else{ 477 | 478 | System.out.println("No copies available"); 479 | 480 | return null;} 481 | 482 | } 483 | 484 | //System.out.println("Not available"); 485 | 486 | //-------------------------checking for software---------------------------------------- 487 | 488 | if (item_holder.get(item_number) instanceof Software){ 489 | 490 | //System.out.println("item number::"+item_number); 491 | 492 | //System.out.println("inside software block"); 493 | 494 | if(((Software) item_holder.get(item_number)).check_download_available()){ 495 | 496 | Scanner read = new Scanner(System.in); 497 | 498 | software_option(); 499 | boolean loop=true; 500 | int download_option=0; 501 | do{ 502 | try{ 503 | System.out.println("Enter the option"); 504 | download_option=read.nextInt(); 505 | switch (download_option){ 506 | 507 | case 0: 508 | loop=false; 509 | break; 510 | 511 | case 1: 512 | loop=false; 513 | System.out.println("Do you want to download the software ?"); 514 | 515 | System.out.println("Press 1 to buy the software"); 516 | 517 | System.out.println("Press 0 to cancel"); 518 | 519 | int option = buy.nextInt(); 520 | 521 | 522 | 523 | switch(option){ 524 | 525 | case 1: 526 | 527 | 528 | 529 | System.out.println("found and added to cart"); 530 | 531 | ((Software) item_holder.get(item_number)).set_download_issue(true); 532 | 533 | user_balance=(int) (user_balance+((Software) item_holder.get(item_number)).get_download_cost()); 534 | 535 | if (user_list.get(user_index)instanceof Member){ 536 | 537 | ((Member) user_list.get(user_index)).addItems(item_holder.get(item_number)); 538 | 539 | ((Member) user_list.get(user_index)).setBalance(((Software) item_holder.get(item_number)).get_download_cost()); 540 | 541 | //System.out.println(((Member) user_list.get(user_index)).getBalance()); 542 | 543 | find_recommendation(item_holder.get(item_number).getItem_id(),user_index);} 544 | 545 | else if (user_list.get(user_index)instanceof NonMember){ 546 | 547 | ((NonMember) user_list.get(user_index)).addItems(item_holder.get(item_number)); 548 | 549 | ((NonMember) user_list.get(user_index)).setBalance(((Software) item_holder.get(item_number)).get_download_cost()); 550 | 551 | //System.out.println(((NonMember) user_list.get(user_index)).getBalance()); 552 | 553 | find_recommendation(item_holder.get(item_number).getItem_id(),user_index);} 554 | 555 | //System.out.println(user_balance); 556 | 557 | return(item_holder.get(item_number)); 558 | 559 | case 0: 560 | 561 | return null; 562 | 563 | } 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | case 3:System.out.println("Checking out"); 572 | loop=false; 573 | break; 574 | 575 | case 2: 576 | loop=false; 577 | if (((Software) item_holder.get(item_number)).get_number_of_cd()>0){ 578 | 579 | System.out.println("item number::"+item_number); 580 | 581 | System.out.println("Do you want to buy the CD version of the software ?"); 582 | 583 | System.out.println("Press 1 to buy the CD"); 584 | 585 | System.out.println("Press 0 to cancel"); 586 | 587 | 588 | 589 | int option1 = buy.nextInt(); 590 | 591 | 592 | 593 | switch(option1){ 594 | 595 | case 1: 596 | 597 | 598 | 599 | System.out.println("found and added to cart"); 600 | 601 | ((Software) item_holder.get(item_number)).setCd_issue(true); 602 | 603 | ((Software) item_holder.get(item_number)).reduce_copies(); 604 | 605 | user_balance=(int) (user_balance+((Software) item_holder.get(item_number)).get_cd_cost()); 606 | 607 | //System.out.println(user_balance); 608 | 609 | if (user_list.get(user_index)instanceof Member){ 610 | 611 | ((Member) user_list.get(user_index)).addItems(item_holder.get(item_number)); 612 | 613 | ((Member) user_list.get(user_index)).setBalance(((Software) item_holder.get(item_number)).get_cd_cost()); 614 | 615 | //System.out.println(((Member) user_list.get(user_index)).getBalance()); 616 | 617 | find_recommendation(item_holder.get(item_number).getItem_id(),user_index);} 618 | 619 | else if (user_list.get(user_index)instanceof NonMember){ 620 | 621 | ((NonMember) user_list.get(user_index)).addItems(item_holder.get(item_number)); 622 | 623 | ((NonMember) user_list.get(user_index)).setBalance(((Software) item_holder.get(item_number)).get_cd_cost()); 624 | 625 | //System.out.println(((NonMember) user_list.get(user_index)).getBalance()); 626 | 627 | find_recommendation(item_holder.get(item_number).getItem_id(),user_index);} 628 | 629 | return(item_holder.get(item_number)); 630 | 631 | case 0: 632 | 633 | return null; 634 | 635 | } 636 | 637 | 638 | 639 | } 640 | 641 | else{ 642 | 643 | System.out.println("no copies available"); 644 | 645 | return null;} 646 | 647 | default: 648 | 649 | System.out.println("That's not a valid input"); 650 | 651 | return null; 652 | 653 | } 654 | } catch (InputMismatchException e) { 655 | System.out.print("Enter the correct option"); 656 | } 657 | read.nextLine(); 658 | }while(loop); 659 | 660 | } 661 | 662 | else 663 | 664 | System.out.println("This software is only available in the CD format"); 665 | 666 | if (((Software) item_holder.get(item_number)).get_number_of_cd()>0){ 667 | 668 | //System.out.println("item number::"+item_number); 669 | 670 | System.out.println("Do you want to buy the CD of the Software ?"); 671 | 672 | System.out.println("Press 1 to buy the CD"); 673 | 674 | System.out.println("Press 0 to cancel"); 675 | 676 | int option= 0; 677 | boolean loop=true; 678 | do{ 679 | try{ 680 | System.out.println("\n Print the option"); 681 | option=buy.nextInt(); 682 | switch(option){ 683 | 684 | case 1: 685 | 686 | 687 | loop=false; 688 | System.out.println("found and added to cart"); 689 | 690 | ((Software) item_holder.get(item_number)).setCd_issue(true); 691 | 692 | ((Software) item_holder.get(item_number)).reduce_copies(); 693 | 694 | user_balance=(int) (user_balance+((Software) item_holder.get(item_number)).get_cd_cost()); 695 | 696 | System.out.println(user_balance); 697 | 698 | if (user_list.get(user_index)instanceof Member){ 699 | 700 | ((Member) user_list.get(user_index)).addItems(item_holder.get(item_number)); 701 | 702 | ((Member) user_list.get(user_index)).setBalance(((Software) item_holder.get(item_number)).get_cd_cost()); 703 | 704 | //System.out.println(((Member) user_list.get(user_index)).getBalance()); 705 | 706 | find_recommendation(item_holder.get(item_number).getItem_id(),user_index);} 707 | 708 | else if (user_list.get(user_index)instanceof NonMember){ 709 | 710 | ((NonMember) user_list.get(user_index)).addItems(item_holder.get(item_number)); 711 | 712 | ((NonMember) user_list.get(user_index)).setBalance(((Software) item_holder.get(item_number)).get_cd_cost()); 713 | 714 | //System.out.println(((NonMember) user_list.get(user_index)).getBalance()); 715 | 716 | find_recommendation(item_holder.get(item_number).getItem_id(),user_index);} 717 | 718 | return(item_holder.get(item_number)); 719 | 720 | case 0: 721 | loop=false; 722 | return null; 723 | 724 | } 725 | } catch (InputMismatchException e) { 726 | System.out.print("Enter the correct option"); 727 | } 728 | buy.nextLine(); 729 | }while(loop); 730 | 731 | } 732 | 733 | else{ 734 | 735 | System.out.println("No copies available"); 736 | 737 | return null;} 738 | 739 | } 740 | 741 | System.out.println("Not available"); 742 | 743 | 744 | 745 | }//closing of if found 746 | 747 | return null; 748 | 749 | } 750 | 751 | 752 | 753 | 754 | 755 | private static void software_option() { 756 | 757 | System.out.println(); 758 | 759 | System.out.print( 760 | 761 | " 1. Buy the downloadable version(Software) \n"+ 762 | 763 | " 2. Buy CD\n"+ 764 | 765 | " 3. Checkout\n" + 766 | 767 | " 4. List all Software items in store\n" + 768 | 769 | " 5. Go back \n"); 770 | 771 | 772 | 773 | } 774 | 775 | 776 | 777 | public static void show_all_items(ArrayList list1) 778 | 779 | { 780 | 781 | Iterator itr = list1.iterator(); 782 | 783 | int index=1; 784 | 785 | while(itr.hasNext()){ 786 | 787 | Item element = (Item) itr.next(); 788 | 789 | if(element!=null){ 790 | 791 | 792 | 793 | if(element instanceof Book){ 794 | 795 | System.out.print("\n"+index+" "); 796 | 797 | ((Book) element).show_book(); 798 | 799 | 800 | 801 | index++; 802 | 803 | } 804 | 805 | else if(element instanceof Software){ 806 | 807 | System.out.print("\n"+index+" "); 808 | 809 | ((Software) element).show_software(); 810 | 811 | 812 | 813 | index++; 814 | 815 | } 816 | 817 | } 818 | 819 | } 820 | 821 | } 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | //display the cart 830 | 831 | public static void show_sales (ArrayList cart) 832 | 833 | { 834 | 835 | if (get_balance()==0){ 836 | 837 | System.out.println("Cart Empty"); 838 | 839 | } 840 | 841 | else{ 842 | 843 | Iterator itr = cart.iterator(); 844 | 845 | int count=1; 846 | 847 | while(itr.hasNext()){ 848 | 849 | Item element = (Item) itr.next(); 850 | 851 | if(element!=null){ 852 | 853 | System.out.println(); 854 | 855 | System.out.print(count+" "); 856 | 857 | if(element instanceof Book){ 858 | 859 | if(((Book) element).get_ebook_issue()){ 860 | 861 | ((Book) element).ebook_sales(); 862 | 863 | } 864 | 865 | if(((Book) element).get_physical_book_issue()){ 866 | 867 | ((Book) element).book_sales(); 868 | 869 | } 870 | 871 | count++; 872 | 873 | } 874 | 875 | else if(element instanceof Software){ 876 | 877 | if(((Software) element).get_download_issue()){ 878 | 879 | ((Software) element).download_sales(); 880 | 881 | } 882 | 883 | if(((Software) element).isCd_issue()){ 884 | 885 | ((Software) element).cd_sales(); 886 | 887 | } 888 | 889 | count++; 890 | 891 | } 892 | 893 | 894 | 895 | } 896 | 897 | 898 | 899 | } 900 | 901 | System.out.println(); 902 | 903 | System.out.println(" Total Balance:$ "+get_balance()); 904 | 905 | } 906 | 907 | } 908 | 909 | // returns the balance 910 | 911 | public static double get_balance () 912 | 913 | { 914 | 915 | return user_balance; 916 | 917 | } 918 | 919 | public static void print_menu(){ 920 | 921 | System.out.println(); 922 | 923 | System.out.println(" Welcome to TechBooks"); 924 | 925 | System.out.println("----------------------------------------------------------------------" 926 | 927 | + "----------------------------------------------------------------------------"); 928 | 929 | System.out.println("Please select an option:\n"+ 930 | 931 | "1. Add item to shopping cart\n"+ 932 | 933 | "2. View shopping cart\n"+ 934 | 935 | "3. Remove item from shopping cart\n"+ 936 | 937 | "4. Checkout\n" + 938 | 939 | "5. List all items\n"+ 940 | 941 | "6. Print previous purchases\n"+ 942 | 943 | "7. Change User\n"+ 944 | 945 | "0. Quit\n"); 946 | 947 | //System.out.println("Enter a option"); 948 | 949 | } 950 | 951 | 952 | 953 | public static void print_admin_menu(){ 954 | 955 | System.out.println(); 956 | 957 | System.out.println(" Welcome to TechBooks"); 958 | 959 | System.out.println("----------------------------------------------------------------------" 960 | 961 | + "----------------------------------------------------------------------------"); 962 | 963 | System.out.print( 964 | 965 | "1. List all items (purchase statistics for each title)"+"\n"+ 966 | 967 | "2. Display all Users"+"\n"+ 968 | 969 | "3. Change price of item"+"\n"+ 970 | 971 | "4. Add new user"+"\n"+ 972 | 973 | "5.Add Copies to the items"+"\n"+ 974 | 975 | "6.Sales Analytics"+"\n"+ 976 | 977 | "7.Change User"+"\n"+"\n 0.Quit"); 978 | 979 | // System.out.println("Enter a option"); 980 | 981 | //Welcome to TechStore, Robert MacQuillan. You are logged in as an Administrator. 982 | 983 | 984 | 985 | //Please select an option: 986 | 987 | // 1. List all items 988 | 989 | //2. Add copies to item 990 | 991 | // 3. Change price of item 992 | 993 | // 4. Add new user 994 | 995 | // 5. Change user 996 | 997 | // 0. Quit 998 | 999 | } 1000 | 1001 | public static void book_option(){ 1002 | 1003 | System.out.println(); 1004 | 1005 | System.out.print( 1006 | 1007 | " 1. Buy an ebook \n"+ 1008 | 1009 | " 2. Buy physical book\n"+ 1010 | 1011 | " 3. Checkout\n" + 1012 | 1013 | " 4. List all books in store\n" + 1014 | 1015 | " 5. Go back \n"); 1016 | 1017 | 1018 | 1019 | } 1020 | 1021 | 1022 | 1023 | public static void add_member(String id,String password,String name,String email){ 1024 | 1025 | Member new_member=new Member(id,password,name,email); 1026 | 1027 | user_list.add(new_member); 1028 | 1029 | } 1030 | 1031 | public static void add_admin(String id,String password,String name,String email){ 1032 | 1033 | Admin new_admin=new Admin(id,password,name,email); 1034 | 1035 | user_list.add(new_admin); 1036 | 1037 | } 1038 | 1039 | public static void add_non_member(String id,String password,String name,String email){ 1040 | 1041 | NonMember new_non=new NonMember(id,password,name,email); 1042 | 1043 | user_list.add(new_non); 1044 | 1045 | } 1046 | 1047 | public static void initial(){ 1048 | 1049 | 1050 | 1051 | Item[] book_array = new Book[5]; 1052 | 1053 | Item[] soft_array = new Software[5]; 1054 | 1055 | 1056 | 1057 | 1058 | 1059 | soft_array[0]=new Software(6,"24-04-2015","Sega Genesis Classics Game Pack","Sega",true,37.50,39.99,10); 1060 | 1061 | soft_array[1]=new Software(7,"24-04-2015","Civilization 5 for Mac","2K",true,58.99,65.99,5); 1062 | 1063 | soft_array[2]=new Software(8,"24-04-2015","Jake and the Neverland Pirates","LeapFrog",false,17.50,19.99,10); 1064 | 1065 | soft_array[3]=new Software(9,"24-04-2015","Call of Duty","Achvision",false,11.62,0,10); 1066 | 1067 | soft_array[4]=new Software(10,"24-04-2015","The Magic School Bus","LeapFrog",true,15.49,17.99,1); 1068 | 1069 | //Sega Genesis Classics Game Pack, Sega, CD and download, 10 copies, $37.50/$39.99 1070 | 1071 | //- Recommended: none 1072 | 1073 | //Civilization 5 for Mac, 2K, CD and download, 5 copies, $58.99/$65.99 1074 | 1075 | //- Recommended: Call of Duty (Achvision) 1076 | 1077 | //Jake and the Neverland Pirates, LeadFrog, CD and download, 0 copies, $17.50/$19.99 1078 | 1079 | //- Recommended: The Magic School Bus (LeapFrog) 1080 | 1081 | //Call of Duty, Achvision, CD only, 0 copies, $11.62 1082 | 1083 | //- Recommended: Civilization 5 for Mac (2K) 1084 | 1085 | //The Magic School Bus, LeapFrog, CD and download, 1 copy, $15.49/17.99 1086 | 1087 | //- Recommended: Jake and the Neverland Pirates (LeadFrog) 1088 | 1089 | 1090 | 1091 | book_array[0]=new Book(1,"24-04-2015","Absolute Java","Savitch",true,75,15,5); 1092 | 1093 | book_array[1]=new Book(2,"24-04-2015","JAVA: How to Program","Deitel and Deitel",true,65,12,1); 1094 | 1095 | book_array[2]=new Book(3,"24-04-2015","Computing Concepts with JAVA 3 Essentials","Hortsman",false,114.72,0,5); 1096 | 1097 | book_array[3]=new Book(4,"24-04-2015","Java Software Solutions","Lewis and Loftus",false,80.00,0,5); 1098 | 1099 | book_array[4]=new Book(5,"24-04-2015","Java Program Design","Cohoon and Davidson",true,51.00,10.00,1); 1100 | 1101 | rec_list1.add(book_array[0]); 1102 | 1103 | rec_list2.add(book_array[0]); 1104 | 1105 | rec_list2.add(book_array[1]); 1106 | 1107 | rec_list3.add(soft_array[3]); 1108 | 1109 | rec_list4.add(soft_array[4]); 1110 | 1111 | rec_list5.add(soft_array[1]); 1112 | 1113 | rec_list6.add(soft_array[2]); 1114 | 1115 | recommend.put(2,rec_list1); 1116 | 1117 | recommend.put(3,rec_list2); 1118 | 1119 | recommend.put(7,rec_list3); 1120 | 1121 | recommend.put(8,rec_list4); 1122 | 1123 | recommend.put(9,rec_list5); 1124 | 1125 | recommend.put(10,rec_list6); 1126 | 1127 | //list.addAll(recommend.get(2)); 1128 | 1129 | //System.out.println("Size of the list "+list.size()); 1130 | 1131 | 1132 | 1133 | for(int i=0;i itr = user_list.iterator(); 1220 | 1221 | 1222 | 1223 | Scanner input = new Scanner(System.in); 1224 | 1225 | boolean user_found=false; 1226 | 1227 | boolean invalid=true; 1228 | 1229 | System.out.println("Enter UserName:"); 1230 | 1231 | String user_name=input.nextLine(); 1232 | 1233 | while(itr.hasNext()) { 1234 | 1235 | user_found=false; 1236 | 1237 | HashMap map = new HashMap(); 1238 | 1239 | //System.out.println(user_list.size()); 1240 | 1241 | //Iterator itr = user_list.iterator(); 1242 | 1243 | if(user_found==false){ 1244 | 1245 | User element = (User) itr.next(); 1246 | 1247 | map.put(element.getId(),element.getPassword()); 1248 | 1249 | } 1250 | 1251 | 1252 | 1253 | while(hm.containsKey(user_name)){ 1254 | 1255 | System.out.println("Enter PassWord"); 1256 | 1257 | String password=input.nextLine(); 1258 | 1259 | if((boolean) hm.get(user_name).equals(password)){ 1260 | 1261 | System.out.println("Welcome::"+user_name); 1262 | 1263 | user_found=true; 1264 | 1265 | break; 1266 | 1267 | } 1268 | 1269 | else System.out.println("Wrong password"); 1270 | 1271 | 1272 | 1273 | } 1274 | 1275 | count++; 1276 | 1277 | //System.out.println("printing count"+count); 1278 | 1279 | 1280 | 1281 | if(user_found){ 1282 | 1283 | //user_found=false; 1284 | 1285 | invalid=false; 1286 | 1287 | return count; 1288 | 1289 | // break; 1290 | 1291 | } 1292 | 1293 | 1294 | 1295 | } 1296 | 1297 | if(!user_found){ 1298 | 1299 | System.out.println("User not found in the database"); 1300 | 1301 | return authenticate(-1); 1302 | 1303 | } 1304 | 1305 | 1306 | 1307 | 1308 | 1309 | return (Integer) 99; 1310 | 1311 | } 1312 | 1313 | 1314 | 1315 | public static void main_activity(int count){ 1316 | 1317 | //System.out.println("inside main activity"); 1318 | 1319 | while(count>user_list.size()){ 1320 | 1321 | System.out.println("invalid username"); 1322 | 1323 | System.exit(0); 1324 | 1325 | } 1326 | 1327 | boolean change_user=false; 1328 | 1329 | while(true){ 1330 | 1331 | if((user_list.get(count) instanceof Member) || (user_list.get(count) instanceof NonMember)){ 1332 | 1333 | //System.out.println(user_list.get(count).getClass()); 1334 | 1335 | if(user_list.get(count) instanceof NonMember){ 1336 | 1337 | System.out.println(); 1338 | 1339 | System.out.println("Hi "+ user_list.get(count).getName()+" You are signed in as a Non Member"); 1340 | 1341 | // ((NonMember) user_list.get(count)).set_count(); 1342 | 1343 | //System.out.println(((NonMember) user_list.get(count)).get_count()); 1344 | 1345 | } 1346 | 1347 | else if(user_list.get(count) instanceof Member){ 1348 | 1349 | System.out.println(); 1350 | 1351 | System.out.println("Hi "+ user_list.get(count).getName()+" You are signed in as a Member"); 1352 | 1353 | //((Member) user_list.get(count)).setLogin_count(); 1354 | 1355 | //System.out.println(((Member) user_list.get(count)).getLogin_count()); 1356 | 1357 | } 1358 | 1359 | 1360 | 1361 | System.out.println("Welcome to TechStore"); 1362 | 1363 | 1364 | 1365 | print_menu(); 1366 | /* 1367 | do { 1368 | try { 1369 | System.out.print("Enter the number of students: "); 1370 | students = input.nextInt(); 1371 | } catch (InputMismatchException e) { 1372 | System.out.print("Enter the number of students"); 1373 | } 1374 | input.nextLine(); // clears the buffer 1375 | } while (students <= 0); 1376 | */ 1377 | //print menu function prints the menu 1378 | 1379 | Scanner reader=new Scanner(System.in); 1380 | 1381 | Integer option=0; 1382 | 1383 | 1384 | 1385 | //take input from the user 1386 | boolean loop=true; 1387 | do{ 1388 | 1389 | try{ 1390 | System.out.println("Enter the option"); 1391 | option = reader.nextInt(); 1392 | switch(option){ 1393 | 1394 | case 1: 1395 | loop=false; 1396 | System.out.println("Enter the name of the item"); 1397 | 1398 | 1399 | 1400 | String item_name= input.nextLine(); 1401 | 1402 | sales.add(find_my_book(item_name,count)); 1403 | 1404 | break; 1405 | 1406 | case 2: 1407 | 1408 | //show_cart(cart); 1409 | 1410 | 1411 | loop=false; 1412 | if(user_list.get(count) instanceof Member){ 1413 | 1414 | //System.out.println("Hi"+ user_list.get(count).getName()+" You are signed in as a Member"); 1415 | 1416 | //System.out.println(((Member) user_list.get(count)).getLogin_count()); 1417 | 1418 | //System.out.println(user_list.get(count).getBalance()); 1419 | 1420 | user_list.get(count).show_my_balance(); 1421 | 1422 | ((Member) user_list.get(count)).show_my_thing(); 1423 | 1424 | } 1425 | 1426 | if(user_list.get(count) instanceof NonMember){ 1427 | 1428 | 1429 | 1430 | System.out.println(((NonMember) user_list.get(count)).get_count()); 1431 | 1432 | //System.out.println(user_list.get(count).getBalance()); 1433 | 1434 | user_list.get(count).show_my_balance(); 1435 | 1436 | ( (NonMember) user_list.get(count)).show_my_thing(); 1437 | 1438 | } 1439 | 1440 | //display the contents of the cart. 1441 | 1442 | break; 1443 | 1444 | case 6: 1445 | 1446 | //show_cart(cart); 1447 | 1448 | loop=false; 1449 | 1450 | if(user_list.get(count) instanceof Member){ 1451 | 1452 | System.out.println(((Member) user_list.get(count)).getLogin_count()); 1453 | 1454 | System.out.println(user_list.get(count).getBalance()); 1455 | 1456 | ((Member) user_list.get(count)).show_my_thing(); 1457 | 1458 | } 1459 | 1460 | if(user_list.get(count) instanceof NonMember){ 1461 | 1462 | System.out.println(((NonMember) user_list.get(count)).get_count()); 1463 | 1464 | System.out.println(user_list.get(count).getBalance()); 1465 | 1466 | ( (NonMember) user_list.get(count)).show_my_thing(); 1467 | 1468 | } 1469 | 1470 | //display the contents of the cart. 1471 | 1472 | break; 1473 | 1474 | case 4: 1475 | loop=false; 1476 | //show_cart(cart); 1477 | 1478 | 1479 | 1480 | if(user_list.get(count) instanceof Member){ 1481 | 1482 | //System.out.println(((Member) user_list.get(count)).getLogin_count()); 1483 | 1484 | //System.out.println(user_list.get(count).getBalance()); 1485 | 1486 | ((Member) user_list.get(count)).show_my_thing(); 1487 | 1488 | } 1489 | 1490 | if(user_list.get(count) instanceof NonMember){ 1491 | 1492 | //System.out.println(((NonMember) user_list.get(count)).get_count()); 1493 | 1494 | //System.out.println(user_list.get(count).getBalance()); 1495 | 1496 | ( (NonMember) user_list.get(count)).show_my_thing(); 1497 | 1498 | } 1499 | 1500 | //display the contents of the cart. 1501 | 1502 | break; 1503 | 1504 | case 3: 1505 | loop=false; 1506 | if(user_list.get(count)instanceof Member){ 1507 | 1508 | ((Member) user_list.get(count)).remove_items(); 1509 | 1510 | break; 1511 | 1512 | } 1513 | 1514 | if(user_list.get(count)instanceof NonMember){ 1515 | 1516 | ((NonMember) user_list.get(count)).remove_items(); 1517 | 1518 | break; 1519 | 1520 | } 1521 | 1522 | 1523 | 1524 | case 5: 1525 | loop=false; 1526 | show_all_items(list); 1527 | 1528 | //display all the books in the store. 1529 | 1530 | break; 1531 | 1532 | case 7: change_user=true; 1533 | loop=false; 1534 | System.out.println("change user"); 1535 | 1536 | if(user_list.get(count) instanceof Member){ 1537 | 1538 | System.out.println("belongs to member"); 1539 | 1540 | ((Member) user_list.get(count)).setLogin_count(); 1541 | 1542 | //System.out.println(((Member) user_list.get(count)).getLogin_count()); 1543 | 1544 | //System.out.println(user_list.get(count).getBalance()); 1545 | 1546 | //((Member) user_list.get(count)).show_my_thing(); 1547 | 1548 | } 1549 | 1550 | if(user_list.get(count) instanceof NonMember){ 1551 | 1552 | System.out.println("belongs to non member"); 1553 | 1554 | ((NonMember) user_list.get(count)).set_count(); 1555 | 1556 | //System.out.println(((NonMember) user_list.get(count)).get_count()); 1557 | 1558 | //System.out.println(user_list.get(count).getBalance()); 1559 | 1560 | //( (NonMember) user_list.get(count)).show_my_thing(); 1561 | 1562 | if ((((NonMember) user_list.get(count)).get_count()<=1) && (user_list.get(count).getBalance()>100)){ 1563 | 1564 | System.out.println("You exceeded the limit"); 1565 | 1566 | user_list.remove(count); 1567 | 1568 | user_list.trimToSize(); 1569 | 1570 | System.out.println("Deleted from database"); 1571 | 1572 | } 1573 | 1574 | else if((((NonMember) user_list.get(count)).get_count()>1) && (user_list.get(count).getBalance()>110)){ 1575 | 1576 | System.out.println("\n\nWould yo like to become a member??"); 1577 | 1578 | System.out.println("Press 1 to become a privileged member\n"+"Press 0 to discard the offer\n"); 1579 | 1580 | Scanner inp=new Scanner(System.in); 1581 | 1582 | int get=inp.nextInt(); 1583 | 1584 | if(get==1){ 1585 | 1586 | String id,name,password,email; 1587 | 1588 | id=user_list.get(count).getId(); 1589 | 1590 | name=user_list.get(count).getName(); 1591 | 1592 | password=user_list.get(count).getPassword(); 1593 | 1594 | email=user_list.get(count).getEmail(); 1595 | 1596 | user_list.remove(count); 1597 | 1598 | Member new_member = new Member(id,password,name,email); 1599 | 1600 | System.out.println("You have been added to the system as a member.Enjoy shopping with more freedom"); 1601 | 1602 | user_list.add(new_member); 1603 | 1604 | //main_activity(authenticate(-1)); 1605 | 1606 | } 1607 | 1608 | } 1609 | 1610 | } 1611 | 1612 | break; 1613 | 1614 | case 0:System.exit(0); 1615 | 1616 | default: 1617 | 1618 | System.out.println("That is not a valid input"); 1619 | 1620 | break; 1621 | 1622 | } 1623 | }catch (InputMismatchException e) { 1624 | System.out.print("Please Enter the correct input from the Menu above"); 1625 | } 1626 | reader.nextLine(); 1627 | }while(loop); 1628 | 1629 | } 1630 | 1631 | 1632 | 1633 | 1634 | 1635 | 1636 | if(user_list.get(count) instanceof Admin){ 1637 | 1638 | //System.out.println(user_list.get(count).getClass()); 1639 | 1640 | System.out.println(); 1641 | 1642 | System.out.println("Welcome to TechStore"); 1643 | 1644 | System.out.println("Hi "+ user_list.get(count).getName()+" You are signed in as a Admin"); 1645 | 1646 | //user_list.get(count).setLogin_count(); 1647 | 1648 | System.out.println(user_list.get(count).getName()); 1649 | 1650 | //System.out.println(user_list.get(count).getLogin_count()); 1651 | 1652 | print_admin_menu(); 1653 | 1654 | //print menu function prints the menu 1655 | 1656 | Scanner reader=new Scanner(System.in); 1657 | 1658 | int option =0; 1659 | boolean loop=true; 1660 | do{ 1661 | 1662 | try{ 1663 | System.out.println("Enter the option"); 1664 | option=reader.nextInt(); 1665 | 1666 | //take input from the user 1667 | 1668 | switch(option){ 1669 | 1670 | case 7: 1671 | loop=false; 1672 | change_user=true; 1673 | 1674 | System.out.println("change user"); 1675 | 1676 | break; 1677 | 1678 | case 1: 1679 | loop=false; 1680 | show_all_items(list); 1681 | 1682 | break; 1683 | 1684 | 1685 | 1686 | case 5: 1687 | loop=false; 1688 | add_copies(list); 1689 | 1690 | break; 1691 | 1692 | case 2: 1693 | loop=false; 1694 | show_all_users(); 1695 | 1696 | break; 1697 | 1698 | case 3: 1699 | loop=false; 1700 | show_all_items(list); 1701 | 1702 | break; 1703 | 1704 | case 4: 1705 | loop=false; 1706 | Scanner take_input= new Scanner(System.in); 1707 | 1708 | String id = null; 1709 | 1710 | Iterator i=user_list.iterator(); 1711 | 1712 | boolean id_unique=false; 1713 | 1714 | while(true){ 1715 | 1716 | System.out.println("Enter Id"); 1717 | 1718 | String ID1=take_input.nextLine(); 1719 | 1720 | 1721 | 1722 | while(i.hasNext()){ 1723 | 1724 | if(i.next().getId().equals(ID1)){ 1725 | 1726 | System.out.println("ID already exists"); 1727 | 1728 | id_unique=false; 1729 | 1730 | break; 1731 | 1732 | } 1733 | 1734 | else{ 1735 | 1736 | id_unique=true; 1737 | 1738 | } 1739 | 1740 | } 1741 | 1742 | if(id_unique){ 1743 | 1744 | id=ID1; 1745 | 1746 | break; 1747 | 1748 | } 1749 | 1750 | } 1751 | 1752 | System.out.println("Enter name"); 1753 | 1754 | String NAME=input.nextLine(); 1755 | 1756 | System.out.println("Enter password"); 1757 | 1758 | String PASSWORD=take_input.nextLine(); 1759 | 1760 | System.out.println("Enter email"); 1761 | 1762 | String EMAIL=input.nextLine(); 1763 | 1764 | System.out.println("Press 1 to add this person as Member\n"+"Press 2 to add as Non Member\n"+"\nPress 3 to add as Admin"); 1765 | 1766 | Scanner my_in=new Scanner(System.in); 1767 | 1768 | int input=my_in.nextInt(); 1769 | 1770 | if(input==1){ 1771 | 1772 | add_member(id,NAME,PASSWORD,EMAIL); 1773 | 1774 | } 1775 | 1776 | else if(input==2){ 1777 | 1778 | add_non_member(id,NAME,PASSWORD,EMAIL); 1779 | 1780 | } 1781 | 1782 | else if(input==3){ 1783 | 1784 | add_admin(id,NAME,PASSWORD,EMAIL); 1785 | 1786 | } 1787 | 1788 | else{ 1789 | 1790 | System.out.println("Not a valid input"); 1791 | 1792 | } 1793 | 1794 | //show_all_items(list); 1795 | 1796 | //display all the books in the store. 1797 | 1798 | break; 1799 | 1800 | case 6: 1801 | loop=false; 1802 | show_sales(sales); 1803 | 1804 | break; 1805 | 1806 | case 0:System.exit(0); 1807 | 1808 | default: 1809 | 1810 | System.out.println("That is not a valid input"); 1811 | 1812 | break; 1813 | 1814 | } 1815 | } 1816 | catch (InputMismatchException e) { 1817 | System.out.print("Please Enter the correct input from the Menu above"); 1818 | } 1819 | reader.nextLine(); 1820 | }while(loop); 1821 | 1822 | } 1823 | 1824 | if(change_user){ 1825 | 1826 | int local=authenticate(-1); 1827 | 1828 | if(local==-1){ 1829 | 1830 | local--;} 1831 | 1832 | change_user=false; 1833 | 1834 | main_activity(local); 1835 | 1836 | //change_user=false; 1837 | 1838 | } 1839 | 1840 | } 1841 | 1842 | } 1843 | 1844 | public static void show_all_users(){ 1845 | 1846 | Iterator itr= user_list.iterator(); 1847 | 1848 | while(((Iterator) itr).hasNext()){ 1849 | 1850 | User u=(User) itr.next(); 1851 | 1852 | if(u instanceof Member){ 1853 | 1854 | ((Member) u).show_member(); 1855 | 1856 | } 1857 | 1858 | if(u instanceof NonMember){ 1859 | 1860 | ((NonMember) u).show_member(); 1861 | 1862 | } 1863 | if(u instanceof Admin){ 1864 | 1865 | ((Admin) u).show_member(); 1866 | 1867 | } 1868 | 1869 | 1870 | 1871 | 1872 | } 1873 | 1874 | } 1875 | 1876 | 1877 | 1878 | public static void add_copies(ArrayList list2){ 1879 | 1880 | show_all_items(list); 1881 | 1882 | Scanner input= new Scanner(System.in); 1883 | 1884 | System.out.println("\n\n"+"Mention the index to add copies"); 1885 | 1886 | int my_num=input.nextInt(); 1887 | 1888 | my_num--; 1889 | 1890 | if(list2.get(my_num) instanceof Book){ 1891 | 1892 | ((Book) list.get(my_num)).add_copies(); 1893 | 1894 | } 1895 | 1896 | else if(list2.get(my_num) instanceof Software){ 1897 | 1898 | ((Software) list.get(my_num)).add_copies(); 1899 | 1900 | 1901 | 1902 | } 1903 | 1904 | else{ 1905 | 1906 | System.out.println("Wrong input"); 1907 | 1908 | } 1909 | 1910 | return; 1911 | 1912 | } 1913 | 1914 | public static void find_recommendation(int item_id,int user_number){ 1915 | 1916 | //System.out.println("inside recommendation"); 1917 | 1918 | ArrayList rec_holder=new ArrayList(); 1919 | 1920 | if(recommend.containsKey(item_id)){ 1921 | 1922 | rec_holder.addAll(recommend.get(item_id)); 1923 | 1924 | Iterator itr = rec_holder.iterator(); 1925 | 1926 | int in=0; 1927 | 1928 | while(itr.hasNext()){ 1929 | 1930 | Item element = itr.next(); 1931 | 1932 | if(element instanceof Book){ 1933 | 1934 | in++; 1935 | 1936 | System.out.println(); 1937 | 1938 | System.out.print(in+" "); 1939 | 1940 | ((Book) element).show_book(); 1941 | 1942 | } 1943 | 1944 | if(element instanceof Software){ 1945 | 1946 | in++; 1947 | 1948 | System.out.println(); 1949 | 1950 | System.out.print(in+" "); 1951 | 1952 | ((Software) element).show_software(); 1953 | 1954 | } 1955 | 1956 | } 1957 | 1958 | System.out.println(" Would you like to buy the recommened items?"); 1959 | 1960 | //set up a loop ..1 t purchase 0 to exit.. 1961 | 1962 | //outer input 1963 | 1964 | System.out.println("\nPress 1 to buy..\n Press 0 to quit "); 1965 | 1966 | Scanner input = new Scanner (System.in); 1967 | 1968 | int user_input=input.nextInt(); 1969 | 1970 | while(user_input==1){ 1971 | 1972 | //System.out.println("inside while loop"); 1973 | 1974 | System.out.println("Wish item do you wish to purchase?\n Type the index of the item to purchase it."); 1975 | 1976 | int buy_item=input.nextInt(); 1977 | 1978 | buy_item--; 1979 | 1980 | sales.add(buy_rec_item(rec_holder,buy_item,user_number)); 1981 | 1982 | System.out.println("Press 0 to quit "); 1983 | 1984 | user_input=input.nextInt(); 1985 | 1986 | } 1987 | 1988 | } 1989 | 1990 | else{ 1991 | 1992 | System.out.println("No recommended titles present for this item");} 1993 | 1994 | } 1995 | 1996 | public static Item buy_rec_item(ArrayList rec,int item_number,int user_number) 1997 | 1998 | { 1999 | 2000 | if(rec.get(item_number)instanceof Book){ 2001 | 2002 | System.out.println("Press 1 to buy the physical book"+"\n"+"Press 2 to buy the ebook of the book"); 2003 | 2004 | Scanner input =new Scanner (System.in); 2005 | 2006 | int buy=input.nextInt(); 2007 | 2008 | if(buy==1){ 2009 | 2010 | if(((Book) rec.get(item_number)).get_number_of_copies()>0){ 2011 | 2012 | System.out.println("found and added to cart"); 2013 | 2014 | ((Book) rec.get(item_number)).set_physical_book_issue(true); 2015 | 2016 | ((Book) rec.get(item_number)).reduce_copies(); 2017 | 2018 | //user_balance=user_balance+((Book) rec.get(item_number)).m_dis_book(); 2019 | 2020 | 2021 | 2022 | //System.out.println(user_balance); 2023 | 2024 | if (user_list.get(user_number)instanceof Member){ 2025 | 2026 | ((Book) rec.get(item_number)).set_m_rec_book_issue(true); 2027 | 2028 | ((Member) user_list.get(user_number)).addItems(rec.get(item_number)); 2029 | 2030 | ((Member) user_list.get(user_number)).setBalance(((Book) rec.get(item_number)).m_dis_book()); 2031 | 2032 | System.out.println(((Member) user_list.get(user_number)).getBalance()); 2033 | 2034 | find_recommendation(rec.get(item_number).getItem_id(),user_number);} 2035 | 2036 | else if (user_list.get(user_number)instanceof NonMember){ 2037 | 2038 | ((Book) rec.get(item_number)).set_nm_rec_book_issue(true); 2039 | 2040 | ((NonMember) user_list.get(user_number)).addItems(rec.get(item_number)); 2041 | 2042 | ((NonMember) user_list.get(user_number)).setBalance(((Book) rec.get(item_number)).nm_dis_book()); 2043 | 2044 | System.out.println(((NonMember) user_list.get(user_number)).getBalance()); 2045 | 2046 | find_recommendation(rec.get(item_number).getItem_id(),user_number);} 2047 | 2048 | return(rec.get(item_number)); 2049 | 2050 | } 2051 | 2052 | else{ 2053 | 2054 | System.out.println("Physical book not available"); 2055 | 2056 | } 2057 | 2058 | } 2059 | 2060 | if(buy==2){ 2061 | 2062 | if(((Book) rec.get(item_number)).check_ebook_available()){ 2063 | 2064 | System.out.println("found and added to cart"); 2065 | 2066 | System.out.println("item number::"+item_number); 2067 | 2068 | ((Book) rec.get(item_number)).set_ebook_issue(true); 2069 | 2070 | 2071 | 2072 | //System.out.println("item_holder size"+item_holder.size()); 2073 | 2074 | //user_balance=user_balance+((Book) rec.get(item_number)).m_dis_ebook(); 2075 | 2076 | //System.out.println(user_balance); 2077 | 2078 | if (user_list.get(user_number)instanceof Member){ 2079 | 2080 | ((Book) rec.get(item_number)).set_m_rec_ebook_issue(true); 2081 | 2082 | ((Member) user_list.get(user_number)).addItems(rec.get(item_number)); 2083 | 2084 | ((Member) user_list.get(user_number)).setBalance(((Book) rec.get(item_number)).m_dis_ebook()); 2085 | 2086 | System.out.println(((Member) user_list.get(user_number)).getBalance()); 2087 | 2088 | find_recommendation(rec.get(item_number).getItem_id(),user_number);} 2089 | 2090 | else if (user_list.get(user_number)instanceof NonMember){ 2091 | 2092 | ((Book) rec.get(item_number)).set_nm_rec_ebook_issue(true); 2093 | 2094 | ((NonMember) user_list.get(user_number)).addItems(rec.get(item_number)); 2095 | 2096 | ((NonMember) user_list.get(user_number)).setBalance(((Book) rec.get(item_number)).nm_dis_ebook()); 2097 | 2098 | System.out.println(((NonMember) user_list.get(user_number)).getBalance()); 2099 | 2100 | find_recommendation(rec.get(item_number).getItem_id(),user_number);} 2101 | 2102 | return(rec.get(item_number)); 2103 | 2104 | } 2105 | 2106 | else{ 2107 | 2108 | System.out.println("Ebook not available"); 2109 | 2110 | } 2111 | 2112 | } 2113 | 2114 | } 2115 | 2116 | if(rec.get(item_number)instanceof Software){ 2117 | 2118 | System.out.println("Press 1 to buy the CD"+"\n"+"Press 2 to buy the Download of the software"); 2119 | 2120 | Scanner input =new Scanner (System.in); 2121 | 2122 | int buy=input.nextInt(); 2123 | 2124 | if(buy==1){ 2125 | 2126 | if(((Software) rec.get(item_number)).get_number_of_cd()>0){ 2127 | 2128 | System.out.println("found and added to cart"); 2129 | 2130 | ((Software) rec.get(item_number)).setCd_issue(true); 2131 | 2132 | ((Software) rec.get(item_number)).reduce_copies(); 2133 | 2134 | //user_balance=(int) (user_balance+((Software) rec.get(item_number)).get_cd_cost()); 2135 | 2136 | //System.out.println(user_balance); 2137 | 2138 | if (user_list.get(user_number)instanceof Member){ 2139 | 2140 | ((Software) rec.get(item_number)).set_m_rec_cd_issue(true); 2141 | 2142 | ((Member) user_list.get(user_number)).addItems(rec.get(item_number)); 2143 | 2144 | ((Member) user_list.get(user_number)).setBalance(((Software) rec.get(item_number)).m_dis_cd()); 2145 | 2146 | System.out.println(((Member) user_list.get(user_number)).getBalance()); 2147 | 2148 | find_recommendation(rec.get(item_number).getItem_id(),user_number);} 2149 | 2150 | else if (user_list.get(user_number)instanceof NonMember){ 2151 | 2152 | ((Software) rec.get(item_number)).set_nm_rec_cd_issue(true); 2153 | 2154 | ((NonMember) user_list.get(user_number)).addItems(rec.get(item_number)); 2155 | 2156 | ((NonMember) user_list.get(user_number)).setBalance(((Software) rec.get(item_number)).nm_dis_cd()); 2157 | 2158 | System.out.println(((NonMember) user_list.get(user_number)).getBalance()); 2159 | 2160 | find_recommendation(rec.get(item_number).getItem_id(),user_number);} 2161 | 2162 | return(rec.get(item_number)); 2163 | 2164 | } 2165 | 2166 | else{ 2167 | 2168 | System.out.println("No CD's available"); 2169 | 2170 | } 2171 | 2172 | } 2173 | 2174 | if(buy==2){ 2175 | 2176 | if(((Software) rec.get(item_number)).check_download_available()){ 2177 | 2178 | System.out.println("found and added to cart"); 2179 | 2180 | ((Software) rec.get(item_number)).set_download_issue(true); 2181 | 2182 | //user_balance=(int) (user_balance+((Software) rec.get(item_number)).get_download_cost()); 2183 | 2184 | if (user_list.get(user_number)instanceof Member){ 2185 | 2186 | ((Software) rec.get(item_number)).set_m_rec_down_issue(true); 2187 | 2188 | ((Member) user_list.get(user_number)).addItems(rec.get(item_number)); 2189 | 2190 | ((Member) user_list.get(user_number)).setBalance(((Software)rec.get(item_number)).m_dis_down()); 2191 | 2192 | //System.out.println(((Member) user_list.get(user_number)).getBalance()); 2193 | 2194 | find_recommendation(rec.get(item_number).getItem_id(),user_number);} 2195 | 2196 | else if (user_list.get(user_number)instanceof NonMember){ 2197 | 2198 | ((Software) rec.get(item_number)).set_nm_rec_down_issue(true); 2199 | 2200 | ((NonMember) user_list.get(user_number)).addItems(rec.get(item_number)); 2201 | 2202 | ((NonMember) user_list.get(user_number)).setBalance(((Software) rec.get(item_number)).nm_dis_down()); 2203 | 2204 | //System.out.println(((NonMember) user_list.get(user_number)).getBalance()); 2205 | 2206 | find_recommendation(rec.get(item_number).getItem_id(),user_number);} 2207 | 2208 | System.out.println(user_balance); 2209 | 2210 | return(rec.get(item_number)); 2211 | 2212 | } 2213 | 2214 | else{ 2215 | 2216 | System.out.println("Not available for download"); 2217 | 2218 | } 2219 | 2220 | } 2221 | 2222 | } 2223 | 2224 | return null; 2225 | 2226 | } 2227 | 2228 | } 2229 | 2230 | 2231 | 2232 | 2233 | 2234 | 2235 | 2236 | -------------------------------------------------------------------------------- /src/partc/User.java: -------------------------------------------------------------------------------- 1 | //package partc; 2 | 3 | public class User { 4 | private String id; 5 | private String password; 6 | private String name; 7 | private String email; 8 | private double balance=0; 9 | 10 | private int type; 11 | 12 | User(String id,String password,String name,String email){ 13 | this.setId(id); 14 | this.setPassword(password); 15 | this.setName(name); 16 | this.setEmail(email); 17 | } 18 | 19 | public User() { 20 | // TODO Auto-generated constructor stub 21 | } 22 | 23 | public String getId() { 24 | return id; 25 | } 26 | 27 | public void setId(String id) { 28 | this.id = id; 29 | } 30 | 31 | public String getPassword() { 32 | return password; 33 | } 34 | 35 | public void setPassword(String password) { 36 | this.password = password; 37 | } 38 | 39 | public String getName() { 40 | return name; 41 | } 42 | 43 | public void setName(String name) { 44 | this.name = name; 45 | } 46 | 47 | public String getEmail() { 48 | return email; 49 | } 50 | 51 | public void setEmail(String email) { 52 | this.email = email; 53 | } 54 | 55 | 56 | public double getBalance() { 57 | return balance; 58 | } 59 | 60 | public void setBalance(double balance) { 61 | this.balance =this.balance+ balance; 62 | } 63 | 64 | public void show_my_balance(){ 65 | System.out.println("Your current balance is "+balance); 66 | } 67 | 68 | 69 | 70 | } 71 | --------------------------------------------------------------------------------