Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 1. Develop a Java application that will determine whether any of several

ID: 3736168 • Letter: P

Question

Problem 1. Develop a Java application that will determine 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 of 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


public class Customer {


private int accountNumber;
private double beginBalance;
private double totalCharged;
private double totalCredits;
private double allowedCreditLimit;
public Customer() {
super();
}
public Customer(int accountNumber, double beginBalance, double totalCharged,
double totalCredits, double allowedCreditLimit) {
super();
this.accountNumber = accountNumber;
this.beginBalance = beginBalance;
this.totalCharged = totalCharged;
this.totalCredits = totalCredits;
this.allowedCreditLimit = allowedCreditLimit;
}
public int getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(int accountNumber) {
this.accountNumber = accountNumber;
}
public double getBeginBalance() {
return beginBalance;
}
public void setBeginBalance(double beginBalance) {
this.beginBalance = beginBalance;
}
public double getTotalCharged() {
return totalCharged;
}
public void setTotalCharged(double totalCharged) {
this.totalCharged = totalCharged;
}
public double getTotalCredits() {
return totalCredits;
}
public void setTotalCredits(double totalCredits) {
this.totalCredits = totalCredits;
}
public double getAllowedCreditLimit() {
return allowedCreditLimit;
}
public void setAllowedCreditLimit(double allowedCreditLimit) {
this.allowedCreditLimit = allowedCreditLimit;
}
public void calculateNewBalance(Customer c)
{
double newBalance=c.getBeginBalance() + c.getTotalCharged() - c.getTotalCredits();
if(newBalance > c.getAllowedCreditLimit())
{
System.out.println("Credit Limit Exceeded");
}
else
{
System.out.println("New Balance for Account "+c.getAccountNumber()+" is :"+newBalance );
}
}
}

CustomerCreditCheck Class:-

import java.util.Scanner;
public class CustomerCreditCheck {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int noOfAccount=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the No of Accounts :");
noOfAccount=sc.nextInt();
for(int i=0;i<noOfAccount;i++)
{
int accountNo=0;
double balance=0;
double charge=0;
double credits=0;
double creditLimit=0;
double newBalance=0;
System.out.println("Enter Account Number: ");
accountNo=sc.nextInt();
System.out.println("Enter Balance:");
balance=sc.nextDouble();
System.out.println("Enter Charges : ");
charge=sc.nextDouble();
System.out.println("Enter Credits :");
credits=sc.nextDouble();

System.out.println("Enter Credit Limit :");
creditLimit=sc.nextDouble();
Customer c=new Customer(accountNo,balance,charge,credits,creditLimit);
c.calculateNewBalance(c);

}
}

}

Output:--

Enter the No of Accounts :
2
Enter Account Number:
1
Enter Balance:
23
Enter Charges :
3
Enter Credits :
5
Enter Credit Limit :
67
New Balance for Account 1 is :21.0
Enter Account Number:
2
Enter Balance:
34
Enter Charges :
45
Enter Credits :
5
Enter Credit Limit :
56
Credit Limit Exceeded

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote