Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Computer Science question Don't answer using chatgpt it's a totally wrong I will dislike you with my multiple uk friends Account guys so provide me
Computer Science question
Don't answer using chatgpt it's a totally wrong I will dislike you with my multiple uk friends Account guys so provide me correct solution for this question.no copy paste pls
Computer Science
import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;
class Book
private String title;
private String author;
private String isbn;
private boolean isIssued;
public BookString title, String author, String isbn
this.title title;
this.author author;
this.isbn isbn;
this.isIssued false;
public String getTitle
return title;
public String getAuthor
return author;
public String getIsbn
return isbn;
public boolean isIssued
return isIssued;
public void issueBook
isIssued true;
public void returnBook
isIssued false;
class Member
private String name;
private String memberId;
private ArrayList issuedBooks;
public MemberString name, String memberId
this.name name;
this.memberId memberId;
this.issuedBooks new ArrayList;
public String getName
return name;
public String getMemberId
return memberId;
public ArrayList getIssuedBooks
return issuedBooks;
public void issueBookBook book
if book.isIssued
book.issueBook;
issuedBooks.addbook;
System.out.printlnBook issued successfully to name;
else
System.out.printlnBook is already issued.";
public void returnBookBook book
if issuedBookscontainsbook
book.returnBook;
issuedBooks.removebook;
System.out.printlnBook returned successfully by name;
else
System.out.printlnThis book is not issued to this member.";
class Transaction
private Member member;
private Book book;
private Date issueDate;
private Date returnDate;
public TransactionMember member, Book book, Date issueDate, Date returnDate
this.member member;
this.book book;
this.issueDate issueDate;
this.returnDate returnDate;
public Member getMember
return member;
public Book getBook
return book;
public Date getIssueDate
return issueDate;
public Date getReturnDate
return returnDate;
public class LibraryManagementSystem
private ArrayList books;
private ArrayList members;
private ArrayList transactions;
public LibraryManagementSystem
books new ArrayList;
members new ArrayList;
transactions new ArrayList;
public void addBookBook book
books.addbook;
System.out.printlnBook added successfully.";
public void addMemberMember member
members.addmember;
System.out.printlnMember added successfully.";
public Book findBookByIsbnString isbn
for Book book : books
if bookgetIsbnequalsisbn
return book;
return null;
public Member findMemberByIdString memberId
for Member member : members
if membergetMemberIdequalsmemberId
return member;
return null;
public void issueBookString memberId, String isbn
Member member findMemberByIdmemberId;
Book book findBookByIsbnisbn;
if member null && book null
member.issueBookbook;
transactions.addnew Transactionmember book, new Date null;
else
System.out.printlnInvalid member ID or book ISBN.";
public void returnBookString memberId, String isbn
Member member findMemberByIdmemberId;
Book book findBookByIsbnisbn;
if member null && book null
member.returnBookbook;
for Transaction transaction : transactions
if transactiongetMemberequalsmember && transaction.getBookequalsbook && transaction.getReturnDate null
transaction new Transactionmember book, transaction.getIssueDate new Date;
break;
else
System.out.printlnInvalid member ID or book ISBN.";
public void showAllBooks
for Book book : books
System.out.printlnTitle: book.getTitle Author: book.getAuthor ISBN: book.getIsbn Issued: book.isIssued;
public void showAllMembers
for Member member : members
System.out.printlnName: member.getName Member ID: member.getMemberId;
public void showTransactions
for Transaction transaction : transactions
System.out.printlnMember: transaction.getMembergetName Book: transaction.getBookgetTitle Issue Date: transaction.getIssueDate Return Date: transactiongetReturnDate null transaction.getReturnDate : "Not Returned";
public static void mainString args
LibraryManagementSystem library new LibraryManagementSystem;
Scanner scanner new ScannerSystemin;
int choice;
do
System.out.println
Library Management System";
System.out.println Add Book";
System.out.println Add Member";
System.out.println Issue Book";
System.out.println Return Book";
System.out.println Show All Books";
System.out.println Show All Members";
System.out.println Show Transactions";
System.out.println Exit";
System.out.printEnter your choice: ;
choice scanner.nextInt;
switch choice
case :
System.out.printEnter book title: ;
scanner.nextLine;
String title scanner.nextLine;
System.out.printEnter book author: ;
String author scanner.nextLine;
System.out.printEnter book ISBN: ;
String isbn scanner.nextLine;
library.addBooknew Booktitle author, isbn;
break;
case :
System.out.printEnter member name: ;
scanner.nextLine;
String name scanner.nextLine;
System.out.printEnter member ID: ;
String memberId scanner.nextLine;
library.addMembernew Membername memberId;
break;
case :
System.out.printEnter member ID: ;
scanner.nextLine;
memberId scanner.nextLine;
System.out.printEnter book ISBN: ;
isbn scanner.nextLine;
library.issueBookmemberId isbn;
break;
case :
System.out.printEnter member ID: ;
scanner.nextLine;
memberId scanner.nextLine;
System.out.printEnter book ISBN: ;
isbn scanner.nextLine;
library.returnBookmemberId isbn;
break;
case :
library.showAllBooks;
break;
case :
library.showAllMembers;
break;
case :
library.showTransactions;
break;
case :
System.out.printlnExiting the system.";
break;
default:
System.out.printlnInvalid choice. Please try again.";
while choice ;
scanner.close;
Classes
Book Class
Attributes:
title: The title of the book.
author: The author of the book.
isbn: The International Standard Book Number of the book.
isIssued: A boolean indicating whether the book is issued.
Methods:
getTitle getAuthor getIsbn isIssued: Getters for the attributes.
issueBook: Sets isIssued to true.
returnBook: Sets isIssued to false.
Member Class
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started