Computer Applications
A Credit card company allows a limit to spend ₹15000 to its clients. It also offers cash back facility according to the table shown below.
| Amount | Cashback |
|---|---|
| First ₹1000 | ₹100 |
| Next ₹2000 | ₹200 + 2% of amount exceeding ₹1000 |
| Next ₹4000 | ₹400 + 4% of amount exceeding ₹3000 |
| Next ₹8000 | ₹800 + 8% of amount exceeding ₹8000 |
Write a program to declare the class 'Credit' that takes in the name of the client and the amount spend by him. Calculate the cash back amount and print it along with the other input details. Assume there are 20 clients. Take details and print the output for each of them one by one.
Answer
import java.util.Scanner;
public class Credit
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
String names[] = new String[20];
double amounts[] = new double[20];
for (int i = 0; i < 20; i++) {
System.out.print("Enter client " + (i+1) + " name: ");
names[i] = in.nextLine();
System.out.print("Enter amount: ");
amounts[i] = in.nextInt();
in.nextLine(); //To empty input buffer
}
for (int i = 0; i < 20; i++) {
double cb = 0;
double amt = amounts[i];
System.out.println("Name: " + names[i]);
System.out.println("Amount: " + amounts[i]);
if (amt <= 1000)
cb = 100;
else if (amt <= 3000)
cb = 200 + (2 * (amt - 1000) / 100);
else if (amt <= 7000)
cb = 400 + (4 * (amt - 3000) / 100);
else if (amt <= 15000)
cb = 800 + (8 * (amt - 8000) / 100);
else
cb = -1;
if (cb == -1) {
System.out.println("Amount exceeds credit limit of 15000");
}
else {
System.out.println("Cash Back: " + cb);
}
}
}
}Output
Related Questions
Define a class to accept values into an integer array of order 4 x 4 and check whether it is a DIAGONAL array or not. An array is DIAGONAL if the sum of the left diagonal elements equals the sum of the right diagonal elements. Print the appropriate message.
Example:
3 4 2 5
2 5 2 3
5 3 2 7
1 3 7 1Sum of the left diagonal element = 3 + 5 + 2 + 1 = 11
Sum of the right diagonal element = 5 + 2 + 3 + 1 = 11
A single dimensional array has 50 elements, which of the following is the correct statement to initialize the last element to 100.
- x[51]=100
- x[48]=100
- x[49]=100
- x[50]=100
Define a class pin code and store the given pin codes in a single dimensional array. Sort these pin codes in ascending order using the Selection Sort technique only. Display the sorted array.
110061, 110001, 110029, 110023, 110055, 110006, 110019, 110033