ICSE and ISC computer science question with answer

 

ICSE  and ISC computer science question with answer

ICSE  and ISC computer science Question with Answer

An ABC Credit card company set the limit for spending 25000 to its customer. ABC Credit Card Company also offers a cashback to its customers according to the following criteria. Accept the amount spent by the user and display the cashback amount he is entitled to. The amount, Cash Back.

                            Cash Back

First     2000            150

Next     2000            230 + 2% of amount exceeding 2000

Next     5000            500 + 4% of amount exceeding 4000

Till        25000         1200 + 8% of the amount exceeding 9000

Write a java program to declare the class 'ABCCreditCompany' that takes in the name of the customer and the amount spent by him. Calculate the cashback amount and print it along with all the other details.

Using following methods

void input()                        // for inputting the spending and customer name

void calculate()                 // for calculating the cash back

void display()                     // print the spending, cashback, and customer name

Solution

/**

A ABC Credit card company

*/

import java.util.*;

public class ABCCreditCompany

{

    double spend, cashBack = 0.0;

    String name;    // customer name

    void input()

    {

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter Customer Name :");

        name = sc.nextLine();

        System.out.println("Enter Spending amount :");

        spend = sc.nextDouble();

    }

 // started calculate method

    void calculate()

    {       

        if(spend > 25000)

        {

            // if spending more then 25000 then print a message and end the program

            System.out.println("Sorry Only Under Rs. 25000/- allowed");

            System.exit(0);  // End the program

        }

        else

        {

            if(spend<=2000)

            {

                cashBack = 150.0;

            }

            else if(spend>2000 && spend<=4000)

            {

                cashBack = 200.0 + (spend - 2000) * 0.02;

            }

            else if(spend>4000 && spend<=9000)

            {

                cashBack = 400.0 + (spend - 4000) * 0.04;

            }

            else

            {

                cashBack = 1200.0 + (spend - 9000) * 0.08;

            }

        }

    }

    void display()

    {

        System.out.println("Customer Name   :" + name);

        System.out.println("Spending        :" + spend);   

        System.out.println("Cash Back       :" + cashBack);

    }

 

    public static void main(String args[])

    {

      // Creating Objcet ob

        ABCCreditCompany ob = new ABCCreditCompany();

        ob.input();

        ob.calculate();

        ob.display();       

    }           

}

Sample output

Enter Customer Name :

Ramesh Das

Enter Spending amount :

8000

Customer Name   :Ramesh Das

Spending             :8000.0

Cash Back           :560.0

Java program



SHARE THIS
Previous Post
Next Post