Question: Develop a Java application that determines whether any of several department-store customers has exceeded the credit limit on a charge account. For each customer, the following facts are available:
- account number
- balance at the beginning of the month
- total of all items charged by the customer this month
- total of all credits applied to the customer’s account this month
- allowed credit limit.
The program should input all these facts as integers, calculate the new balance (= beginning balance + charges – credits), display the new balance and determine whether the new balance exceeds the customer’s credit limit. For those customers whose credit limit is exceeded, the program should display the message “Credit limit exceeded”.
1 2 |
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> *<br /> * Exercise 4.18 - Credit Limit Calculator<br /> *<br /> */ <br /><br />import java.util.Scanner;<br /><br />public class CreditLimitCalculator {<br /><br /> public static void main(String[] args) {<br /><br /> int accountNumber; // stores the account number of the customer<br /> int balance; // stores the balance of the customer at the beginning of the month<br /> int totalItems; // stores the total of all items charged by the customer this month <br /> int totalCredits; // stores the total of all credits applied to the customer’s account this month<br /> int allowedCreditLimit; // stores the allowed credit limit of the customer<br /><br /> Scanner input = new Scanner(System.in); //create scanner object for collecting input from user<br /><br /> System.out.println("This Application Determines Whether Any Of Several "<br /> + "Department-store nCustomers Has Exceeded The Credit Limit On A Charge Account.n");<br /><br /> System.out.println("Enter "CUSTOMER ACCOUNT NUMBER": ");<br /> accountNumber = input.nextInt();<br /><br /> System.out.println();<br /><br /> System.out.println("Enter "CUSTOMER BALANCE" at the beginning of the month: ");<br /> balance = input.nextInt();<br /><br /> System.out.println();<br /><br /> System.out.println("Enter "TOTAL OF ALL ITEMS CHARGED" by the Customer this month: ");<br /> totalItems = input.nextInt();<br /><br /> System.out.println();<br /><br /> System.out.println("Enter "TOTAL OF ALL CREDITS APPLIED" to the Customer this month: ");<br /> totalCredits = input.nextInt();<br /><br /> System.out.println();<br /><br /> System.out.println("Enter the "ALLOWED CREDIT LIMIT" of the Customer: ");<br /> allowedCreditLimit = input.nextInt();<br /><br /> System.out.println();<br /><br /> int newBalance = balance + totalItems - totalCredits;<br /><br /> System.out.println("Customer: " + accountNumber + "n"<br /> + "Balance at the beginning of the month: " + balance + "n"<br /> + "Total number of items charged this month: " + totalItems + "n"<br /> + "Total number of Credits Applied this month: " + totalCredits + "n");<br /><br /> System.out.println("The Customer's new Balance is " + newBalance);<br /><br /> System.out.println();<br /><br /> if (newBalance < allowedCreditLimit) {<br /> System.out.println("CREDIT LIMIT EXCEEDED");<br /> }<br /><br /> System.out.println();<br /> }<br />}<br /><br /> |
Program Output |
Click here to see other answers to Dietel’s Java How to Program exercises.