Hi Here is my following problem:
I have 3 fields:
yearModel
make
speed
the class is labeled Car.
I must create a cosntructor thast accepts the cars year model and make as arguments. these values should be asssigned to the objects yearModel and make fields. the constructor should also assign 0 to the speed field.
I must create get methods that get the values stored in yearmodel make and speed fields
i must create an accelerate method that should add 5 to the speed each time it is called
i must also create a brake method that will minus 5 to the speed each time it is called
I must demonstrate this class in a program that calls the accelerate method 5 times. after each time it is called i must get the current speed and display it.
then i must call the brake method 5 times and after each time it is called get the current speed and display it.
I think i have the class set up correctly but not sure: I also am not quite sure how to start the program and how to execute propely. mainly how to call the methods in the program.
package CAR_PKG;
public class car {
private int yearModel;
private String make;
private int speed;
public car(int year, String m, int s){
yearModel=year;
make=m;
speed=s;
speed=0;
}
public int getyearModel()
{
return yearModel;
}
public String getmake()
{
return make;
}
public int getspeed()
{
return speed;
}
public int accelerate(int s){
int sum=s+5;
return sum;
}
public int brake(int s){
int sub=s-5;
return sub;
}
}