Computer Applications

Given below is a class based program to accept name and price of an article and find the amount after 12% discount if the price exceeds 10,000 otherwise, discount is nil. There are some places in the program left blank marked with ?1?, ?2?, ?3? and ?4? to be filled with appropriate keyword/expression.

class Discount 
( 
    int pr; double d, amt; String nm; 
    Scanner ob = ...?1?... Scanner(System.in); 
    void input( )   {
        System.out.println("Enter customer's name:"); 
        nm = ...?2?... ;
        System.out.println("Enter price of the article:"); 
        pr = ob.nextInt( ); 
    } 
    void calculate()    {
        if (...?3?...)  
            d= ...?4?... ;
        else 
            d = 0;
        amt = pr - d;
    } 
    void print()    {
        System.out.println("Name =" + nm); 
        System.out.println("Amount to be paid=" + amt); 
    }
}

Based on the above discussion, answer the following questions:

(a) What will be keyword /expression filled in place of ?1?

(b) What will be keyword/expression filled in place of ?2?

(c) What will be keyword /expression filled in place of ?3?

(d) What will be keyword /expression filled in place of ?4?

Java Classes

10 Likes

Answer

(a) new

(b) ob.nextLine()

(c) pr > 10000

(d) 12.0 / 100.0 * pr

The complete program is as follows:

class Discount 
( 
    int pr; double d, amt; String nm; 
    Scanner ob = new Scanner(System.in); 
    void input( )   {
        System.out.println("Enter customer's name:"); 
        nm = ob.nextLine();
        System.out.println("Enter price of the article:"); 
        pr = ob.nextInt( ); 
    } 
    void calculate()    {
        if (pr > 10000)  
            d= 12.0 / 100.0 * pr;
        else 
            d = 0;
        amt = pr - d;
    } 
    void print()    {
        System.out.println("Name =" + nm); 
        System.out.println("Amount to be paid=" + amt); 
    }
}

Answered By

7 Likes


Related Questions