Create Book having following attributes: Book ID, Title, Author and Price. Create Periodical which has the following additional attributes: Period (weekly, monthly etc...) .Add a behavior to modify the Price and the Period of the periodical. Display the updated periodical details.
Hello Friend,
Try the following code:
import java.util.*;
class Book{
int id;
String title;
String author;
double price;
public void setId(int id){
this.id=id;
}
public int getId(){
return id;
}
public void setTitle(String title){
this.title=title;
}
public String getTitle(){
return title;
}
public void setAuthor(String author){
this.author=author;
}
public String getAuthor(){
return author;
}
public void setPrice(double price){
this.price=price;
}
public double getPrice(){
return price;
}
}
class Periodical
{
String timeperiod;
public void setTimeperiod(String timeperiod){
this.timeperiod=timeperiod;
}
public String getTimeperiod(){
return timeperiod;
}
}
public class BookInformation{
public static void main(String[]args){
Book b=new Book();
Periodical p=new Periodical();
Scanner input=new Scanner(System.in);
System.out.print("Book ID: ");
int id=input.nextInt();
b.setId(id);
System.out.print("Title: ");
String title=input.next();
b.setTitle(title);
System.out.print("Author: ");
String author=input.next();
b.setAuthor(author);
System.out.print("Price: ");
double price=input.nextDouble();
b.setPrice(price);
System.out.print("Period: ");
String pp=input.next();
p.setTimeperiod(pp);
System.out.println();
System.out.println("----Book Information----");
System.out.println();
System.out.println("Book ID: "+b.getId());
System.out.println("Title: "+b.getTitle());
System.out.println("Author: "+b.getAuthor());
System.out.println("Price: "+b.getPrice());
System.out.println("Period: "+p.getTimeperiod());
}
}
Thanks
Add a behavior to modify the Price and the Period of the periodical, can u please elaborate this because i am unable to understand. In the above program i found that just we are accepting values from keyboard and printing by using inheritance concept. am i rite...?? but i didn't understood the line add a behavior etc....