-
Notifications
You must be signed in to change notification settings - Fork 4
Implemented Interactive client and still working on pushing books to … #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<String> books = new HashSet<String>(); | ||
|
|
||
| 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++; | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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(); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can do it Book 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!"); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<String, String> students = new HashMap<String, String>(); | ||
| Book book = new Book(); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might not be required here since each time a student object is created, it will call book constructor and would create redundant / duplicate books. |
||
| 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()); | ||
| } | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since book is the domain object it should have it property called as name which could be string.