Determining if Customers had exceeded their Credit Limit in Java

Problem:

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 numberb) balance at the beginning of the monthc) total of all items charged by the customer this monthd) total of all credits applied to the customer’s account this monthe) 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


Solution:

 import java.util.Scanner;

public class problemg
{
  public static void main(String[] args)
       {
        Scanner scan = new Scanner (System.in);
        {
        //Let's declare our account detail variables
        //Note: to make coding faster, you can declare variables
        //that use the same data type (e.g., int) together with
        //with a comma to separat the variables, without or without
        //initializing them (e.g., making them equal to something)
        int account = 1, balance,charges,credits,credit_limit, newbal;
        
        //Let's assume that an account number can't be zero so that 
        //we can loop over every customer account number until we
        //type in 0 to tell the program to stop
        while( account != 0 )
          {
          //Let's just add a new blank line to make things look nicer
          System.out.println();
          System.out.print("Input Account Number: ");
          account = scan.nextInt();           
          
          System.out.print("Input Beginning Balance: ");
          balance = scan.nextInt();
          
          System.out.print("Input Total Charges: ");
          charges = scan.nextInt();
          
          System.out.print("Input Total Credits: ");
          credits = scan.nextInt();
          
          System.out.print("Input Credit Limit: ");
          credit_limit = scan.nextInt();

          //And time for the calculations and displaying what the paragraph wants
          newbal = balance + charges - credits;
          System.out.println("Equivalent New Balnce: " + newbal);

               if ( newbal > credit_limit)
               {
                  System.out.println("Credit Limit Exceeded");
                break;
               }
          }
       }
}
}


No comments :

Post a Comment

Follow Me

If you like our content, feel free to follow me to stay updated.

Subscribe

Enter your email address:

We hate spam as much as you do.

Upload Material

Got an exam, project, tutorial video, exercise, solutions, unsolved problem, question, solution manual? We are open to any coding material. Why not upload?

Upload

Copyright © 2012 - 2014 Java Problems  --  About  --  Attribution  --  Privacy Policy  --  Terms of Use  --  Contact