1. Exercises: Write a class Book with three data members BookId, Pages and Price. It also contains the following member function: • The get() method is used to input values • The show() method is used to display values Object Oriented Programming using JAVA Lab Manual – Page 24|193 • The set() method is used to set the values of data members using parameters • The getPrice() method is used to return the value of price
class Book {
private int BookId;
private int Pages;
private double Price;
public int getBookId() { return this.BookId; }
public int getPages() { return this.Pages; }
public double getPrice() { return this.Price; }
public void setBookId(int BookId) { this.BookId = BookId; }
public void setPages(int Pages) { this.Pages = Pages; }
public void setPrice(double Price) { this.Price = Price; }
public void show() {
System.out.println("BookId: " + BookId);
System.out.println("Pages: " + Pages);
System.out.println("Price: " + Price);
}
}
Comments
Leave a comment