Advertisement
Guest User

Untitled

a guest
Jun 13th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.71 KB | None | 0 0
  1. Tester Class
  2. ---------------------------------------------------------------------------------------------
  3.  
  4. import java.util.*;
  5. public class Tester {
  6.  
  7. public static void studentOptions(Students users){
  8. Library lib=new Library();
  9. Scanner test=new Scanner(System.in);
  10. boolean leave = false;
  11. do {
  12. System.out.println("Press 1 Check out");
  13. System.out.println("Press 2: Return");
  14. System.out.println("Press 3:Compare");
  15. System.out.println("Press 4: Log out");
  16.  
  17. int choice =test.nextInt();
  18. switch (choice) {
  19. case 1:
  20. lib.checkout(users);
  21. break;
  22. case 2:
  23. users.returnBooks();
  24. break;
  25. case 3:
  26. lib.compare_books();
  27. break;
  28. case 4:
  29. leave = true;
  30. break;
  31. }
  32. } while (leave == false);
  33. }
  34. public static void adminOptions(){
  35. Library lib=new Library();
  36. Scanner test=new Scanner(System.in);
  37. boolean leave = false;
  38. do {
  39. System.out.println("Press 1 to list all students");
  40. System.out.println("Press 2: To add a student");
  41. System.out.println("Press 3: To remove a student");
  42. System.out.println("Press 4: To search for a student");
  43. System.out.println("Press 5: to add a book");
  44. System.out.println("Press 6: to remove for a book");
  45. System.out.println("Press 7: to search a book");
  46. System.out.println("Press 8: Checkout a book");
  47. System.out.println("Press 9: Return a book");
  48. System.out.println("Press 10 to Compare Books");
  49. System.out.println("Press 11: to Go to Menu");
  50. int choice =test.nextInt();
  51. switch (choice) {
  52. case 1:
  53. lib.liststudents();
  54. break;
  55. case 2:
  56. lib.add_students();
  57. break;
  58. case 3:
  59. System.out.println("Enter Student Number: ");
  60. Scanner scan=new Scanner(System.in);
  61. int search= scan.nextInt();
  62. lib.removestudents(search);
  63. break;
  64. case 4:
  65. lib.search_students();
  66. break;
  67. case 5:
  68. lib.add_books();
  69. break;
  70. case 6:
  71. lib.remove_books();
  72. break;
  73. case 7:
  74. lib.search_books();
  75. break;
  76. case 8:
  77. lib.checkout(null);
  78. break;
  79. case 9:
  80. lib.getBookBack(null);
  81. break;
  82. case 10:
  83. lib.compare_books();
  84. case 11:
  85. leave = true;
  86. break;
  87. }
  88. } while (leave == false);
  89. }
  90.  
  91.  
  92. public static void main(String[] args) {
  93. Students user = null;
  94. Library lib=new Library();
  95. Scanner test=new Scanner(System.in);
  96. boolean loop = true;
  97.  
  98. while(loop){
  99. System.out.println("Bramalea Secondary School Library");
  100. System.out.println("Press 1: Student Login");
  101. System.out.println("Press 2: Admin Login");
  102. int x= test.nextInt();
  103. switch (x) {
  104. case 1:
  105. System.out.println("Enter student number: ");
  106. int num = test.nextInt();
  107. boolean isUser = false;
  108. for (int counter = 0; counter < Library.students.size(); counter++){
  109. if (Library.students.get(counter).getstudentid() == num){
  110. isUser = true;
  111. break;
  112. }
  113. }
  114. if (isUser == true){
  115. user = lib.search_studentsPlus(num);
  116. System.out.println("Hello, Student ");
  117. studentOptions(user);
  118. } else {
  119. System.out.println("Not Student");
  120. }
  121.  
  122.  
  123.  
  124. break;
  125. case 2:
  126. String password = "";
  127. boolean firstTime =false;
  128. do{
  129. if (firstTime == false){
  130. System.out.println("Status: Librarian");
  131. System.out.println("please enter your admin password: ");
  132. password=test.next();
  133. firstTime = true;
  134. adminOptions();
  135. } else {
  136. System.out.println("Incorrect the Password");
  137. System.out.println("please enter the password");
  138. password=test.next();
  139. }
  140. } while (!password.matches("admin"));
  141. }
  142. }
  143.  
  144. }
  145. }
  146.  
  147. ---------------------------------------------------------------------------------------------------------------------------------------Books Class
  148. ---------------------------------------------------------------------------------------------------------------------------------------
  149. public class Books {
  150.  
  151. private String title;
  152. private String author;
  153. private int ISBN;
  154. private String category;
  155. private double cost;
  156. private double rating;
  157.  
  158. public Books (String titleofbook, String person, int ISBNnum, String genre, double costofbook, double starrating){
  159. title=titleofbook;
  160. author=person;
  161. ISBN= ISBNnum;
  162. category=genre;
  163. cost=costofbook;
  164. rating=starrating;
  165. }
  166. public String getAuthor() {
  167. return author;
  168. }
  169. public String getCategory() {
  170. return category;
  171. }
  172. public double getCost() {
  173. return cost;
  174. }
  175. public int getISBN() {
  176. return ISBN;
  177. }
  178. public double getrating() {
  179. return rating;
  180. }
  181. public String getTitle(){
  182. return title;
  183. }
  184.  
  185. }
  186.  
  187. ---------------------------------------------------------------------------------------------------------------------------------------Library Class
  188. ---------------------------------------------------------------------------------------------------------------------------------------
  189.  
  190. import java.util.*;
  191. import java.text.SimpleDateFormat;
  192.  
  193.  
  194. public class Library {
  195. public ArrayList<Books> books=new ArrayList<Books>();
  196. public static ArrayList<Students> students=new ArrayList<Students>();
  197.  
  198. public void add_students() {
  199.  
  200. Scanner scan=new Scanner(System.in);
  201.  
  202. System.out.println("How many students would you like to add: ");
  203. int numofstudents=scan.nextInt();
  204. for(int i=0;i<numofstudents;i++)
  205. {
  206.  
  207. System.out.println("Enter first name");
  208. String firstname=scan.next();
  209. System.out.println("Enter last name");
  210. String lastname=scan.next();
  211. System.out.println("Enter student number");
  212. int studentNum=scan.nextInt();
  213. students.add((new Students(firstname, lastname, studentNum,0)));
  214. }
  215. }
  216. public void add_books() {
  217.  
  218. Scanner scan=new Scanner(System.in);
  219.  
  220. System.out.println("How many books would you like to add: ");
  221. int numofstudents=scan.nextInt();
  222. int m ;
  223. for(int i=0;i<numofstudents;i++)
  224.  
  225. {
  226. m = i+1;
  227. System.out.println("For the "+m+" book");
  228. scan.nextLine();
  229. System.out.println("Enter book's name");
  230. String bookname=scan.nextLine();
  231. System.out.println("Enter the Author's Name");
  232. String authorname=scan.nextLine();
  233. System.out.println("Enter the ISBN number");
  234. int ISBN=scan.nextInt();
  235. scan.nextLine();
  236. System.out.println("Please Enter the Genre of the book");
  237. String category=scan.nextLine();
  238. System.out.println("Please Enter the cost of the book");
  239. double cost=scan.nextDouble();
  240. System.out.println("Please Enter the Rating of the the book");
  241. double rating =scan.nextDouble();
  242. books.add((new Books(bookname, authorname, ISBN,category,cost, rating )));
  243. }
  244. }
  245. public void search_books() {
  246. {
  247. Scanner scan=new Scanner(System.in);
  248. System.out.println("Enter the ISBN of the book");
  249. int search= scan.nextInt();
  250. for(int i = 0;i<books.size();i++){
  251. if (books.get(i).getISBN()==search)
  252. {
  253. System.out.println("Title: "+books.get(i).getTitle());
  254. System.out.println("Author Name: "+books.get(i).getAuthor());
  255. System.out.println("Genre: "+books.get(i).getCategory());
  256. System.out.println("Cost: "+books.get(i).getCost());
  257. System.out.println("ISBN: "+books.get(i).getISBN());
  258. System.out.println("Stars: "+books.get(i).getrating());
  259. System.out.println("\n");
  260. }
  261.  
  262.  
  263. }
  264. }
  265. }
  266. public void liststudents(){
  267. System.out.println("Student List");
  268. System.out.println("______________________________");
  269. System.out.println(" ");
  270. for(Students x : students){
  271. System.out.println("First Name: "+x.getfirstname());
  272. System.out.println("Last Name "+x.getlastname());
  273. System.out.println("Student Number: "+x.getstudentid());
  274. System.out.println("Student Fines: "+x.getstudentfines());
  275. System.out.println("\n");;
  276. }
  277. }
  278. public void compare_books(){
  279. Scanner scan=new Scanner(System.in);
  280. System.out.println("Enter the ISBN of the first book");
  281. int searchkey= scan.nextInt();
  282. System.out.println("Enter the ISBN of the second");
  283. int searchkey2=scan.nextInt();
  284. for(int i = 0;i<books.size();i++){
  285. if (books.get(i).getISBN()==searchkey)
  286. {
  287.  
  288. System.out.println("Title: "+books.get(i).getTitle());
  289. System.out.println("Author: "+books.get(i).getAuthor());
  290. System.out.println("Category: "+books.get(i).getCategory());
  291. System.out.println("Cost(in CAD): "+books.get(i).getCost());
  292. System.out.println("ISBN: "+books.get(i).getISBN());
  293. System.out.println("Star rating"+books.get(i).getrating());
  294. }
  295. for(int j = 0;i<books.size();j++)
  296. if (books.get(i).getISBN()==searchkey2)
  297. {
  298. System.out.println("Title: "+books.get(i).getTitle());
  299. System.out.println("Author: "+books.get(i).getAuthor());
  300. System.out.println("Category: "+books.get(i).getCategory());
  301. System.out.println("Cost(in CAD): "+books.get(i).getCost());
  302. System.out.println("ISBN: "+books.get(i).getISBN());
  303.  
  304. System.out.println("Star rating"+books.get(i).getrating());
  305.  
  306. }
  307.  
  308. }
  309. }
  310. public void listbooks(){
  311. System.out.println("Book List");
  312. for(Books y: books){
  313. System.out.println("Title of the Book: "+y.getTitle());
  314. System.out.println("Author of the book: "+y.getAuthor());
  315. System.out.println("Genre of the Book"+y.getCategory());
  316. System.out.println("Cost of the book"+y.getCost());
  317. System.out.println("Rating of the book"+y.getrating());
  318. System.out.println("ISBN of the book: "+y.getISBN());
  319. System.out.println("\n");
  320. }
  321. }
  322. public void removestudents(int num) {
  323.  
  324. Scanner scan=new Scanner(System.in);
  325. for(int u = 0;u<students.size();u++){
  326. if (students.get(u).getstudentid() == num)
  327. {
  328. students.remove(u);
  329. }
  330.  
  331. }
  332. }
  333. public void remove_books(){
  334. Scanner scan=new Scanner(System.in);
  335. System.out.println("Enter the ISBN of the book");
  336. int isbnsearch= scan.nextInt();
  337. for(int i = 0;i<books.size();i++){
  338. if (books.get(i).getISBN()==isbnsearch)
  339. {
  340. System.out.println("Title: "+books.get(i).getTitle());
  341. System.out.println("Author: "+books.get(i).getAuthor());
  342. System.out.println("Genre: "+books.get(i).getCategory());
  343. System.out.println("Cost of book: "+books.get(i).getCost());
  344. System.out.println("Get Book ISBN: "+books.get(i).getISBN());
  345. System.out.println("Book Rating: "+books.get(i).getrating());
  346. System.out.println("Are you sure you want to remove this book? (Y)es/(N)o");
  347. String yes=scan.next();
  348. yes.toLowerCase();
  349. if(yes.matches("y")){
  350. books.remove(i);
  351. System.out.println("This book has been Removed");
  352. }
  353. else{
  354. System.out.println("This book has not been Removed");
  355. }
  356. }
  357. }
  358. }
  359. public void search_students() {
  360. {
  361. Scanner scan=new Scanner(System.in);
  362. System.out.println("Enter the Student Number: ");
  363. int search= scan.nextInt();
  364. for(int i = 0;i<students.size();i++){
  365. if (students.get(i).getstudentid()==search)
  366. {
  367. System.out.println("First Name: "+students.get(i).getfirstname());
  368. System.out.println("Last Name: "+students.get(i).getlastname());
  369. System.out.println("Student ID: "+students.get(i).getstudentid());
  370. System.out.println("OutStanding Fines: "+students.get(i).getstudentfines());
  371. System.out.println();
  372. System.out.println("\n");
  373. }
  374. }
  375. }
  376. }
  377.  
  378. public Students search_studentsPlus(int num) {
  379. Students s = null;
  380. for(int i = 0;i<students.size();i++){
  381. if (students.get(i).getstudentid()==num)
  382. {
  383. s = students.get(i);
  384. }
  385. }
  386. return(s);
  387. }
  388.  
  389. public void checkout(Students user) {
  390. Scanner input = new Scanner(System.in);
  391. int index = 0;
  392.  
  393. System.out.println("Please Enter the ISBN of the book");
  394. int search = input.nextInt();
  395. for(int i1 = 0;i1<books.size();i1++){
  396. if (books.get(i1).getISBN()==search)
  397. {
  398. index = i1;
  399. user.checkOut(books.get(i1));
  400. user.displayBooks();
  401. break;
  402. }
  403.  
  404. }
  405. books.remove(index);
  406. }
  407. public void getBookBack (Books b){
  408. books.add(b);
  409. }
  410.  
  411. }
  412.  
  413. ---------------------------------------------------------------------------------------------------------------------------------------Students Class
  414. ---------------------------------------------------------------------------------------------------------------------------------------
  415. import java.util.ArrayList;
  416. import java.util.Scanner;
  417.  
  418. public class Students extends Library {
  419.  
  420. private String firstname;
  421. private String lastname;
  422. private int studentid;
  423. private double studentfines;
  424. private ArrayList<Books> books = new ArrayList<Books>();
  425.  
  426. public Students(String firstnam, String lastnam, int id,double fines)
  427. {
  428. firstname=firstnam;
  429. lastname=lastnam;
  430. studentid=id;
  431. studentfines=fines;
  432. }
  433. public String getfirstname() {
  434. return firstname;
  435. }
  436. public String getlastname() {
  437. return lastname;
  438. }
  439. public int getstudentid() {
  440. return studentid;
  441. }
  442. public double getstudentfines() {
  443. return studentfines;
  444. }
  445. public void checkOut(Books book){
  446. books.add(book);
  447. }
  448. public void returnBooks(){
  449. Library lib=new Library();
  450. Scanner input=new Scanner(System.in);
  451. for(int i = 0; i < books.size(); i++){
  452. System.out.println("Press (" + i + ") to return: " + books.get(i).getTitle() + " by " + books.get(i).getAuthor());
  453. }
  454. int choice = input.nextInt();
  455. lib.getBookBack(books.get(choice));
  456. books.remove(choice);
  457. }
  458.  
  459. public void displayBooks(){
  460. System.out.println(firstname + lastname + "Student ID: " + studentid + " has: ");
  461. for(Books x : books){
  462. System.out.print(x.getTitle() + "\n");
  463. }
  464. }
  465.  
  466.  
  467. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement