Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Help with transaction assignment

  1. #1
    Member
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with transaction assignment

    import javax.swing.JOptionPane;
    public class Assignment1 
    {
     
     
     
           public static CheckingAccount info;
     
     
     
         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)
            {
     
             double tamount;
             tamount = getTransAmt();
     
     
             message = "Transaction: Check in the amount of $" + tamount+
                     "\n" +
                       "Current balance: $" + 
     
     
            public static int getTransCode()
            {
                int tcode;
                String transcode;
                transcode = JOptionPane.showInputDialog ("Enter your transaction" + 
                       " code:");
                 tcode = Integer.parseInt(transcode);
     
                 return tcode;
            }
     
            public static double getTransAmt()
            {
                  double tamount;
                  String transamount;
             transamount = JOptionPane.showInputDialog ("Enter your trans amount:");
             tamount = Double.parseDouble(transamount);
     
             return tamount;
            }
     
            public static _________ processCheck(___________)
            {
            }
            public static __________ processDeposit(___________)
            {
            }
     
     
     
     
        }
    }



    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?


    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?


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Help with transaction assignment

    You've got lines of code that don't end, methods nested inside of methods, ... sorry to blunt, but it looks to be a real mess.

    Consider starting over, but compiling frequently, and making sure you fix all compilation errors before adding new code.

  3. #3
    Member
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with transaction assignment

    Quote Originally Posted by curmudgeon View Post
    You've got lines of code that don't end, methods nested inside of methods, ... sorry to blunt, but it looks to be a real mess.

    Consider starting over, but compiling frequently, and making sure you fix all compilation errors before adding new code.

    The messiness is due to the fact that my instructor provides us with a sample code, thus those helper methods were provided but not filled out.

  4. #4
    Member
    Join Date
    Jun 2012
    Location
    Left Coast, USA
    Posts
    451
    My Mood
    Mellow
    Thanks
    1
    Thanked 97 Times in 88 Posts

    Default Re: Help with transaction assignment

    Quote Originally Posted by alex067 View Post
    .
    .
    .
            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.

    Quote Originally Posted by alex067 View Post
    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
    Last edited by Zaphod_b; October 2nd, 2012 at 01:14 AM.

Similar Threads

  1. Need help with Assignment
    By gakon3445 in forum Algorithms & Recursion
    Replies: 5
    Last Post: September 14th, 2012, 12:55 PM
  2. assignment troubles polymorphism (guide for assignment included)
    By tdawg422 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 8th, 2011, 10:01 AM
  3. need help on an assignment :(
    By gamfreak in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 23rd, 2010, 04:20 PM
  4. Replies: 1
    Last Post: February 22nd, 2010, 08:20 AM
  5. Need help with assignment
    By TonyL in forum Loops & Control Statements
    Replies: 2
    Last Post: February 20th, 2010, 09:44 PM