Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package proggraph1;
- public class Car {
- String color;
- int speed;
- // start
- public Car(){
- }
- //
- public Car(String c){
- color = c;
- speed = 0;
- }
- // end
- public String toString(){
- return " color=" + color + " speed=" + speed;
- }
- public String getColor(){
- return color;
- }
- //
- public void setColor(String c){
- color = c;
- }
- //
- public int getSpeed(){
- return speed;
- }
- //
- public void upSpeed(int inc){
- speed = speed + inc;
- }
- public void breakSpeed(int dec){
- speed = speed - dec;
- }
- public static void main(String[] args){
- Car myCar1 = new Car();
- System.out.println("myCar1.currentSpeed=" + myCar1.getSpeed());
- System.out.println("Начальная скорость машины "+myCar1.getSpeed());
- myCar1.upSpeed(10);
- System.out.println("Скорость разгона "+myCar1.getSpeed());
- myCar1.breakSpeed(5);
- System.out.println("Скорость торможения "+myCar1.getSpeed());
- myCar1.setColor("red");
- System.out.println("myCar1.color=" + myCar1.getColor());
- //
- //Car myCar2 = new Car();
- //myCar2.setColor("blue");
- //System.out.println("myCar2.color=" + myCar2.getColor());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement