Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package carproject;
- //if i missed something or if you don't understand something don't hesitate to ask --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 <50)//wouldnt work with overloaded speed increase(ie accelarate(3) could get above 50)
- speed += staticValue;//shorter + again not sure of that static value
- }
- public void accelarate(int speeds) { // method overloading
- if (speed <50)
- speed += speeds;
- }
- public void brake ()
- {
- if (speed >0)//wouldnt work with overloaded speed increase(ie brake(-3) could get under 0)
- speed -= staticValue;//shorter + again not sure of that static value
- }
- public void brake(int speeds) { // method overloading
- if (speed >0)
- speed -= speeds;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment