Home > JAVA, Java SE Codes > CREDIT LIMIT – Java Program

CREDIT LIMIT – Java Program

Question : [CREDIT LIMIT]
Develop an 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 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”. Your class should have a constructor that initializes the instance variables. Account number is auto generated and user is not supposed to enter it. Provide a set and a get method for each instance variable.
Answer

/**
* FileName: CreditLimit.java
* @author (Sandeep Negi)
* MCA 2nd Year
* Java Programming Lab-406
*/

import java.util.Scanner;

class Customer{
private int accNumber;
private double balance;
private double creditLimit;
private double totalItemsCharge;
private double totalCreditUsed;
private static int counter = 1234;

public Customer(double b,double cl){

this.accNumber = this.counter + 10;
this.counter += 10;
this.balance = b;
this.creditLimit = cl;
this.totalItemsCharge = 0.0;
this.totalCreditUsed = 0.0;
}

public void setNewBalance(){
balance = balance + totalItemsCharge - totalCreditUsed;
}
public void setItemsCharge(double ic){
totalItemsCharge += ic;
}
public void setCreditUsed(double cu){
totalCreditUsed += cu;
}
public double getBalance(){
return balance;
}
public double getCreditLimit(){
return creditLimit;
}
public int getAccountNumber(){
return accNumber;
}
}

class CreditLimit {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
double bal,cl,tic,tcu;
System.out.print("Enter number of Customers :");
int noOfCustomers = sc.nextInt();
for(int i=0;i<noOfCustomers;i++){
System.out.println("\nEnter customer " + (i+1) + " details--> ");
System.out.print("Enter balance and credit limit(use space to separate them) :");
bal = sc.nextDouble(); cl = sc.nextDouble();
Customer c = new Customer(bal,cl);
System.out.print("Enter total items charge and total credit used(use space to separate them) :");
tic = sc.nextDouble(); tcu = sc.nextDouble();
c.setItemsCharge(tic);
c.setCreditUsed(tcu);
c.setNewBalance();
if(c.getBalance() > c.getCreditLimit()){
System.out.print("\nCredit Limit Exceeded for Account Number " + c.getAccountNumber());
}else{
System.out.print("\nSufficient Credit Limit Remaining for Account Number " + c.getAccountNumber());
}
}
}
}
About these ads
Categories: JAVA, Java SE Codes Tags: , , ,
  1. July 25, 2011 at 11:09 am | #1

    Aw, this was a really nice post. In idea I would like to put in writing like this additionally – taking time and actual effort to make a very good article… but what can I say… I procrastinate alot and by no means seem to get something done.

  2. July 30, 2011 at 3:28 am | #2

    You made some decent points there. I looked on the internet for the issue and found most individuals will go along with with your website.

  3. August 28, 2011 at 2:53 am | #3

    I liked your article is an interesting technology
    thanks to google I found you

  4. shaba
    October 27, 2011 at 5:24 am | #4

    i wish that i will meet the programmer of this java code

    • October 27, 2011 at 9:49 am | #5

      Well thanks for ur beautiful comment,,,but it’s all but craziness of programming that inspires me to write codes like this.Actually it was my college assignment and i shared it on my blog becz of my believe & support to open source and free software community.
      Thanks u all

  5. claudeforlife
    January 12, 2012 at 4:57 pm | #6

    thanks for that i like the codes you wrote and your approach to the question

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: