










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Java Programming languagelhgnykludluduld
Typology: Exercises
1 / 18
This page cannot be seen from the preview
Don't miss anything!
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Scanner;
public class LMSImpl {
static List
public static void main(String[] args) { addIssueDetails(); System.out.println("Library Management System"); System.out.println("Press 1 to add Book"); System.out.println("Press 2 to issue a book");
System.out.println("Press 3 to return a book"); System.out.println("Press 4 to print the book details"); System.out.println("Press 5 to print complete issue detais"); System.out.println("Press 6 to exit"); Scanner c = new Scanner(System.in); int choice = c.nextInt(); do { switch (choice) { case 1: addBook(); break; case 2: issueBook(); break; case 3: returnBook(); break; case 4: printBookDetails();
for (BookIssueDetails b : entry.getValue()) { System.out.println(entry.getKey() + " " + b.getBookNumber()
private static void printBookDetails() { for (BookDetails b : books) { System.out.print(b.getBookNumber() + " " + b.getBookName() + " "
private static void returnBook() { System.out.println("Enter studentId & bookId"); Scanner c = new Scanner(System.in); int id = c.nextInt();
int bookId = c.nextInt(); List
long diff = todayDate.getTime() - issueDate.getTime();
long diffDays = diff / (24 * 60 * 60 * 1000);
if (diffDays > 10) { int fine = (int) (diffDays - 10); fine = fine * 10; System.out.println("Total Fine " + fine + " Rs."); } } }
hm.put(104, list4);
}
private static void issueBook() { System.out.println("Enter Student Id,Booknumber, name and price"); Scanner c = new Scanner(System.in); int studentId = c.nextInt(); Scanner c1 = new Scanner(System.in); int bookNumber = c1.nextInt(); Scanner c2 = new Scanner(System.in); String name = c2.nextLine(); Scanner c3 = new Scanner(System.in); String issueDate = c3.nextLine(); BookIssueDetails newIssuedBook = new BookIssueDetails(); newIssuedBook.setName(name); newIssuedBook.setBookNumer(bookNumber);
ArrayList
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
try {
Date date = formatter.parse(issueDate); newIssuedBook.setIssueDate(date);
} catch (ParseException e) { e.printStackTrace(); }
List
package com.lms;
import java.util.Date;
public class BookIssueDetails {
private int bookNumber; private String name; private int totalBookAllowed = 2; private int noOfBookIssued=0; private Date issueDate; private Date returnDate;
public BookIssueDetails(int bookNumber,String name,int n,Date issueDate) {
this.bookNumber=bookNumber; this.name=name; this.noOfBookIssued=n; this.issueDate=issueDate; }
public BookIssueDetails() { }
public int getBookNumber() { return bookNumber; }
public void setBookNumer(int bookNumber) { this.bookNumber = bookNumber; }
public int getNoOfBookIssued() { return noOfBookIssued;
this.returnDate = returnDate; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public int getTotalBookAllowed() { return totalBookAllowed; }
public void setTotalBookAllowed(int totalBookAllowed) { this.totalBookAllowed = totalBookAllowed; }
package com.lms;
public class BookDetails { private int bookNumber; private String bookName; private Double price; private int count;
public BookDetails(int bookNumber,String name,Double price) { this.bookNumber=bookNumber; this.bookName=name; this.price=price;
public void setBookName(String bookName) { this.bookName = bookName; }
public Double getPrice() { return price; }
public void setPrice(Double price) { this.price = price; } }
package com.lms;
public class StudentDetails {
private int studentId; private String studentName; private String className;
public int getStudentId() { return studentId; }
public void setStudentId(int studentId) { this.studentId = studentId; }
public String getStudentName() { return studentName; }
public void setStudentName(String studentName) { this.studentName = studentName; }