Advertisement
sergAccount

Untitled

Dec 19th, 2020
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.58 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 ja10;
  7.  
  8. public class JA10 {
  9.  
  10.     /**
  11.      * @param args the command line arguments
  12.      */
  13.     public static void main(String[] args) {
  14.         // TODO code application logic here
  15.         // объявляем переменную типа Car
  16.         Car c1;
  17.         Car c2;
  18.         // создаем объекта типа Car
  19.         // используем ключевое слово new для создания объекта
  20.         // переменной c1 присваиваем объект типа Car
  21.         c1 = new Car();
  22.         // объявляем переменную c3 и присваиваем объект типа Car
  23.         Car c3 = new Car();        
  24.         // вызываем метод setColor для установки цвета авто c3
  25.         // для вызова метода - используем оператор .
  26.         c3.setColor("green"); // устанавливаем красный цвет для авто c3
  27.         // выводим на экран цвет авто c3
  28.         String color1 = c3.getColor();
  29.         System.out.println("color1=" + color1);
  30.         // вызываем speedUp для авто c1
  31.         c1.speedUp(10);
  32.         c1.speedUp(20);
  33.         System.out.println("c1.speed1=" + c1.getSpeed());
  34.         c1.speedUp(30);
  35.         System.out.println("c1.speed1=" + c1.getSpeed());
  36.         c1.speedUp(-10);
  37.         System.out.println("c1.speed1=" + c1.getSpeed());
  38.         // вызываем speedUp для авто c3
  39.         System.out.println("c3.speed1=" + c3.getSpeed());
  40.         //
  41.         Car c4 = new Car();    
  42.         String color4 = c4.getColor();
  43.         System.out.println("color4=" + color4);
  44.         System.out.println("speed4=" + c4.getSpeed());
  45.         System.out.println("m4="     + c4.getM());
  46.         // используем конструктор с параметром
  47.         Car c5 = new Car("blue");    
  48.         System.out.println("color5=" + c5.getColor());
  49.        
  50.         Truck t1 = new Truck();
  51.         // t1 - переменная типа Truck  
  52.         Truck t2 = new Truck();
  53.         double d1 = t1.getCapacity();
  54.         System.out.println("d1=" + d1);
  55.         t1.setCapacity(1000);
  56.         System.out.println("d1=" + t1.getCapacity());            
  57.         t1.speedUp(20);
  58.         System.out.println("t1.speed=" + t1.getSpeed());            
  59.     }    
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement