Sup folks, I have a rather unorganized homework assignment which consists of creating a program which stores the users initial balances and maintains their checking account.
The assignment template:
Write a class with methods to help you balance your checking account(an object class-main method is not in this class). The CheckingAccount Class should have at least two instance variables: the balance and the total service charges, along with methods to get and set each instance variables. You may add other variables and methods if you like. The program should read the initial balance for the month, followed by a series of transactions. For each transaction entered, the program should display the transaction data, the current balance for the account, and the total service charges. Service charges are $0.10 for a deposit and $0.15 for a check. If the balance drops below $500.00 at any point during the month, a service charge of $5.00 is assessed once for the month. Anytime the balance drops below $50.00, the program should print a warning message. If the balance becomes negative, an additional service charge of $10.00 should be assessed for each check until the balance becomes positive again. A transaction takes the form of an int number, followed by a double number. If the int number is a 1, then the double number is the amount of a check. If the int number is 2, then the double number is the amount of a deposit. The last transaction is 0 with no number to follow it.
A sample Input/Output dialogue might look like this: (Use the JOptionPane for the dialog)
I Enter your initial balance: 879.46
O Initial balance : $879.46
I Enter trans code:1
I Enter trans amt: 400.00
O Transaction : Check in amount of $400.00
Current Balance : $479.46
Service charge : Check --- charge $0.15
Service charge : Below $500 --- charge $5.00
Total service charge : $5.15
I Enter trans code: 2
I Enter trans amt: 100
O Transaction : Deposit in amount of $100.00
Current Balance : $579.46
Service charge : Deposit --- charge $0.10
Total service charge : $5.25
I Enter trans code: 0
O Transaction : End
Current Balance : $579.46
Total service charge : $5.25
Final Balance : $574.21
Code template:
public class Main { //global variables: //define a CheckingAccount object to keep trach of the // account information. public static void main (String[] args) { // defines local variables // get initial balance from the user // perform in a loop until the trans code = 0 // get the trans code from the user and process it with appropriate helper method // When loop ends show final balance to user. } public static __________ getTransCode() { } public static _________ getTransAmt() { } public static __________ processCheck(___________) { } public static __________ processDeposit(___________) { } } --------------------CheckingAccount.java ------------------------- public class CheckingAccount { private double balance; private double totalServiceCharge; public CheckingAccount(double initialBalance) { balance = ______________________; totalServiceCharge = ______________; } public ____________ getBalance() { return _______________; } public void setBalance(double transAmt, int tCode) { if(tCode == 1) balance = ___________________; else //if(tCode == 2) balance = ______________________; } public ____________ getServiceCharge() { return totalServiceCharge; } public void setServiceCharge(double currentServiceCharge) { totalServiceCharge = ___________________________; } }
To define the checkingaccount object, I did:
public class Assignment1 { CheckingAccount info; double balance = 0; info = new CheckingAccount(balance); public static void main(String[] args) {
however an error comes up stating: identifier expected
My code currently consists of this:
import javax.swing.JOptionPane; public class Assignment1 { CheckingAccount info; double balance = 0; info = new CheckingAccount(balance); public static void main(String[] args) { String balance, transcode, transamount, input; double ibalance; int tcode; double tamount; do { balance = JOptionPane.showInputDialog ("Enter your initial balance: "); ibalance = Double.parseDouble(balance); transcode = JOptionPane.showInputDialog ("Enter your transaction" + " code:"); tcode = Integer.parseInt(transcode); if(tcode >= 1) { transamount = JOptionPane.showInputDialog ("Enter your trans amount:"); tamount = Double.parseDouble(transamount); public static int getTransCode() { int transcode; return transcode; } } public static _________ getTransAmt() { } public static __________ processCheck(___________) { } public static __________ processDeposit(___________) { } } }
With the last 4 methods given by my instructor, although I am not sure what they are used for. Would the getTrans method be only used to return the transaction value?
Also how would I proceed from here? After asking the user for the transaction amount, I have to post the users checking account as so:
This is the sample run code my professor has supplied, after asking the user for the transaction amount.
Transaction: Check in amount of $50.00
Current Balance: &450.00
Service Charge: Check --- charge $0.15
Service Charge: Below $4000 --- charge $5.00
Total Service Charge: $5.15
I understand how to post the transaction amount and the current balance, as the current balance would just be a simple calculation of initial balance - transaction amount.
I don't understand how to calculate the service charge, with all the parameters in place of, if the balance is below 500 you have to charge 5.00. I'm guessing this is done by using a nested if - else statement, however the sample code my professor provided includes nothing of that sort, just the checkingaccount.class