ICSE 2016 Computer Application Question 4 Solution

ICSE 2016 Computer Application Question 4 Solution

Computer Application Question 4 Solution ICSE 2016

ICSE 2016 Computer Application Question 4 Solution

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.
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.

Solution
import java.io.*;
/**
 * class BookFair here.
 *
 * @author (Khurshid Md Anwar)
 *
 */
public class BookFair
{
    // instance variables
    private double price;                 // Book price
    private double discount;           // Book discount
    private String Bname;              // Book Name

    /**
     * Constructor for objects of class BookFair
     */
    public BookFair()
    {
        // initialise instance variables
        price = 0.0;
        Bname = null;
    }

    void input()throws IOException  // input method
    {
        InputStreamReader in=new InputStreamReader(System.in);
        BufferedReader br=new BufferedReader(in);
        System.out.println("Enter Book name and it's Price: ");
        Bname = br.readLine();
        price = Double.parseDouble(br.readLine());
    }

    void calculate()   // calculate method
    {
        if(price <= 1000)
        {
            discount = price * 0.02;                       // 2% discount price
        }
        else if(price > 1000 && price <= 3000) // 10% discount price
        {
            discount = price * 0.1;
        }
        else
        {
            discount = price *.15;                         // 15% discount price
        }
    }

    void display()     // display method
    {
        price = price - discount;
        System.out.println("\n\n Book Name :" + Bname);
        System.out.println("\n Price after discount :" + price);
    }

    public static void main(String args[]) throws IOException
    {
        // Object creation
        BookFair ob = new BookFair();
        ob.input();
        ob.calculate();
        ob.display();
    }
}

Output:
Enter Book name and it's Price:
Learn Java in 24 Hours
450.0


Book Name :Learn Java in 24 Hours

Price after discount :441.0

Enter Book name and it's Price:
Search Engine Optimization
1200.0


Book Name :Search Engine Optimization



Price after discount :1080.0


More programs:

Java program for Niven or Harshad number ICSE 2016 Q 8

IMPORTANT QUESTION ANSWER for ICSE ISC BSC BCA BTECH

Good Book for ICSE exam



Java program for Niven or Harshad number

Java program for Niven or Harshad number

Java program for Niven or Harshad number


ICSE 2016 Question 8 solution

Write a program to accept a number and check and display whether it is a Niven number or not.
(Niven number is the number which is divisible by its sum of digits it is also called Harshad number)
Example:
Consider the number 126
Sum of its digits is 1 + 2 + 6 = 9 and 126 is divisible by 9



Solution:
import java.util.*;
/**
 * class Niven Or Harshad Number
 * @author (Khurshid Md Anwar)
*/
public class NivenOrHarshadNumber
{
    public static void main(String args[])
    {
        int n, s, a, p;
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a number : ");
        n = sc.nextInt();   // take the number
        p = n;
        s=0;                // initialize s for summation as 0
        while(n!=0)
        {
            a = n % 10;     // mod division for reminder
            s = s + a;      // sum the reminder
            n = n / 10;     // integer division
        }
        // check the summation whether it is divisble by entered number
        // or not
        if(p % s == 0)
        {
            System.out.println("It is a Niven / Harshad Number");
        }
        else
        {
            System.out.println("It is not a Niven / Harshad Number");
        }
    }
}

Output:
Enter a number : 126
It is a Niven / Harshad Number

Enter a number : 125


It is not a Niven / Harshad Number

More programs:

Java program to print Twin Prime Numbers


Some of the Good Books for ICSE exam 2017