Create a class Vehicle. It should have noofwheele (Integer), maxspeed (float), a
ID: 3772023 • Letter: C
Question
Create a class Vehicle. It should have noofwheele (Integer), maxspeed (float), and color (string) as Instance variables. It's constructor must take in three parameters, an integer, a float and a string, and set the instance variables to those values. It should also have a function called calculateTollO that returns the toll to be paid by that car. The toll Is 15 middot the number of wheels. Final create functions getnoofwheels(). getmaxspeedO. and getcolorO that return the noofwheels, maxspeed. and col or respectively.Explanation / Answer
Here is the class for you. If you have any further queries, just get back to me.
import java.io.*;
class Vehicle //Vehicle class.
{
int noOfWheels; //noOfWheels of type integer.
float maxSpeed; //maxSpeed of type float.
String color; //color of type String.
Vehicle(int no, float max, String clr) //A constructor which takes, 3 parameters as input, and initializes the private variables.
{
noOfWheels = no;
maxSpeed = max;
color = clr;
}
int calculateToll() //calculateToll() function which returns the value 15 * noOfWheels as the toll to be paid.
{
return 15 * noOfWheels;
}
int getNoOfWheels() //Accessor for the noOfWheels value.
{
return noOfWheels;
}
float getMaxSpeed() //Accessor for the maxSpeed value.
{
return maxSpeed;
}
String getColor() //Accessor for the getColor value.
{
return color;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.