Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. package kwiecien.dziewiaty;
  2.  
  3. public class Car {
  4.     String name;
  5.     String color;
  6.     String engine;
  7.     int speed; // predkosc
  8.  
  9.  
  10.     public Car() {
  11.     }
  12.  
  13.     public Car(String name, String color, String engine, int speed) {
  14.         this.name = name;
  15.         this.color = color;
  16.         this.engine = engine;
  17.         this.speed = speed;
  18.     }
  19.  
  20.     public void printCar() {
  21.         System.out.println("Nazwa: " + name + ", kolor: " + color + ", silnik: " + engine);
  22.     }
  23.  
  24.     public void switchCarName(String name) {
  25.         this.name = name;
  26.     }
  27.  
  28.     public void driveFast() throws InterruptedException {
  29.         int actualSpeed = 0;
  30.         for (int i = 0; actualSpeed < speed; i++) {
  31.             Thread.sleep(5000);
  32.             actualSpeed += 100;
  33.             System.out.println("Obecna prędkość wynosi: " + actualSpeed + " km/h");
  34.         }
  35.     }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement