Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/com/sphoorthi/LibraryManagement/Book.java
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>();
Copy link
Owner

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.


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++;
}

}






}
77 changes: 77 additions & 0 deletions src/com/sphoorthi/LibraryManagement/Client.java
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();
Copy link
Owner

Choose a reason for hiding this comment

The 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!");
}

}

}

}
79 changes: 79 additions & 0 deletions src/com/sphoorthi/LibraryManagement/Student.java
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();
Copy link
Owner

Choose a reason for hiding this comment

The 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());
}
}

}