0% found this document useful (0 votes)
13 views

Assignment 8 Backup

The document defines a Library class with methods to add/remove reading materials and members, and issue/return reading materials to members. It defines subclasses for different reading material types and a Member class. The LibraryTest class demonstrates using the Library class by adding sample data and calling its methods.

Uploaded by

srivastavanetra3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Assignment 8 Backup

The document defines a Library class with methods to add/remove reading materials and members, and issue/return reading materials to members. It defines subclasses for different reading material types and a Member class. The LibraryTest class demonstrates using the Library class by adding sample data and calling its methods.

Uploaded by

srivastavanetra3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

ppackage logic;

import java.util.*;
public class Library {
HashSet<RM> rms=new HashSet<>();
HashSet<Member> members=new HashSet<>();

public void add_rm(RM r)


{
rms.add(r);
}
public void remove_rm(RM r)
{
rms.remove(r);
}
public void add_m(Member m)
{
members.add(m);
}
public void display_rm_library()
{
System.out.println("Reading material in Library:");
for(RM r: rms)
{
r.display();
}
System.out.println("----------------");
}
public void display_member_library(){
System.out.println("Members enrolled in Library:");
for(Member m: members)
{
System.out.println("Name of member:"+m.getName());
}
System.out.println("----------------");
}
public void issue(RM r,Member m)
{
if(rms.contains(r)){
int count=0;
for(int i=0;i<m.rmsm.size();i++)
{
count++;
}
if(count<3){
remove_rm(r);
m.add_rm_member(r);
}
else{
System.out.println("More reading material cannot be issued");
}
}
else{
System.out.println("Reading material is not avaiable , cannot be issued");
}
}
public void return_rm(RM r,Member m)
{
add_rm(r);
m.remove_rm_member(r);

}
}

package logic;

public class RM {
String title;
double price;
public RM(String title,double price)
{
this.title=title;
this.price=price;
}
public void display()
{

}
}

package logic;

public class Book extends RM {


String ISBN;
public Book(String title,double price, String ISBN)
{
super(title,price);
this.ISBN=ISBN;
}
public void display()
{
System.out.println("Book:"+title);
System.out.println("Price:"+price);
System.out.println("ISBN:"+ISBN);
}
}

package logic;

public class Magazine extends RM{


String month;
public Magazine(String title,double price, String month)
{
super(title,price);
this.month=month;
}
public void display()
{
System.out.println("Magazine:"+title);
System.out.println("Price:"+price);
System.out.println("Month of issue:"+month);
}
}

package logic;

public class CD extends RM {


int dim;
public CD(String title,double price, int dim)
{
super(title,price);
this.dim=dim;
}
public void display()
{
System.out.println("CD:"+title);
System.out.println("Price:"+price);
System.out.println("Duration in minutes:"+dim);
}
}

package logic;

import java.util.HashSet;

public class Member {


String name;
HashSet<RM> rmsm=new HashSet<>();

public String getName() {


return name;
}
public void setName(String name) {
this.name = name;
}
public Member(String name)
{
this.name=name;
}
public void add_rm_member(RM r)
{

rmsm.add(r);

}
public void remove_rm_member(RM r)
{
rmsm.remove(r);

}
public void display()
{
System.out.println("Name of member:"+name);

if(rmsm.isEmpty()){
System.out.println(" No Reading material issued");
}
else{
System.out.println("Reading material issued:");
for(RM m: rmsm)
{
m.display();
}
}
System.out.println("--------------");
}
}

package client;
import logic.*;
public class LibraryTest {
public static void main(String args[])
{
RM b1=new Book("Alice in Wonderland", 450.00,"1234568921");
RM b2=new Book("Wizard of Oz", 350.00,"12678568921");
RM m1=new Magazine("Vogue",300.00,"January");
RM m2=new Magazine("Glamour",200.00,"November");
RM c1=new CD("Humanity",50.00,30);
RM c2=new CD("DBMS",150.00,40);
Member mem1=new Member("Hermoine Granger");
Member mem2=new Member("Petta Melark");
Library l=new Library();
l.add_rm(b1);
l.add_rm(b2);
l.add_rm(m1);
l.add_rm(m2);
l.add_rm(c1);
l.add_rm(c2);
l.add_m(mem1);
l.add_m(mem2);

l.display_rm_library();
l.display_member_library();
l.issue(b1, mem1);
l.issue(m2, mem1);
l.issue(c1,mem2);
l.issue(m1,mem2);
mem1.display();
mem2.display();
System.out.println("After issueng");
l.display_rm_library();
l.return_rm(b1, mem1);
System.out.println("After returning");
l.display_rm_library();
mem1.display();
}
}

Reading material in Library:


Book:Alice in Wonderland
Price:450.0
ISBN:1234568921
Book:Wizard of Oz
Price:350.0
ISBN:12678568921
Magazine:Glamour
Price:200.0
Month of issue:November
Magazine:Vogue
Price:300.0
Month of issue:January
CD:Humanity
Price:50.0
Duration in minutes:30
CD:DBMS
Price:150.0
Duration in minutes:40
----------------
Members enrolled in Library:
Name of member:Petta Melark
Name of member:Hermoine Granger
----------------
Reading material is not avaiable , cannot be issued
Name of member:Hermoine Granger
Reading material issued:
Book:Alice in Wonderland
Price:450.0
ISBN:1234568921
Magazine:Glamour
Price:200.0
Month of issue:November
Magazine:Vogue
Price:300.0
Month of issue:January
--------------
Name of member:Petta Melark
No Reading material issued
--------------
After issueng
Reading material in Library:
Book:Wizard of Oz
Price:350.0
ISBN:12678568921
CD:Humanity
Price:50.0
Duration in minutes:30
CD:DBMS
Price:150.0
Duration in minutes:40
----------------
After returning
Reading material in Library:
Book:Wizard of Oz
Price:350.0
ISBN:12678568921
Book:Alice in Wonderland
Price:450.0
ISBN:1234568921
CD:Humanity
Price:50.0
Duration in minutes:30
CD:DBMS
Price:150.0
Duration in minutes:40
----------------
Name of member:Hermoine Granger
Reading material issued:
Magazine:Glamour
Price:200.0
Month of issue:November
Magazine:Vogue
Price:300.0
Month of issue:January
--------------

You might also like