Originally Posted by
alex067
.
.
.
for(int i = 0; i < 3;, ++i)
.
.
.
I'm having an error at the for loop; for(int = i; i < 3; ++i) it's saying that it's an illegal start of an expression?
But that is not what is actually in your code. Look again. I mean really
look.
Originally Posted by
alex067
Also at the getTranscode helper method, an error states that it "reached end of file while paraphrasing" and "illegal start of an expression"
What does this mean?
It means that your code is totally screwed up. Part of the first message is related to the fact that you have more opening '{' braces than closing '}' braces.
The messages together mean that your code looks like the dog's dinner (the one that he barfed up on the sidewalk last night), and the compiler won't even try to help you out of the mess.
Well...
Don't panic! Help is on the way. (At least I hope to be able to get you started.)
Some absolute rules for occurrence of {} braces in Java:
All function (method) bodies begin with a '{' opening brace and end with a '}' closing brace.
All blocks within functions begin with a '{' opening brace and end with a '}' closing brace. (Not all statements have to be inside a block.)
Certain other program constructs are also delimited by balanced pairs of {} braces.
All functions are self-contained. That is, you can not have a function defined inside another function.
Blocks can be totally nested within other blocks but blocks can never overlap.
Braces must always be balanced.
Here's how to inspect balance of braces with a counter in your head.
Note that I am talking about braces that are part of the program. Braces inside Strings (delimited by a pair of double " quote marks) and braces that are literal characters (inside single ' quote marks) do not count.
Anyhow...
Set the counter in your head to zero.
Every time you encounter a '{', increment the counter in your head.
Every time you encounter a '}', decrement the counter in your head.
The counter in your head must never go negative. If it does, you have overlapped or nested your blocks in some illegal fashion, and this must be fixed before proceeding.
The counter in your head must be exactly zero at the end of the file, since braces occur in pairs.
Suggested stylistic "rules" to make it easier for humans to follow your code structure, and, if you do it consistently, you won't have to go through the counting-in-your-head routine that I described above. (Also if you use a text editor with auto-indent features, don't fight it. Turn on auto-indent and let it do the work. You can fine-tune special cases that you want to format slightly differently, but try to be consistent.)
Every time you encounter a '{', indent the following lines by a certain number of spaces (I use four spaces for the "shiftwidth" for block indentation) until you encounter that brace's matching '}'
If you have nested blocks, inner blocks are indented more than outer blocks. The compiler ignores indentation in Java, but it really helps humans (yourself as well as others who might be recruited to ponder your code) if you are consistent in your use of braces and indentation.
Now, here's the thing: If your instructor was lousy, then boo-hoo. I mean, I don't know about you, but no one ever guaranteed to me that the Universe is fair. Sorry. Try to leave the bitterness behind. (It's called spiritual development. It is good for the soul as well as for your physical health. At least that's what they tell me. I'm still working on it.)
I applaud you for having the self-motivation for trying to "get it right" in spite of your previous bad experience. Really. Sitting here in my room, all by myself, I just took my hands off the keyboard and applauded.
Look at examples in your book. Find tutorials that show good code. See if you can make your code as "pretty" as the good examples you see. This is not a Small Thing just for some vain cosmetic appeal; it is a Big Thing, since, in my opinion, making the structure and flow of the program obvious at-a-glance is the most important single debugging aid that is outside of your head.
Now, I'll help you get started. I'll pull out your separate function definitions. They can go in any order. They can all go before main(). They can all go after main(). Some can come before and some can come after. Bada-bing, bada-boom. But they all must be separated.
Anyhow...
import javax.swing.JOptionPane;
public class Assignment1 {
public static CheckingAccount info;
public static int getTransCode() {
int tcode;
String transcode;
transcode = JOptionPane.showInputDialog ("Enter your transaction" +
" code:");
tcode = Integer.parseInt(transcode);
return tcode;
} // End getTransCode
public static double getTransAmt() {
double tamount;
String transamount;
transamount = JOptionPane.showInputDialog ("Enter your trans amount:");
tamount = Double.parseDouble(transamount);
return tamount;
} // End getTransAmt
public static _________ processCheck(___________)
{
} // End whatever...
public static __________ processDeposit(___________)
{
} // End whatever...
public static void main(String[] args) {
String balance, transcode, transamount, message;
CheckingAccount info;
double ibalance;
balance = JOptionPane.showInputDialog ("Enter your initial balance: ");
ibalance = Double.parseDouble(balance);
info = new CheckingAccount(ibalance);
do {
int tcode;
tcode = getTransCode();
for(int i = 0; i < 3;, ++i) { //<---Syntax error here
double tamount;
tamount = getTransAmt();
// From Zaphod_b: The following needs a little work, right?
message = "Transaction: Check in the amount of $" + tamount+
"\n" +
"Current balance: $" +
} //End for
} // End do
// |
// | From Zaphod_b
// | What the heck happened to the closing brace for main()
// V and the closing brace for the class definition?
Now, I have used the style convention that lots of Java programmers seem to prefer: Put the opening '{' brace on the same line as the beginning statement.
On the other hand, lots of people use another convention: Put the opening '{' on the next line.
Well, I say, "Chacun à son goût," about that, but the important thing is that each block begins and ends at the same column, and statements inside each block are indented more than the beginning and ending pair of {} braces.
Note that I also put comments on the lines with the closing '}' braces to remind me what block I intended to be delimited. I don't always do that, especially if the block is short enough and none of the lines are so long that they wrap around in a visually confusing manner.
Judicious use of whitespace in expressions and occasional blank lines to separate different pieces of the code can make it more readable, but random multiple blank lines and inconsistent indentation and other spacing is quite distracting (and just plain butt-ugly).
Bottom line:
Develop your own style according to your own taste, but I respectfully suggest that you stick to one of the common forms that you see in books and in good tutorials. You will thank me later.
Cheers!
Z