Advertisement
sergAccount

Untitled

Feb 7th, 2021
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.17 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package com.mycompany.ja7;
  7.  
  8. public class Car {
  9.     // свойства
  10.     // цвет, масса, текущая скорость авто
  11.     // цвет
  12.     private String color;
  13.     // масса
  14.     private double m;
  15.     //текущая скорость авто
  16.     private double speed;    
  17.     // двигатель авто
  18.     private Engine engine;
  19.     // конструкторы класса
  20.     // конструктор класса без параметров
  21.     public Car(){
  22.         color = "grey";
  23.     }
  24.     // конструктор класса c параметрами - масса и цвет авто  
  25.     public Car(double m, String color){
  26.         this.m = m;
  27.         this.color = color;
  28.     }
  29.     // конструктор класса c параметрами - масса и цвет авто  
  30.     public Car(double m, String color, Engine engine){
  31.         this.m = m;
  32.         this.color = color;
  33.         this.engine = engine;
  34.     }
  35.     //
  36.     public Engine getEngine() {
  37.         return engine;
  38.     }
  39.     public void setEngine(Engine engine) {
  40.         this.engine = engine;
  41.     }
  42.    
  43.     // методы
  44.     // get, set - методы
  45.     // get
  46.     public String getColor(){
  47.         return color;
  48.     }
  49.     // Alt+Insert
  50.     public double getM() {
  51.         return m;
  52.     }
  53.     public double getSpeed() {
  54.         return speed;
  55.     }    
  56.     //
  57.     public void setColor(String color) {
  58.         this.color = color;
  59.     }
  60.  
  61.     public void setM(double m) {
  62.         this.m = m;
  63.     }
  64.    
  65.     // Скорость автомобиля не должна быть отрицательной! (должна быть всегда >=0)
  66.     // метод для изменения текущей скорости авто на определенное значение
  67.     public void speedUp(double value){
  68.         //speed = speed + value;
  69.         speed+= value;
  70.         if(speed<0){
  71.             speed = 0;
  72.         }
  73.     }
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement