VerdommeMan

the car

Sep 19th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. package carproject;
  2. //if i missed something or if you don't understand something don't hesitate to ask --verd
  3. public class Car
  4. {
  5.     private int speed; //they way I got it taught is that you don't capitalize the first letter of the variables(lowerCamelCase)
  6.     private String make;
  7.     private int yearModel;
  8.     private static int staticValue = 5;// not sure what was meant with static value 5 (if it is like this normally i finalize it)
  9.    
  10.     public Car() { // this is constructor overloading
  11.        
  12.         speed=50;
  13.         make = "Subaro";
  14.         yearModel = 2016;
  15.     }  
  16.     public Car (String n, int Model) //speed to 0
  17.     {  
  18.         make = n;
  19.         yearModel = Model;
  20.         speed = 0;
  21.     }
  22.    
  23.     public Car (String n, int Model,int speeds) // this is constructor overloading
  24.     {  
  25.         make = n;
  26.         yearModel = Model;
  27.         speed = speeds;
  28.     }
  29.    
  30.     public int getyearModel ()
  31.     {
  32.         return yearModel;
  33.     }
  34.    
  35.     public String getMake ()
  36.     {
  37.         return make;
  38.     }
  39.    
  40.     public int getSpeed ()
  41.     {
  42.         return speed;
  43.     }  
  44.        
  45.     public void accelerate ()
  46.     {
  47.         if (speed <50)//wouldnt work with overloaded speed increase(ie accelarate(3) could get above 50)
  48.             speed += staticValue;//shorter + again not sure of that static value
  49.     }
  50.     public void accelarate(int speeds) { // method overloading
  51.        
  52.         if (speed <50)
  53.             speed += speeds;
  54.     }
  55.    
  56.     public void brake ()
  57.     {
  58.         if (speed >0)//wouldnt work with overloaded speed increase(ie brake(-3) could get under 0)
  59.             speed -= staticValue;//shorter + again not sure of that static value
  60.     }
  61.     public void brake(int speeds) { // method overloading
  62.        
  63.         if (speed >0)
  64.             speed -= speeds;
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment