#### 5. Some credit card companies pay back a small portion of the charges a customer makes over a year. A particular credit card company’s pay back policy is as follows:

- 0.25% for charges up to Rs. 500
- 0.50% for the next Rs.1000 (that is, the portion between Rs. 500 and Rs. 1500)
- 0.75% for the next Rs.1000 (that is, the portion between Rs. 1500 and Rs. 2500)
- 1.0% for charges above Rs2500

**Define the program, which accepts a charge amount and computes the corresponding pay back amount.**

**Examples to understand the question:**

- A customer whose charge is Rs. 400 a year, then he will get Rs.1.00, which is 0.25 % of 400.
- When a customer’s charge is Rs.1, 400 a year, then he will receive Rs. 5.75, which is Rs.1.25 till Rs.500 and 0.50% of 900 = Rs.4.50

**Logic of the Solution:**

- Declare charges and pb as double
- Initialize both the variables with 0, so we don’t get scrap value while carrying out arithmetical operations on them
- Print a message for the user using System.out.println and ask the user for total charges
- Store the amount entered by the user into charges variable
- We will be using the
**nested if else**to calculate the payback amount - If the charges are lower than 500 then
- Take out 0.25 percent of the amount
- And print the Payback amount to the screen

- Otherwise, if the amount is more than 500 then
- Payback amount will be 0.25 till 500
- Now deduct 500 from the total charges
- If the deducted charges are smaller than 1000 then
- 0.50% will be calculated on the amount and add the new payback amount to the previous one.

- Otherwise, if it is still more than 1000 then
- Payback amount will be 0.50 till next 1000 and add the new payback amount to the previous one.
- Now deduct 1000 from the total charges again
- If the deducted charges are smaller than 1000 then
- 0.75% will be calculated on the amount and add the new payback amount to the previous one.

- Otherwise, if it is still more than 1000 then
- Payback amount will be 0.75 till next 1000 and add the new payback amount to the previous one.
- Now deduct 1000 from the total charges again

- If there are still some remaining charges then
- Payback amount will be 1% of all remaining charges and added to the previous payback amount calculated.

- Now, simply print the
**pb**variable

import java.util.*; class charges { public static void main(String [] arg) { Scanner sc = new Scanner(System.in); double charges=0,pb=0; System.out.println("Enter the total charges"); charges=sc.nextDouble(); if(charges<=500) { pb=(charges/100)*0.25; } else { pb=(500/100)*0.25; charges=charges-500; if(charges<=1000) { pb=pb+(charges/100)*0.50; } else { pb=pb+(1000/100)*0.50; charges=charges-1000; if(charges<=1000) { pb=pb+(charges/100)*0.75; } else { pb=pb+(1000/100)*0.75; charges=charges-1000; if(charges>=1) { pb=pb+(charges/100)*1.0; } } } } System.out.println("Your Payback Amount is = "+pb); } }

**Output:**

**Alternative logics that can be applied:**

This program can be simplified even further and that can reduce the number of code lines, we’ll soon be posting an alternate solution for this question. If you already got a good logic in mind, then help us by leaving a comment below.

Continue to next page for another question.

## 0 Responses on Java Question Set I - Conditional Statements in Java|