. 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
Hi 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
Hey buddy, But,where is the behaviour to modify the price and period of the periodicals? The class Periodical doesn't even mention about the price variable. Please help me understand. Thanks in advance :)