Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Car
- {
- String brand;
- String colour;
- double engineSize;
- double currentSpeed;
- public Car(String b, String c, double es, double cs)
- {
- if (es < 1.0)
- {
- es = 1.0;
- }
- this.brand = b;
- this.colour = c;
- this.engineSize = es;
- this.currentSpeed = cs;
- }
- public String getCategory()
- {
- String category = "";
- if (engineSize < 1.3)
- {
- category = "small";
- }
- else if ((engineSize > 1.3) && (engineSize < 2.5))
- {
- category = "medium";
- }
- else if (engineSize > 2.5)
- {
- category = "large";
- }
- return category;
- }
- public void brake ()
- {
- if (currentSpeed > 0)
- {
- currentSpeed = currentSpeed - 1;
- }
- else if (currentSpeed == 0)
- {
- currentSpeed = 0;
- }
- }
- public void accelerate()
- {
- if (currentSpeed == 0)
- {
- currentSpeed = 1;
- }
- else
- {
- currentSpeed = currentSpeed * engineSize / 10;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement