/ Published in: Java
This was an assignment given to me in my Java course.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* Author: Ethan Courtney * Date Created: 2/28/18 */ public class CreditCalculator { private int accountNum, balanceStartOfMonth, itemsCharged, totalCredits, creditLimit, newBalance; public CreditCalculator(int account, int balance, int items, int totalcred, int limit, int newBalance) { accountNum = account; balanceStartOfMonth = balance; itemsCharged = items; totalCredits = totalcred; creditLimit = limit; newBalance = newBalance; } public int setAccount(int account) { accountNum = account; return accountNum; } public int setBalance(int balance) { balanceStartOfMonth = balance; return balanceStartOfMonth; } public int setItems(int items) { itemsCharged = items; return itemsCharged; } public int setTotalCredit(int totalcred) { totalCredits = totalcred; return totalCredits; } public int setCreditLimit(int limit) { creditLimit = limit; return creditLimit; } public int setNewBalance() { newBalance = newBalance; newBalance = balanceStartOfMonth + itemsCharged - totalCredits; return newBalance; } } /* Author: Ethan Courtney * Date Created: 2/27/18 */ import java.util.*; public class CreditCalculatorTest { { CreditCalculator calculator = new CreditCalculator(0,0,0,0,0,0); int account = 1; //setting account to 1 here so it will be initialized in the while loop int balance; int items; int totalcred; int limit; int newbalance; while (calculator.setAccount(account) != 0) //As long as the account number is not set to 0 program will continue to loop { account = input.nextInt(); calculator.setAccount(account); //prompts user for account number balance = input.nextInt(); calculator.setBalance(balance); //prompts user for balance items = input.nextInt(); calculator.setItems(items); //prompts user for total amount of charges totalcred = input.nextInt(); calculator.setTotalCredit(totalcred); //prompts user for total credit limit = input.nextInt(); calculator.setCreditLimit(limit); //prompts the user for credit limit System.out.println("The customers new balance is " + calculator.setNewBalance()); //prints the new balance if (calculator.setBalance(balance) > calculator.setCreditLimit(limit)) { break; //stops loop } } } }