Posted By


EthanEC94 on 03/01/18

Tagged


Statistics


Viewed 2200 times
Favorited by 0 user(s)

Java Credit Limit Calculator


/ Published in: Java
Save to your folder(s)

This was an assignment given to me in my Java course.


Copy this code and paste it in your HTML
  1. /* Author: Ethan Courtney
  2.  * Date Created: 2/28/18 */
  3.  
  4. public class CreditCalculator {
  5.  
  6. private int accountNum, balanceStartOfMonth, itemsCharged, totalCredits, creditLimit, newBalance;
  7.  
  8. public CreditCalculator(int account, int balance, int items, int totalcred, int limit, int newBalance)
  9. {
  10. accountNum = account;
  11. balanceStartOfMonth = balance;
  12. itemsCharged = items;
  13. totalCredits = totalcred;
  14. creditLimit = limit;
  15. newBalance = newBalance;
  16. }
  17.  
  18. public int setAccount(int account)
  19. {
  20. accountNum = account;
  21. return accountNum;
  22. }
  23.  
  24. public int setBalance(int balance)
  25. {
  26. balanceStartOfMonth = balance;
  27. return balanceStartOfMonth;
  28. }
  29.  
  30. public int setItems(int items)
  31. {
  32. itemsCharged = items;
  33. return itemsCharged;
  34. }
  35.  
  36. public int setTotalCredit(int totalcred)
  37. {
  38. totalCredits = totalcred;
  39. return totalCredits;
  40. }
  41.  
  42. public int setCreditLimit(int limit)
  43. {
  44. creditLimit = limit;
  45. return creditLimit;
  46. }
  47.  
  48.  
  49. public int setNewBalance()
  50. {
  51. newBalance = newBalance;
  52.  
  53. newBalance = balanceStartOfMonth + itemsCharged - totalCredits;
  54.  
  55. return newBalance;
  56. }
  57. }
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. /* Author: Ethan Courtney
  71.  * Date Created: 2/27/18 */
  72.  
  73. import java.util.*;
  74.  
  75. public class CreditCalculatorTest
  76.  
  77. {
  78. public static void main(String[] args)
  79. {
  80. CreditCalculator calculator = new CreditCalculator(0,0,0,0,0,0);
  81.  
  82. Scanner input = new Scanner(System.in);
  83.  
  84. int account = 1; //setting account to 1 here so it will be initialized in the while loop
  85. int balance;
  86. int items;
  87. int totalcred;
  88. int limit;
  89. int newbalance;
  90.  
  91. while (calculator.setAccount(account) != 0) //As long as the account number is not set to 0 program will continue to loop
  92. {
  93. System.out.println("Enter the customers account number: ");
  94. account = input.nextInt();
  95. calculator.setAccount(account); //prompts user for account number
  96.  
  97. System.out.println("Enter the customers balance at the start of the month: ");
  98. balance = input.nextInt();
  99. calculator.setBalance(balance); //prompts user for balance
  100.  
  101. System.out.println("Enter the total amount of charges: ");
  102. items = input.nextInt();
  103. calculator.setItems(items); //prompts user for total amount of charges
  104.  
  105. System.out.println("Enter the total amount of credits: ");
  106. totalcred = input.nextInt();
  107. calculator.setTotalCredit(totalcred); //prompts user for total credit
  108.  
  109. System.out.println("Enter the credit limit: ");
  110. limit = input.nextInt();
  111. calculator.setCreditLimit(limit); //prompts the user for credit limit
  112.  
  113. System.out.println("The customers new balance is " + calculator.setNewBalance()); //prints the new balance
  114.  
  115. if (calculator.setBalance(balance) > calculator.setCreditLimit(limit))
  116. {
  117. System.out.println("Credit Limit Exceeded"); //if balance is greater limit will print this
  118. break; //stops loop
  119. }
  120.  
  121. }
  122. }
  123. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.