I am practicing with a program to read data from a Pseudo Speed and Pressure sensor using getters and setter. As the sensor does not exist, the values that the user enters via the reader from the main method have been assigned.
The exercise explicitly asks that the class must have two constructors and I do not know how to get there. At the moment I have this code that works quite well. But it does not fulfill the request to have two constructors, or at least I can not see it.
package sensores;
public class Auto {
private double angularSpeed;
private double pres;
private String name;
public Auto()
{
}
public double getSpeed()
{
return angularSpeed;
}
public void setSpeed(double s)
{
angularSpeed = s;
}
public double getPres()
{
return pres;
}
public void setPres(double p)
{
pres = p;
}
public String getName(){
return name;
}
public void setName(String n){
name = n;
}
}
I understand that I could create a second constructor like that.
public Auto(double speed, double pres){
this.pres = pres;
this.speed = speed;
}
This would serve to assign the setters, but the getters are left out ... can this be done? and if so, how do I implement the getters?