I am trying to do the exercise that they have sent us in class, I put the statement.
In the Runner class:
Attributes(private)
name: partner name (string)
nif: partner nif (string)
age: runner's age (integer numeric value)
numDorsal: runner number (integer numerical value). static attribute.
dorsalActivo: that indicates if the bib is active (boolean variable)
numMinutes: number of minutes it took the runner to complete the marathon. When creating each object of this type, it will be initialized to 0. Throughout the program it will be taken into account that the time cannot be less than 0 and the marathon cannot last more than 12 hours.
Methods (accessed from the same package)
· Parameterless Runner object constructor.
· Constructor of objects Constructor with three arguments that gives value to the first attributes.
· Runner object constructor with two arguments, nif and age, which you always name “Guest”.
· Corridor Object Copy Constructor.
My question: Do I have to make four builders 3 runner and one builder? How do I get to do all four options, knowing that I can't do multiple constructors with parameters? At least the program fails me.
I leave you my code:
public class Corredor {
private String nombre;
private String nif;
private int edad;
private static int numDorsal;
private boolean dorsalActivo;
private int numMinutos;
public String getNombre(){
return nombre;
}
public void setNombre(String nombre){
this.nombre=nombre;
}
public String getNif(){
return nif;
}
public void setNif(String nif){
this.nif=nif;
}
public int getEdad(){
return edad;
}
public void setEdad(int edad){
this.edad=edad;
}
public int getNumdorsal(){
return numDorsal;
}
public void setNumdorsal(int numDorsal){
this.numDorsal=numDorsal;
}
public boolean getDorsalActivo(){
return dorsalActivo;
}
public void setDorsalActivo(boolean dorsalActivo){
this.dorsalActivo=dorsalActivo;
}
public int getNumMinutos(){
return numMinutos;
}
public void setNumMinutos(int numMinutos){
this.numMinutos=numMinutos;
}
//sin argumentos
public Corredor(){
}
//con argumentos
Corredor(String nombre, String nif, int edad, int numDorsal, boolean dorsalActivo, int numMinutos){
this.nombre=nombre;
this.nif=nif;
this.edad=edad;
this.numDorsal=numDorsal;
this.dorsalActivo=dorsalActivo;
this.numMinutos=numMinutos;
}
//con los tres primeros arguemntos y aqui es donde me da fallo dado que la clase corredor está declarada
public Corredor(){
nombre="Pepe";
nif="740325679E";
edad=57;
}
}
Hello friend, your error is that you want to have two empty constructors which is not possible, I recommend that you take a look at the constructor overload topic , since it is the topic you need to solve the error. Remember that you can have several constructors as long as the parameters are different.
For example your first constructor is fine.
In the case of the second it is also fine since the parameters are different, which complies with the principles of constructor overloading.
But according to what was requested, something like this would remain.
But the error is in the third constructor that you try to make, which cannot be defined since you already have an empty constructor that is the first.
And in your statement it says `
So it has to be something like this.
And if with the last constructor and based on the documentation that I suggest you can do it without any problem.
Cheers