•Write a Java
class Book with following features:
•Instance variables :
–title for
the title of book of type String.
–author for
the author’s name of type String.
–price for the book price of type double.
•Instance methods:
–public void setTitle(String title): Used to set the
title of book.
–public void setAuthor(String author): Used to set the
name of author of book.
–public void setPrice(double price): Used to set the
price of book.
–public String getTitle(): This method returns the title of book.
–public String getAuthor(): This method returns the author’s name of book.
–Public double getPrice( ): Used to set the price of book.
class Book
{
String title,author;
double price;
void setTitle(String t)
{
title=t;
}
void setAuthor(String a)
{
author=a;
}
void setPrice(double p)
{
price=p;
}
String getTitle()
{
return title;
}
String getAuthor()
{
return author;
}
double getPrice()
{
return price;
}
public static void main(String[] args)
{
Book b1=new Book();
b1.setTitle("introduction to java");
b1.setAuthor("Dietiel");
b1.setPrice(550.60);
System.out.println("Book Title "+ b1.getTitle()+"Author "+b1.getAuthor()+"Price "+b1.getPrice());
}
}
No comments:
Post a Comment