Advertisement
sergAccount

Untitled

Mar 12th, 2016
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 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 proggraph1;
  7.  
  8. public class Car {
  9.    
  10.     String color;
  11.     int speed;
  12.    
  13.     // start
  14.     public Car(){
  15.      
  16.     }
  17.     //
  18.     public Car(String c){
  19.         color = c;
  20.         speed = 0;
  21.     }    
  22.     // end
  23.    
  24.    
  25.     public String toString(){
  26.         return " color=" + color + " speed=" + speed;
  27.     }
  28.    
  29.     public String getColor(){
  30.         return color;
  31.     }    
  32.     //
  33.     public void setColor(String c){        
  34.         color = c;
  35.     }    
  36.     //
  37.     public int getSpeed(){
  38.         return speed;
  39.     }
  40.     //
  41.     public void upSpeed(int inc){
  42.         speed = speed + inc;
  43.     }    
  44.     public void breakSpeed(int dec){
  45.         speed = speed - dec;
  46.     }
  47.    
  48.     public static void main(String[] args){
  49.         Car myCar1 = new Car();
  50.         System.out.println("myCar1.currentSpeed=" + myCar1.getSpeed());        
  51.         System.out.println("Начальная скорость машины "+myCar1.getSpeed());
  52.         myCar1.upSpeed(10);
  53.         System.out.println("Скорость разгона  "+myCar1.getSpeed());
  54.         myCar1.breakSpeed(5);
  55.         System.out.println("Скорость торможения "+myCar1.getSpeed());
  56.         myCar1.setColor("red");
  57.         System.out.println("myCar1.color=" + myCar1.getColor());        
  58.         //        
  59.         //Car myCar2 = new Car();
  60.         //myCar2.setColor("blue");        
  61.         //System.out.println("myCar2.color=" + myCar2.getColor());        
  62.        
  63.        
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement