[Question 4] ICSE 2016 Computer Application Solved - Book Fair
Question 4.
Define a class named BookFair with the following description:
Instance variables/Data members:
String Bname – stores the name of the book.
double price – stores the price of the book.
double price – stores the price of the book.
Member Methods:
(i) BookFair() Default constructor to initialize data members.
(ii) void Input() To input and store the name and the price of the book.
(iii) void calculate() To calculate the price after discount. Discount is calculated based on the following criteria.
Price | Discount |
Less than or equal to Rs 1000 | 2% of price |
More than Rs 1000 and less than or equal to Rs 3000 | 10% of price |
More than Rs 3000 | 15% of price |
(iv) void display() To display the name and price of the book after discount.
Write a main method to create an object of the class and call the above member methods.
SOURCE CODE
import java.io.*;
import java.util.*;
class BookFair
{
String Bname;
double price,total;
BookFair()
{
Bname="";
price=0.0;
}
void Input()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter name of book :");
Bname=sc.nextLine();
System.out.print("Enter Price of book :");
price=sc.nextDouble();
}
void calculate()
{
double dis=0;
if(price<=1000)
dis=price*0.02;
else if(price>1000&&price<=3000)
dis=price*0.1;
else if(price>3000)
dis=price*0.15;
total=price-dis;
}
void display()
{
System.out.println("Name of Book :"+Bname);
System.out.println("Price of Book :"+price);
System.out.println("Price after of book discount :"+total);
}
public static void main(String args[])
{
BookFair obj=new BookFair();
obj.Input();
obj.calculate();
obj.display();
}
}
OUTPUT
If you have any question then leave a comment below I will do my best to answer that question.
Comments
Post a Comment