Advertisement
sergAccount

Untitled

Dec 13th, 2020
699
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.35 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.ja9;
  7.  
  8. public class Car {
  9.     // свойства
  10.     // тек скорость, мощность, цвет, масса ...
  11.     // private - модификатор доступа
  12.     private double power;
  13.     private String color;
  14.     //
  15.     private double speed;
  16.     // не рек-ся использовать мод-к public
  17.     private double m;
  18.     //
  19.     // Конструктор класса
  20.     // конструктор класса без параметров
  21.     // public - модификатор
  22.     // имя конструктора совпадает с именем класса (Car)
  23.     public Car(){
  24.         color = "grey";
  25.     }
  26.     // конструктор класса с одинм параметром - цвет авто  
  27.     public Car(String c1){
  28.         color = c1;
  29.     }
  30.    
  31.     /*        
  32.     Добавить конструктор в класс Car с двумя параметрами - цвет и мощность авто.
  33.     В методе main создать авто с помощью нового конструктора с двумя параметрами.*/
  34.     public Car(String color, double power){
  35.         /*
  36.         color = c1;
  37.         power = p1;
  38.         */
  39.         /* setColor(c1);
  40.         setPower(p1);
  41.         */
  42.         this.color = color;
  43.         this.power = power;
  44.     }    
  45.    
  46.     // методы
  47.     // get, set - методы
  48.     // get - позовляют получать значения св-в
  49.     public double getPower(){
  50.         return power;
  51.     }
  52.     // alt + insert -
  53.     public String getColor() {
  54.         return color;
  55.     }
  56.     public double getSpeed() {
  57.         return speed;
  58.     }
  59.     // set - позовляют установить (изменить значения) для опреде-х свойств
  60.     public void setPower(double p){
  61.         power = p;
  62.     }
  63.     public void setColor(String color) {
  64.         this.color = color;
  65.     }    
  66.     // метод для ипзменения текущ скорости на значение value
  67.     public void speedUp(double value){
  68.         speed += value;
  69.     }
  70. }
  71.  
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement