Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Java analysis, Exercises of Javascript programming

Java Programming languagelhgnykludluduld

Typology: Exercises

2017/2018

Uploaded on 10/22/2018

shekhar-rakhe
shekhar-rakhe 🇮🇳

1 document

1 / 18

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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<BookDetails> books = new ArrayList<BookDetails>();
static Map<Integer, ArrayList<BookIssueDetails>> hm = new HashMap<Integer, ArrayList<BookIssueDetails>>
();
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");
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download Java analysis and more Exercises Javascript programming in PDF only on Docsity!

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 books = new ArrayList(); static Map<Integer, ArrayList> hm = new HashMap<Integer, ArrayList> ();

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()

  • " " + b.getName() + " " + b.getNoOfBookIssued()
  • " " + b.getIssueDate() + " " + b.getReturnDate()); } } }

private static void printBookDetails() { for (BookDetails b : books) { System.out.print(b.getBookNumber() + " " + b.getBookName() + " "

  • b.getCount() + " " + b.getPrice()); } }

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 bd = hm.get(id); for (BookIssueDetails b : bd) { if (b.getBookNumber() == bookId) { Date issueDate = b.getIssueDate(); Date todayDate = new Date();

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 l=new ArrayList();

SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");

try {

Date date = formatter.parse(issueDate); newIssuedBook.setIssueDate(date);

} catch (ParseException e) { e.printStackTrace(); }

List list = hm.get(studentId); for (BookIssueDetails b : list) { int value = b.getNoOfBookIssued(); newIssuedBook.setNoOfBookIssued(++value); l.add(newIssuedBook);

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