Results 1 to 12 of 12
- 09-25-2012, 02:10 AM #1
Member
- Join Date
- Sep 2012
- Posts
- 6
- Rep Power
- 0
Checking Account function, need help!
Hey everyone. For my assignment, I am to construct a program which deals with the users checking account.
The assignment: 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)
The sample code:
The code I have currently:Java Code: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 = ___________________________; } }
I am having trouble at line 34, which is the info = new CheckingAccount (ibalance); line, an error comes up stating:Java Code:import javax.swing.JOptionPane; public class Assignment1 { public static CheckingAccount info; public static void main(String[] args) { String balance, transcode, transamount, input; CheckingAccount info; double ibalance; int tcode; double tamount; balance = JOptionPane.showInputDialog ("Enter your initial balance: "); ibalance = Double.parseDouble(balance); info = newCheckingAccount(ibalance); do { 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); CheckingAccount info = new CheckingAccount(tamount, tcode, ibalance); public static int getTransCode() { int transcode; return transcode; } } public static _________ getTransAmt() { } public static __________ processCheck(___________) { } public static __________ processDeposit(___________) { } } }
cannot find symbol
symbol: method newCheckingAccount(double)
location: class Assignment 1
I am also unsure how to proceed after asking for the transaction amount, using the checkingaccount.class how do I keep counters on the transaction amount considering the various parameters it presents?
-
Re: Checking Account function, need help!
Notice the difference between the line you state you're having a problem with:
And the actual line in the code? The error message is telling you exactly what's wrong:Java Code:info = new CheckingAccount (ibalance);
cannot find symbol
symbol: method newCheckingAccount(double)
- 09-25-2012, 02:29 AM #3
Member
- Join Date
- Sep 2012
- Posts
- 6
- Rep Power
- 0
Re: Checking Account function, need help!
Yeah the line on the code I posted is wrong for some reason, in my program it states its 34 which is the info = new CheckingAccount line.
What does that mean, cannot find symbol? I've tried putting double as an argument, but an error comes up saying:
.class expected
unexpected type
required: value
found: class
The code for the checkingaccount.class is:
This is more or less the sample code my instructor has providedJava Code:public class CheckingAccount { private double balance; private double totalServiceCharge; public CheckingAccount(double balance) { balance = ibalance; 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 =; } } } }
-
Re: Checking Account function, need help!
If you've made changes and have a new error, then you need to post the new code and the complete error message. Else you're forcing us to guess, and we're notoriously bad at that.
- 09-25-2012, 04:20 AM #5
Member
- Join Date
- Sep 2012
- Posts
- 6
- Rep Power
- 0
-
Re: Checking Account function, need help!
You state that you put "double as an argument" that's a change in your code -- *again* if you need our help, please post it as we need to see exactly what you mean by this, and the only way to show it is by showing your code. I'm not sure why you're holding back on this request.
Last edited by Fubarable; 09-25-2012 at 04:27 AM.
- 09-25-2012, 04:30 AM #7
Member
- Join Date
- Sep 2012
- Posts
- 6
- Rep Power
- 0
Re: Checking Account function, need help!
Yes, I put double as an argument, meaning info = new CheckingAccount(double); but as I've said the only error message I've recieved is
.class expected
unexpected type
required: value
found: class
-
Re: Checking Account function, need help!
OK, that's more like it. Don't do that. You need to pass a double variable or double literal into the constructor when calling it. You don't pass in double itself. I was afraid that you might be doing this but couldn't tell until you showed me the code. The solution is simple:
1) fix the typographical error that you showed in your first post, and it looks like you've done that by separating the identifier "new" from "CheckingAccount", and
2) don't try to pass in variable type names as if they were variables.
- 09-25-2012, 04:43 AM #9
Member
- Join Date
- Sep 2012
- Posts
- 6
- Rep Power
- 0
Re: Checking Account function, need help!
Wow, thank you so much I don't know how I didn't see the error of a simple space congestion. Thank you once again.
I'm quite lost on how to produce the results, with the transaction fee having a lot of parameters (0.10 cents for a deposit, 0.15 for check, if balance is below 500 then add 5.00).
When I compile, the program stops at line 9 on the CheckingAccount.java class. How would I construct the totalservicecharge variable with the listed parameters? For the balance variable I put balance = ibalance;
-
Re: Checking Account function, need help!
Yep, that's why I highlighted that bit in red (see my first answer).
Please tell the details about this.I'm quite lost on how to produce the results, with the transaction fee having a lot of parameters (0.10 cents for a deposit, 0.15 for check, if balance is below 500 then add 5.00).
When I compile, the program stops at line 9 on the CheckingAccount.java class. How would I construct the totalservicecharge variable with the listed parameters? For the balance variable I put balance = ibalance;
- 09-25-2012, 04:54 AM #11
Member
- Join Date
- Sep 2012
- Posts
- 6
- Rep Power
- 0
Re: Checking Account function, need help!
After fixing the error, I compiled and the program stopped when the main function calls for info = new CheckingAccount(ibalance);
It stops at the CheckingAccount.java Class, under method
Where the variable Totalservicecharge has yet to be identified. My question is how I would go about declaring this variable, considering the various parameters it presents. For example, if the users balance is below 500, I am to charge 5.00. For every deposit, I am to charge 0.5 and for every check 0.15Java Code:public CheckingAccount(double ibalance) { balance = ibalance; totalServiceCharge= balance+ } public getBalance() { return ; }
How would I construct this variable considering it has 3 different parameters to be considered?
-
Re: Checking Account function, need help!
First off it's totalServiceCharge, not Totalservicecharge. I know that I'm nitpicking about your post above that's not even part of your code, but since programming is an exercise in precision, you have to develop a strong intolerance for this thing.
Next off, we must decide on program logic before we can think about how to code things. Above you're talking about what happens when you create a new CheckingAccount. So what will the accumulated service charge be at the time of account creation? That number is what you should initialize the variable to.
Similar Threads
-
Recursive function to iteractive function
By mikeZet in forum New To JavaReplies: 0Last Post: 03-13-2012, 01:42 AM -
Checking if a math function is valid
By HardToHandle in forum New To JavaReplies: 3Last Post: 01-18-2012, 01:40 AM -
Calling function in Javascript- from other function
By jdigger in forum New To JavaReplies: 1Last Post: 02-27-2011, 09:00 PM -
Transfer from one account to another
By vividcooper in forum New To JavaReplies: 3Last Post: 01-26-2010, 10:43 PM -
Possible? Callback function passed as arguments to another function
By TreyAU21 in forum Advanced JavaReplies: 3Last Post: 12-04-2009, 03:08 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks