"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++}
}
}
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.
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?
Re: "Identifier expected" problem
Quote:
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.
Re: "Identifier expected" problem
Thank you very very much! :D