[go: up one dir, main page]

0% found this document useful (0 votes)
33 views3 pages

Book Class With Getters Setters

Uploaded by

Devil Lucifer
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)
33 views3 pages

Book Class With Getters Setters

Uploaded by

Devil Lucifer
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/ 3

import java.io.

*;

class Book
{
private String memberName;
private int isbn;
private String bookName;
private int price;
private String bookAuthor;
private String publication;

Book() //Default/Empty Constructor


{
this.memberName = null;
this.isbn = 0;
this.bookName = null;
this.price = 0;
this.bookAuthor = null;
this.publication = null;
}

Book(String memberName,int isbn,String bookName,int price,String bookAuthor,String publication)


{ //Parameterised Constructor
this.memberName = memberName;
this.isbn = isbn;
this.bookName = bookName;
this.price = price;
this.bookAuthor = bookAuthor;
this.publication = publication;
}

void display() //Display Method Only Using For Constructors


{
System.out.println("Member Name :" + this.memberName);
System.out.println("Book ISBN :" + this.isbn);
System.out.println("Book Name :" + this.bookName);
System.out.println("Book Price :" + this.price);
System.out.println("Book Author :" + this.bookAuthor);
System.out.println("Book Publication :" + this.publication);
System.out.println("========================================");
}

// All Setter Methods

public void setMemberName(String memberName)


{
this.memberName = memberName;
}

public void setIsbn(int isbn)


{
this.isbn = isbn;
}

public void setBookName(String bookName)


{
this.bookName = bookName;
}

public void setPrice(int price)


{
this.price = price;
}

public void setBookAuthor(String bookAuthor)


{
this.bookAuthor = bookAuthor;
}

public void setPublication(String publication)


{
this.publication = publication;
}

//All Getter Methods

public String getMemberName()


{
return memberName;
}

public int getIsbn()


{
return isbn;
}

public String getBookName()


{
return bookName;
}

public int getPrice()


{
return price;
}

public String getBookAuthor()


{
return bookAuthor;
}

public String getPublication()


{
return publication;
}
};

public class Book_Class_With_Getters_Setters


{
public static void main(String args[])
{
Book b1 = new Book();
b1.display();
Book b2 = new Book("HARI",4567,"HEAD FIRST C",456,"Harry. H. Chaudhary","O\'REILY");
b2.display(); //Calling using Parameterised Constructor , Using Display Methods

System.out.println("Member Name :" + b2.getMemberName());


System.out.println("Book ISBN :" + b2.getIsbn());
System.out.println("Book Name :" + b2.getBookName()); // Using Getters to print values for Object "b2"
System.out.println("Book Price :" + b2.getPrice());
System.out.println("Book Author :" + b2.getBookAuthor());
System.out.println("Book Publication :" + b2.getPublication());
System.out.println("========================================");

b1.setMemberName("SHIVAM");
b1.setIsbn(45699);
b1.setBookName("DataStructure And Algorithm Made Easy"); //Setting Values Using Setters For Object "b1"
b1.setPrice(500);
b1.setBookAuthor("Narsimha Karumanchi");
b1.setPublication("Career Monk");

System.out.println("Member Name :" + b1.getMemberName());


System.out.println("Book ISBN :" + b1.getIsbn());
System.out.println("Book Name :" + b1.getBookName()); // Using Getters to print the values For Object "b1"
System.out.println("Book Price :" + b1.getPrice());
System.out.println("Book Author :" + b1.getBookAuthor());
System.out.println("Book Publication :" + b1.getPublication());
System.out.println("========================================");

}
}

You might also like