From 87d6f5f30e76b12dd85ca394e1d2929a2caaec3d Mon Sep 17 00:00:00 2001 From: Sphoorthi-G Date: Mon, 13 Feb 2017 17:43:25 -0600 Subject: [PATCH] Implemented Interactive client and still working on pushing books to students --- src/com/sphoorthi/LibraryManagement/Book.java | 41 ++++++++++ .../sphoorthi/LibraryManagement/Client.java | 77 ++++++++++++++++++ .../sphoorthi/LibraryManagement/Student.java | 79 +++++++++++++++++++ 3 files changed, 197 insertions(+) create mode 100644 src/com/sphoorthi/LibraryManagement/Book.java create mode 100644 src/com/sphoorthi/LibraryManagement/Client.java create mode 100644 src/com/sphoorthi/LibraryManagement/Student.java diff --git a/src/com/sphoorthi/LibraryManagement/Book.java b/src/com/sphoorthi/LibraryManagement/Book.java new file mode 100644 index 0000000..1adaaa5 --- /dev/null +++ b/src/com/sphoorthi/LibraryManagement/Book.java @@ -0,0 +1,41 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package LibraryManagement; + +import java.util.*; + +/** + * + * @author Sphoorthi Gaddam + */ +public class Book { + Set books = new HashSet(); + + public Book() { + books.add("Java Script"); + books.add("Java"); + books.add("J2EE"); + books.add("Let us C"); + books.add("Selenium"); + books.add("Database"); + } + + public void listOfBooks(){ + Iterator it = books.iterator(); + int i = 1; + while(it.hasNext()){ + System.out.println("A"+i+" "+it.next()); + i++; + } + + } + + + + + + +} diff --git a/src/com/sphoorthi/LibraryManagement/Client.java b/src/com/sphoorthi/LibraryManagement/Client.java new file mode 100644 index 0000000..359e8a6 --- /dev/null +++ b/src/com/sphoorthi/LibraryManagement/Client.java @@ -0,0 +1,77 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package LibraryManagement; + +import java.util.*; + +/** + * + * @author Sphoorthi Gaddam + */ +public class Client { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + Book book; + Student student; + book = new Book(); + student = new Student(); + + String entry = ""; + System.out.println("Enter y or Y to continue or any key to exit to continue"); + entry = scan.next(); + if (!(entry.equals("y")) || (entry.equals("Y"))) { + System.out.println("Thank you, Bye!"); + } + + while ((entry.equals("y")) || (entry.equals("Y"))) { + + System.out.println("List of Students"); + student.listOfStudents(); + String name = ""; + + System.out.println("Choose Student"); + int choice = scan.nextInt(); + switch (choice) { + case 1: + name = "Sphoorthi"; + student.assignBook(name); + student.printAssignedBooks(); + break; + case 2: + name = "Malathi"; + student.assignBook(name); + student.printAssignedBooks(); + break; + case 3: + name = "Surender"; + student.assignBook(name); + student.printAssignedBooks(); + break; + case 4: + name = "Sreenidhi"; + student.assignBook(name); + student.printAssignedBooks(); + break; + default: + System.out.println("Please select the students from the list"); + break; + + } + System.out.println("Enter y or Y to continue or any key to exit to continue"); + entry = scan.next(); + if (!(entry.equals("y")) || (entry.equals("Y"))) { + System.out.println("Thank you, Bye!"); + } + + } + + } + +} diff --git a/src/com/sphoorthi/LibraryManagement/Student.java b/src/com/sphoorthi/LibraryManagement/Student.java new file mode 100644 index 0000000..c539f0f --- /dev/null +++ b/src/com/sphoorthi/LibraryManagement/Student.java @@ -0,0 +1,79 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package LibraryManagement; + +import java.util.*; + +/** + * + * @author Sphoorthi Gaddam + */ +public class Student { + + Map students = new HashMap(); + Book book = new Book(); + Scanner sc = new Scanner(System.in); + + public Student() { + students.put("Sphoorthi", ""); + students.put("Surender", ""); + students.put("Malathi", ""); + students.put("Sreenidhi", ""); + + } + + public void listOfStudents() { + + Iterator it = students.keySet().iterator(); + int i = 1; + while (it.hasNext()) { + System.out.println(i + " " + it.next()); + i++; + } + + } + + public void assignBook(String name) { + System.out.println("List of Books"); + book.listOfBooks(); + String bookChoice; + System.out.println("Choose Book to be assigned to "+name); + bookChoice = sc.next(); + switch (bookChoice) { + case "A1": + students.put(name, "Java"); + break; + case "A2": + students.put(name, "Java Script"); + break; + case "A3": + students.put(name, "Database"); + break; + case "A4": + students.put(name, "J2EE"); + break; + case "A5": + students.put(name, "Selenium"); + break; + case "A6": + students.put(name, "Let us C"); + break; + default: + System.out.println("Please select books from the list"); + break; + } + + } + + public void printAssignedBooks(){ + System.out.println("********Books Assigned********"); + Iterator it = students.entrySet().iterator(); + while (it.hasNext()) { + System.out.println(it.next()); + } + } + +}