Develop a java application that determines whether any of several department-sto
ID: 3623148 • Letter: D
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:a) account number
b) balance at the beginning of the month
c) total of all items charged by the customer this month
d) total of all credits applied to the customer's account this month
e) 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".
Explanation / Answer
More information is required to make the program more efficient. public class Main { public static void main(String[] args) { //account, balance, items, charges Customer customer = new Customer(12345, 500, 10, 2000); customer.calcualteNewBalance(); customer.checkCredit(); System.out.println("month balance: "+customer.getNewBalance()); if (customer.isPassedCredit() == true) { System.out.println("Credit limit exceeded"); } } } public class Customer { private int accountNumber; private int monthBalance, newBalance; private int itemsCharged; private int totalCharges; private int usedCredit; private boolean passedCredit; public static final int CREDIT_LIMIT = 1000; public Customer(int accountNumber, int monthBalance, int items, int charges) { this.accountNumber = accountNumber; this.monthBalance = monthBalance; this.itemsCharged = items; this.totalCharges = charges; } /** * Calculates for the new month balance */ public void calcualteNewBalance() { newBalance = monthBalance - totalCharges; if (newBalance < 0) { usedCredit = CREDIT_LIMIT - newBalance; } else { monthBalance = newBalance; } } /** * Checks if the credit limit has been exceeded */ public void checkCredit() { if (usedCredit < 0) { passedCredit = false; } else { passedCredit = true; } } /** * Acquires the state of the credit limit * @return True if the limit is exceeded, otherwise false */ public boolean isPassedCredit() { return passedCredit; } /** * Acquires the new balance for the month * @return The new month balance */ public int getNewBalance() { return newBalance; } }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.