Question: write a Java class named Car.java to represent a Car type with the following field: speed (private)- The speed field is an double that holds
write a Java class named Car.java to represent a Car type with the following field: speed (private)- The speed field is an double that holds a cars current speed (e.g. 25.0) In addition, the Car class should have the following methods. Constructor The constructor should accept the beginning speed as argument Getter Methods Write a accessor (getter) method to get the speed value stored in an object field: getSpeed() accelerate Write an accelerate method that has no arguments (parameters) passed to it and adds 1 to the speed field each time it is called For example: if the car was going 3 mph, accelerate would set the speed to 4 mph Note: the valid speed range is [e, 100]. The car speed cannot be negative or over 100mph. If a client tried to set invalid speed, your program should set to default value: 50 mph
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
