Results 1 to 5 of 5
  1. #1
    turtlish is offline Member
    Join Date
    Dec 2011
    Posts
    15
    Rep Power
    0

    Default "Identifier expected" problem

    Hello! I'm new in java and I'm trying to make a programm but it keeps getting this error...what i'm doing wrong? thanks for your time!

    public class Ticket
    {
    private String q;
    private int x;
    private int y;
    private int z;
    private int id;

    public Ticket()
    { q="Random Ticket";
    x=1;
    y=2;
    z=3;
    id=0;
    }

    public Ticket (int no1,int no2, int no3,String nameOfOwner)
    {

    x=no1;
    y=no2;
    z=no3;
    q=nameOfOwner;
    System.out.println ("Your name is " +nameOfOwner);
    System.out.println ("Your first number is "+no1);
    System.out.println ("Your second number is "+no2);
    System.out.println ("Your third number is "+no3);
    }
    public Ticket (){
    int i;
    this.id=i;
    {TICKET ticket1=new.Ticket(i);
    i++}

    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: "Identifier expected" problem

    Any time you post a question about errors, please tell us which line is causing the errors, and show the actual error message itself. This will prevent us having to do a lot of guessing.

    You seem to have added a second constructor to the class with the same signature as a constructor that's already present -- both take no parameters -- and you can't do this. You can only have one constructor like that. Plus the code in this second constructor is completely borked, and I recommend that you delete it (that bit of code on the end that begins with public Ticket() {...}) and rethink your design.

  3. #3
    turtlish is offline Member
    Join Date
    Dec 2011
    Posts
    15
    Rep Power
    0

    Default Re: "Identifier expected" problem

    Oops I'm sorry I forgot it :S Ok thank you very much! I'll change it ! The problem is that I want these tickets to have an id for example 1 and every new ticket is being made I want this id to increase (example 2,3,4 etc)How can I do it?
    Last edited by turtlish; 12-07-2011 at 12:39 PM.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: "Identifier expected" problem

    The problem is that I want these tickets to have an id
    Define a static variable in the class.
    Use it to give the class its id number and increment it for the next class to have a unique number.

  5. #5
    turtlish is offline Member
    Join Date
    Dec 2011
    Posts
    15
    Rep Power
    0

    Default Re: "Identifier expected" problem

    Thank you very very much! :D

Similar Threads

  1. Replies: 4
    Last Post: 10-20-2011, 05:10 AM
  2. Replies: 3
    Last Post: 01-31-2011, 09:46 AM
  3. Replies: 3
    Last Post: 05-21-2009, 03:48 PM
  4. Replies: 3
    Last Post: 12-05-2008, 08:34 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •