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: Extremely Simple Problem... Im new. (illegal start of expression)

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Extremely Simple Problem... Im new. (illegal start of expression)

    Taking a java class, and have a online friend who has been tutoring me, who normally answers my questions... But isnt online now... So thought Id give this forum a try for some help maybe... I have no idea what I am doing wrong here...

    /**
     * Lesson 3
     * 
     * @author 
     * @version 
     */
    //Create a class called BankAccount
    public class BankAccount
    {
        // The class should have the following fields:
        private int accountNo;
        private float balance;
        private String firstName, lastName;
     
        // The class should have ONE constructor with two String parameters: first and last
        public BankAccount(String first, String last){
            balance = 100;
            accountNo = 12345;
            firstName = first;
            lastName = last;
        }
     
        // Create a mutator method called deposit...
        public void deposit(int depositAmount)
        {
            if(depositAmount < 0) {
                System.out.println("Invalid deposit amount");
            }
            else {
                balance = balance + depositAmount;        
        }
     
        // Create a mutator method called withdraw...
        public void withdraw(int withdrawAmount)
        {
            if(withdrawAmount < 0) {
                System.out.println("Invalid deposit amount");
            }
            else if (withdrawAmount > balance) {
                System.out.println("Insufficient funds to complete withdraw request");
            }
            else {
                balance = balance - withdrawAmount;        
        }
     
        // Create a mutator method called changeFirst...
        public void changeFirst(String first)
        {
            firstName = first;
            System.out.println("First name has been changed to: " + firstName);
        }
     
        // Create a mutator method called changeLast...
        public void changeLast(String last)
        {
            lastName = last;
            System.out.println("Last name has been changed to: " + lastName);
        }
     
        // Create the accessor method showBal...
        public void showBal()
        {
            System.out.println(balance);
        }
     
        // Create the accessor method accInfo...
        public void accInto()
        {
            System.out.println("Account No: " + accountNo);
            System.out.println("Account Owner: " + firstName + " " + lastName);
            System.out.println("Account Balance: " + balance);
     
    }


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    983
    Thanks
    7
    Thanked 207 Times in 183 Posts

    Default Re: Extremely Simple Problem... Im new. (illegal start of expression)

    Accidental douple post - sorry I removed this while HW was dealing to the other one... Hopefully sorted now.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Extremely Simple Problem... Im new. (illegal start of expression)

    Sorry about that, new to the forums, and the first time I didnt see that it said my post had to be approved by a mod, so I thought I just did something wrong and it didnt post... Plus my first one did not use the java code highlight option like I was supposed to.

    --- Update ---

    God damn brackets. Figured it out.

  4. #4
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    983
    Thanks
    7
    Thanked 207 Times in 183 Posts

    Default Re: Extremely Simple Problem... Im new. (illegal start of expression)

    Hi Zea, welcome to the forum!

    The software *sometimes* holds posts pending approval. It shouldn't keep happening.

    I was unable yesterday to actually read the post fully, and so couldn't really help. But I'm glad you've got the brackets sorted out (The usual cause of that error)

Similar Threads

  1. Need HELP! Illegal start of expression & while expected..
    By Zaki in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 15th, 2012, 04:22 PM
  2. PROBLEM: ILLEGAL START OF EXPRESSION
    By zerfgog in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 29th, 2012, 07:24 AM
  3. illegal start of expression error!!!!
    By aks.1393 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 14th, 2011, 08:47 AM
  4. Illegal Start of Expression Error. Any help is appreciated.
    By SKhoujinian91 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 8th, 2009, 12:57 AM