168k views
2 votes
"Write a class named Car that has the following data attributes:" _ _year_model (for the car’s year model) _ _make (for the make of the car) _ _speed (for the car’s current speed)

1 Answer

0 votes

Answer:

public class Car {

private String __year_model;

private String __make;

private int __speed;

//Creating the constructor

public Car(String __year_model, String __make, int __speed) {

this.__year_model = __year_model;

this.__make = __make;

this.__speed = __speed;

}

//Creatining the set and get methods

public String get__year_model() {

return __year_model;

}

public void set__year_model(String __year_model) {

this.__year_model = __year_model;

}

public String get__make() {

return __make;

}

public void set__make(String __make) {

this.__make = __make;

}

public int get__speed() {

return __speed;

}

public void set__speed(int __speed) {

this.__speed = __speed;

}

}

Step-by-step explanation:

As stated in the question, The class Car is created using Java programming language with the three attributes year_model, make and speed.

Constructors as well as set and get methods were also created for each of the fields.

User Joesdiner
by
4.9k points