Results 1 to 20 of 55
Thread: Help?
- 02-06-2011, 07:12 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 25
- Rep Power
- 0
Help?
Hey guys so I have to do this project but for some reason it says cannot find symbol. Can anyone help?
Here is the code.
Java Code:/** * OverBank is used to tell a person how much money is in their bank account after a widthdraw, or deposit. * * @author * @version 1.0 2/6/2011 */ public class BankAccount { /** * Constructor for objects of class OverBank */ public BankAccount() { // instance variable double balance is how much money is curently in the account. // instance variable string name is the name of the person owning the account. double balance; String name; } /** * deposit method returns nothing, accepts a double that is the amount of money being withdrawn. This will be subtracted to the balance. * * @param double deposit * @return nothing */ public void deposit(double deposit, double current,double balance) { balance = deposit + current; } /** * withdraw method returns nothing, accepts a double that is the amount of money being withdrawn. This will be subtracted ded to the balance. * * @param double withdrawn * @return nothing */ public void withdrawn(double withdrawn, double current,double balance) { balance = current - withdrawn; } }
Main Method The error is down here.
Java Code:/** * Tester is the main method of OverBank. This is where the inputs for money will be asked. * * @author * @version 1.0 2/6/2011 */ public class Tester { /** * MAIN METHOD */ public static void main(String [ ] args) { [COLOR="DarkOrange"] double BankAccount; BankAccount myAccount = new BankAccount (1000);[/COLOR] } }
I highlighted where the error occurs. I need to set myAccount to a value of $1000 but when I try to do this it won't let me.
Moderator Edit: Code tags addedLast edited by Fubarable; 02-06-2011 at 07:38 PM. Reason: Moderator Edit: Code tags added
- 02-06-2011, 07:16 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,392
- Blog Entries
- 7
- Rep Power
- 17
You have only defined a constructor that doesn't take arguments; in your main( ... ) method you're trying to use a constructor that takes one argument numeric parameter. You don't have that. That was what the compiler is complaining about.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-06-2011, 07:19 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 25
- Rep Power
- 0
ok well what if i do this?
/**
* MAIN METHOD
*/
public static void main(String [ ] args)
{
String BankAccount;
double myAccount;
myAccount = 1000;
deposit(505.22);
System.out.println(balance);
would that work?
or would it not be able to call the deposit method?
- 02-06-2011, 07:22 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,392
- Blog Entries
- 7
- Rep Power
- 17
- 02-06-2011, 07:25 PM #5
Member
- Join Date
- Feb 2011
- Posts
- 25
- Rep Power
- 0
i have tried it however it takes forever to compile, so I think that it doesn't work? It never says compilation complete nor does it say error.
- 02-06-2011, 07:28 PM #6
Senior Member
- Join Date
- Jan 2011
- Location
- Belgrade, Serbia
- Posts
- 227
- Rep Power
- 3
What for you need String BankAccount and double myAccount. I can see you never use them...
- 02-06-2011, 07:29 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,392
- Blog Entries
- 7
- Rep Power
- 17
- 02-06-2011, 07:29 PM #8
Member
- Join Date
- Feb 2011
- Posts
- 25
- Rep Power
- 0
alright yeah that 2nd way doesn't work. It can't find the method like i thought.
- 02-06-2011, 07:30 PM #9
Member
- Join Date
- Feb 2011
- Posts
- 25
- Rep Power
- 0
so I need to do it along the lines of
/**
* MAIN METHOD
*/
public static void main(String [ ] args)
{
double BankAccount;
BankAccount myAccount = new BankAccount (1000);
}
}
how do I make my constructor accept arguments?
-
Give the BankAccount class a constructor that accepts the arguments needed, but this has already been suggested I see. Have you tried this? If so, what happened?
Also, when posting code here, please use code tags so that your code will retain its formatting and thus will be readable -- after all, your goal is to get as many people to read your post and understand your code as possible, right?
To do this, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.
Another way to do this is to manually place the tags into your code by placing the tag [code] above your pasted code and the tag [/code] below your pasted code like so:
I will edit your first post but will leave it to you to edit your other posts.Java Code:[code] // your code goes here // notice how the top and bottom tags are different [/code]
Luck!
- 02-06-2011, 07:38 PM #11
Senior Member
- Join Date
- Jan 2011
- Location
- Belgrade, Serbia
- Posts
- 227
- Rep Power
- 3
Java Code:public BankAccount(int [I]someNumber[/I]){ // your code for constructor }
- 02-06-2011, 07:40 PM #12
Member
- Join Date
- Feb 2011
- Posts
- 25
- Rep Power
- 0
would i place that in the main method or in the constructor?
- 02-06-2011, 07:42 PM #13
Member
- Join Date
- Feb 2011
- Posts
- 25
- Rep Power
- 0
I would place that in the constructor like this?
Java Code:/** * Constructor for objects of class BankAccount */ public BankAccount(int x){ double BankAccount; }
Then in the tester put this?
Java Code:/** * MAIN METHOD */ public static void main(String [ ] args) { int x =1000; BankAccount myAccount = new BankAccount (x); }
-
- 02-06-2011, 07:44 PM #15
Member
- Join Date
- Feb 2011
- Posts
- 25
- Rep Power
- 0
yeah. I just really lost. My teacher really didn't teach us much of this because it's been snowing a lot and we have had a lot of snow days.
-
- 02-06-2011, 07:45 PM #17
Senior Member
- Join Date
- Jan 2011
- Location
- Belgrade, Serbia
- Posts
- 227
- Rep Power
- 3
Well, that will be your constructor. I put int as parameter just as an example.
-
- 02-06-2011, 07:49 PM #19
Member
- Join Date
- Feb 2011
- Posts
- 25
- Rep Power
- 0
Yeah, I'm reading in my book however the thing they are dealing with in the example is a circle, and really isn't helping me much.
now im getting the error cannot find sumbol - method deposit(double)
- 02-06-2011, 07:51 PM #20
Member
- Join Date
- Feb 2011
- Posts
- 25
- Rep Power
- 0


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks