Java cannot find symbol and ";" expected errors

Discussion in 'Software' started by lolwuut, Mar 16, 2013.

  1. lolwuut

    lolwuut Private E-2

    Hi everyone, heres the problem, i'm basically writing up a very very simple code for my first assignment. Its my 4th week into java programming so please excuse me if there are errors that seem noobish.

    I've got 3 classes with 4 inputs. Heres an example, the other 2 are almost the same except i have yet to add the update section. All 3 classes will compile without problems, but when i try to create an object in either, they either say cannot find symbol or ";" expected depending on what i input in the fields. I checked it over multiple times, im not missing any ";" and it compiles fine, so i have no idea what is causing this problem.

    import java.util.*;
    class Club
    {
    String name;
    String address;
    int licenseNumber;
    String registrationFee;

    Club (String newName, String newAddress, int newLicenseNumber, String newRegistrationFee)
    {
    name = newName;
    address = newAddress;
    licenseNumber = newLicenseNumber;
    registrationFee = newRegistrationFee;
    }

    void updateName()
    {
    Scanner scanner = new Scanner (System.in);
    System.out.println("Enter new name:");
    String newName = scanner.nextLine();
    System.out.println("The new name is " + newName);
    }




    }
     
  2. Adrynalyne

    Adrynalyne Guest

    Your constructor expects four inputs. You are only getting one from the Scanner object and I'd say that is part the problem. Also, your setter for name is formed incorrectly. The idea with a constructor is that you call it as such:

    In another class, you get the inputs, then:

    someClub = new Club(stringValue, stringValue, intValue, stringValue);

    It must have four inputs to correctly build the object. While we are on that subject, I'd change license to string and fee to float.
     
    Last edited by a moderator: Mar 16, 2013
  3. lolwuut

    lolwuut Private E-2

    Thanks for the help. Creating it in blueJ right now, allows me to enter the initial value for each input. The scanner is kinda of irrelevant as its for after the object has been created to change any values.

    My problem is the first section of the code,

    import java.util.*;
    class Club
    {
    String name;
    String address;
    int licenseNumber;
    String registrationFee;

    Club (String newName, String newAddress, int newLicenseNumber, String newRegistrationFee)
    {
    name = newName;
    address = newAddress;
    licenseNumber = newLicenseNumber;
    registrationFee = newRegistrationFee;
    }

    With this alone, i still cant enter the initial values to create the object.
     
  4. Adrynalyne

    Adrynalyne Guest

    Can you post the rest of your code? I feel like I am missing something. Specifically, the code you use to create the object.
     
  5. lolwuut

    lolwuut Private E-2

    been working on it since yesterday, and i got up to here, still the same problem though.

    import java.text.*;
    import java.util.*;
    class Club
    {
    String name;
    String address;
    String licenseNumber;
    float registrationFee;

    Club (String newName, String newAddress, String newLicenseNumber, float newRegistrationFee)//constructor
    {
    name = newName;//requests the intial values
    address = newAddress;
    licenseNumber = newLicenseNumber;
    registrationFee = newRegistrationFee;
    }

    void updateName()//Method to allow the updating of the name
    {
    Scanner scanner = new Scanner (System.in);//allows the input
    System.out.println("Enter new name:");//prompts the user to input the new name
    String newName = scanner.nextLine();//takes the new name and replaces the previous one
    System.out.println("The new name is " + newName);//displays the new name confirming the change to the user
    }

    void updateAddress()//Method to allow the updating of the address
    {
    Scanner scanner = new Scanner (System.in);
    System.out.println("Enter new address:");
    String newAddress = scanner.nextLine();
    System.out.println("The new address is " + newAddress);
    }

    void updateLicenseNumber()//Method to allow the updating of the license number
    {
    Scanner scanner = new Scanner (System.in);
    System.out.println("Enter new license number:");
    String newLicenseNumber = scanner.nextLine();
    System.out.println("The new license number is " + newLicenseNumber);
    }

    void updateRegistrationFee()//Method to allow the updating of the registration fee
    {
    Scanner scanner = new Scanner (System.in);
    System.out.println("Enter new registration fee:");
    String newRegistrationFee = scanner.nextLine();
    System.out.println("The new registration fee is " + newRegistrationFee);
    }



    }

    The work compiles but when i select my class and click on Club (String newName, String newAddress, String newLicenseNumber, float newRegistrationFee) to create the object, thats when it wont work. Thanks
     
  6. Adrynalyne

    Adrynalyne Guest

    Well, I think we are having a breakdown in communication.

    While there are some inherent issues with your class here (getters and setters work a little differently than you have it), the problem isn't there. It is how you are trying to create the object, which is code I haven't seen posted (hence I had asked for all code).


    I used your precise code here and was able to successfully make a Club object.



    I took your class, then added an executable method to it:

    public static void main(String[] args) {

    String license = "abc";
    String name = "jim";
    String address = "123";
    Float fee = 2f;



    Club club = new Club(name, address, license, fee);


    System.out.println(club.name);
    System.out.println(club.address);
    System.out.println(club.licenseNumber);
    System.out.println(club.registrationFee);

    }

    The output was

    jim
    123
    abc
    2.0


    Maybe this example will help you out. We have to be careful that we don't do your assignment for you ;) You understand, of course.



    https://dl.dropbox.com/u/2056318/Snapshot2.jpg
     
    Last edited by a moderator: Mar 17, 2013

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds