Having troubles with a complex program, need help with an illegal start of type error.

I have highlighted my error in red, not sure what is going on, this program should allow the user to enter a choice and not exit until they enter a choice of 5 or higher. That is what the loop does and the user selection allows them to start an account, deposit, withdraw, or see their balance, or of course quit. Thought it would be nice to fill you in on whats going on, thanks for your help!

Could be a little more descriptive? Im sorry but I have a program with a switch and cases similar to this and it works, I've been hassling with this all day, I would really appreciate a little more insight. Im waiting for the aw ha! moment lol

It's not that either Henry or I don't understand the assignment. I promise.

The syntax is wrong and the compiler is telling you that. Henry and I agree.

I'll spend all night on here helping you if you wanna put the work in and pay attention to what we're saying. I won't just fix it and post the solution here for you.

It's up to you. The alternative is to fight with incorrect syntax all night and hand it in tomorrow incomplete.

Nick Harms
Ranch Hand

Joined: Mar 06, 2010
Posts: 44

posted Mar 30, 2010 16:44:17

0

Janeice DelVecchio wrote:For an example:

the do while loop should be in the main method and the other method should be declared OUTSIDE the main method. Then you can call it when you need it.

Im confused, how can I declare a method outside the main method while the loop is in the main method and the other methods are inside it. what you posted is an exact copy of mine correct, not a fix, because if so im missing something, god im cofused is there a way a to declare the methods outside the loop and call them in? I have never seen that done and wouldn't know were to start. My instructor told me to write my methods and inclose them in the do while loop. Thanks you for your help and baring with me

Nick Harms
Ranch Hand

Joined: Mar 06, 2010
Posts: 44

posted Mar 30, 2010 16:46:07

0

Just to be clear i wasn't being rude, sorry I just was making sure you didnt need more info about it from me.

You need to extract each of these (I suggest you start with the original because I explained wrong) WITHOUT the do/while and switch/case business.... and pop them OUTSIDE the main method curly braces and inside the class curly braces.

Just the methods belong in a class.
Code (that means ifs, dos, switches, etc) belongs in a method.

And, in fact, in this case, proper indentation would help you identify (or at least start to identify) where things are going crazy.

Right now you're trying to declare methods in the middle of a switch statement. That won't work. Period. No matter what your teacher says.

You can *call* methods from your switch statement, but the methods themselves still need to be declared using valid, legal Java syntax.

Your switch statement isn't even *in* a method (I'm pretty sure this was pointed out earlier). It needs to be. We're not just making up random syntax rules to mess with your head. And if your teacher told you to put the actual method declarations in essentially random places in the source... well, my first assumption would be that you've misunderstood.

The purpose of this assingment is too know how to succefully call in methods. I have already argued this is not practical, and she says that is not the purpose.

Now i have switched starting balance to balance in the call method area do i need to switch the doubles below for it to call correctly?
here is the instructions
Please write the following program using methods. All methods will be called from the main method.
Write a program titled: BankAccount. The purpose of the program is to allow the user to open a BankAccount with a starting deposit as the starting balance. The program will have methods that will allow the user to make a deposit or withdrawal. Please follow the outline below:
Main Method:
The main method will display a message to the user stating what the purpose of the program is.
The Main method will first call the Beginning balance method to determine the beginning balance and return the balance.
The main method will ask the user what type of transaction they are making (hint: Use a do while loop to display a menu and call each method based upon the choice given by the user). The methods are described below. After each method is called, the method will return the new balance and the main method will display the new balance.
Methods:
Beginning balance – Ask the user for the amount they will deposit to open the account which will be returned as the starting balance;
Deposit – When called the deposit method will receive the starting balance as a parameter and add the deposit, returning the new balance.
Withdrawal - When called the Withdrawal method will receive the starting balance as a parameter and subtract the withdrawal, returning the new balance.
Display Balance – This will be the last method called and will display the balance.
Don’t forget to pass parameters for each method to perform the task!

Nick Harms
Ranch Hand

Joined: Mar 06, 2010
Posts: 44

posted Mar 30, 2010 18:05:00

0

given the instructions I would say switching balance back to starting balance is in order, what say you?

Nick Harms
Ranch Hand

Joined: Mar 06, 2010
Posts: 44

posted Mar 30, 2010 18:08:39

0

Also

It says
switch(userChoice)
possible loss of precsion!
<-----haha jk I need a bit of humor at this point

You should buy HeadFirst Java. It's like $30 on Amazon and worth every penny. Not kidding.

And you shouldn't wait til the day before to do your homework

This is now a question of the lifecycle of references/variables.

If you pass something into a method

bar gets named (locally, inside the method) whatever the name is here:

Once it leaves, the data in this method is gone. dead. Unless 2 things happen (on a very basic level... there are exceptions).
1. the method returns something
2. you catch that return value somehow by making something equal to it

so the "startingBalance" in the parenthesis of the methods you made, is just the starting balance before the method runs. Get it?