Write code for a JAVA class for a "Car". The Car class has 2 properties: modelType and currentSpeed. Make sure to write code for instance variables (the properties), getters/setters and a default constructor, overloaded constructor. ALSO, include one method called "accelerate" that increases the speed by "1.0" miles per hour
//Car.java public class Car { private String modelType; private String currentSpeed; public Car() { } public Car(String modelType, String currentSpeed) { this.modelType = modelType; this.currentSpeed = currentSpeed; } public String getModelType() { return modelType; } public void setModelType(String modelType) { this.modelType = modelType; } public String getCurrentSpeed() { return currentSpeed; } public void setCurrentSpeed(String currentSpeed) { this.currentSpeed = currentSpeed; } public String toString() { return "Car{" + "modelType='" + modelType + '\'' + ", currentSpeed='" + currentSpeed + '\'' + '}'; } void accelerate(){ currentSpeed += 1; } }
Get Answers For Free
Most questions answered within 1 hours.