Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

car class java

public class Car {
    private boolean engine = true;
    private String model;
    private int wheels = 4;
    private int cylinder;
    private int doors = 4;
    private int speed;
    private int maxspeed ;

    public Car(boolean engine, String model, int wheels, int cylinder, int doors, int speed,int maxspeed) {
        this.engine = engine;
        this.model = model;
        this.wheels = wheels;
        this.cylinder = cylinder;
        this.doors = doors;
        this.speed = speed;
        this.maxspeed = maxspeed;
    }
    public void TurnOnOffEngine(boolean turn){
        if(turn){
            this.engine = true;
            System.out.println("Your start your engine");
        }System.out.println("Your engine is off");

    }

    public int Accelerate(int acceleration,int maxspeed){
        if(this.speed > 0 && this.speed<maxspeed)
        {
            this.speed += speed;
        }else
        {
            System.out.println("Illegal speed limit");
            if(acceleration>0)
            {
                System.out.println("you still have " + acceleration + " to reach your maximum speed");
            }
        }
        return this.speed;
    }
    public void stopEngine(){
        engineMode();
    }
    public void startEngine(){
        engineMode();
    }
    private void engineMode() {
        System.out.println("your engine mode is");
        if(this.engine == true){
            System.out.println("ON");
        }else{
            System.out.println("OFF");
        }
    }

    public void setSpeed(int speed,int maxspeed) {
        if(this.speed+speed < maxspeed){
            this.speed += speed;
            System.out.println("Your speed now is "+ this.speed);
        }else{
            System.out.println("Speed out of limits");
        }


    }

    public int getSpeed() {
        return speed;
    }

    public void breakCar(int speed){
        if(this.speed > speed){
            this.speed -= speed;
            System.out.println("Car has slow down,your speed now is "+this.speed);
        }else if(this.speed-speed <= 0){
            System.out.println("your car has stopped ");
        }


    }
    public boolean getEngine() {
        return engine;
    }

    public void setEngine(boolean engine) {
        this.engine = engine;
    }

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public int getWheels() {
        return wheels;
    }

    public void setWheels(int wheels) {
        this.wheels = wheels;
    }

    public int getCylinder() {
        return cylinder;
    }

    public void setCylinder(int cylinder) {
        this.cylinder = cylinder;
    }

    public int getDoors() {
        return doors;
    }

    public void setDoors(int doors) {
        this.doors = doors;
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: count occurrences of character in string java using hashmap 
Java :: boucles java 
Java :: exception in thread "main" java.lang.indexoutofboundsexception: index 1 out of bounds for length 1 
Java :: cmd java compile 
Java :: how to output sum of even numbers in java between two user values 
Java :: dequeue in java 
Java :: statusbar text color android 
Java :: how generate a random number in java between 3 and 5 
Java :: find minimum number in java 
Java :: java wait(timeout) 
Java :: write files with FileOutPutStream java 
Java :: math.absolute java 
Java :: java repository sql find not in list 
Java :: boucle for avec un tableau java 
Java :: java get attributes from class 
Java :: how to round double to 2 decimal places java 
Java :: java append a string to file 
Java :: reviews button ade android studio 
Java :: java list select field 
Java :: java program using FileOutputStream to create a file on mac 
Java :: java set value of arraylist 
Java :: register watch service java 
Java :: Java alt + f4 
Java :: How do you count characters in a string array in Java? 
Java :: do...while loop Java 
Java :: how to run java in eclipse 
Java :: GenerationTarget encountered exception accepting command : Error executing DDL 
Java :: Looping Through Array Elements Java 
Java :: $JAVA_HOME ENV 
Java :: java string vs stringbuilder 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =