[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.
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.
PriceDiscount
Less than or equal to Rs 10002% of price
More than Rs 1000 and less than or equal to Rs 300010% of price
More than Rs 300015% 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

Popular posts from this blog

[Question 3] ISC 2017 Computer Practical Paper Solved – Caesar Cipher.

Pattern of your own name.

Designing Patterns - Print 'Z'.