Main Class:
package pkg3;
public class Main {
public static void main(String[] args)
{
Author author = new Author("Tamim Shahriar Subeen","book@subeen,.com","M");
Book book = new Book("Computer Programming",author,250,1000);
System.out.println("Name of the book: "+book.getName());
System.out.println("Name of the Author: "+book.getAuthor().getName());
System.out.println("Price of The Book: "+book.getPrice());
System.out.println("Available in Stock: "+book.getInStock());
}
}
Author Class:
package pkg3;
public class Author
{
private String name,email,gender;
Author(String name,String email,String gender)
{
this.name = name;
this.email=email;
this.gender = gender;
}
public void setName(String name)
{
this.name = name;
}
public void setEmail(String email)
{
this.email = email;
}
public void setGender(String gender)
{
this. gender= gender;
}
public String getName()
{
return name;
}
public String getEmail()
{
return email;
}
public String getGender()
{
return gender;
}
}
Book Class:
package pkg3;
public class Book
{
private Author a;
private String book_name;
private int price,total;
Book(String book_name,Author a,int price,int total)
{
this.book_name=book_name;
this.a=a;
this.price=price;
this.total=total;
}
public String getName()
{
return book_name;
}
public Author getAuthor()
{
return a;
}
public int getPrice()
{
return price;
}
public int getInStock()
{
return total;
}
public void setName(String book_name)
{
this.book_name=book_name;
}
public void setAuthor(Author a)
{
this.a=a;
}
public void setPrice(int price)
{
this.price =price;
}
public void setTotal(int total)
{
this.total=total;
}
}
Output
Name of the book:Computer Programming
Name of the Author: Tamim Shahriar Subeen
Price of The Book:250
Available in Stock: 1000
Add your comment