Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package carproject;
- //fixed the issue + found a typo could be the source to your error --verd
- public class Car
- {
- private int speed; //they way I got it taught is that you don't capitalize the first letter of the variables(lowerCamelCase)
- private String make;
- private int yearModel;
- private static int staticValue = 5;// not sure what was meant with static value 5 (if it is like this normally i finalize it)
- public Car() { // this is constructor overloading
- speed=50;
- make = "Subaro";
- yearModel = 2016;
- }
- public Car (String n, int Model) //speed to 0
- {
- make = n;
- yearModel = Model;
- speed = 0;
- }
- public Car (String n, int Model,int speeds) // this is constructor overloading
- {
- make = n;
- yearModel = Model;
- speed = speeds;
- }
- public int getyearModel ()
- {
- return yearModel;
- }
- public String getMake ()
- {
- return make;
- }
- public int getSpeed ()
- {
- return speed;
- }
- public void accelerate ()
- {
- if (speed+staticValue <50)//wouldnt work with overloaded speed increase(ie accelarate(3) could get above 50) + fixed condition issue
- speed += staticValue;//shorter + again not sure of that static value
- }
- public void accelerate(int speeds) { // method overloading + fixed condition issue + fixed typo could be the source to your error my bad
- if (speed+speeds <50)
- speed += speeds;
- }
- public void brake ()
- {
- if (speed-staticValue >0)//wouldnt work with overloaded speed increase(ie brake(-3) could get under 0) + fixed condition issue
- speed -= staticValue;//shorter + again not sure of that static value
- }
- public void brake(int speeds) { // method overloading + fixed condition issue
- if (speed-speeds >0)
- speed -= speeds;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment