Advertisement
Guest User

Untitled

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