In: Computer Science
1. Implement the Vehicle class.
Add the following private instance variables to the Accoun class:
• An instance variable called wheelsCount of type int
• An instance variable called vType of type String
• An instance variable called isTruck of type boolean .
Add getters and setters for the three instance variables
Add the following methods to the Account class:
• A void method called initialize that takes a parameter of type int, a String,and one double and uses those arguments to set the values of the WheelsCount VType,and isTruck instance variables.
• A void method called display that displays the vehicle information
• A boolean method called equals with one parameter of type Vehicle.This method must return true if all instance variables of the given objects equal to the instance variables of the current object (this object).
In the main method of your main class, create two Vehicle objects and perform the following:
• Initialize the first and second objects with your own parameter values.
• Display both vehicles • Use the == to compare the two vehicle objects and display the result.
• Use the equals method for the first object, compare it with the second vehicle as the parameter to the method and display the result.
Run the main program to see if the tests were successful.
• Here is a sample output of the program.
First Vehicle:
Vehicle Type: Ford F150
Wheels Count: 4
is Truck: true
Second Vehicle:
Vehicle Type: Ford F150
Wheels Count: 4
is Truck: true
v1 is NOT equal to v2 using ==
v1 is equal to v2 using equals method
Note:
If you are a beginner I will help you in executing the code.
Could you plz go through this code and let me know if u need any
changes in this.Thank You
=================================
// Vehicle.java
public class Vehicle {
// Declaring instance variables
private int wheelsCount;
private String vType;
private boolean isTruck;
/**
* @return the wheelsCount
*/
public int getWheelsCount() {
return wheelsCount;
}
/**
* @param wheelsCount
* the wheelsCount to set
*/
public void setWheelsCount(int wheelsCount) {
this.wheelsCount =
wheelsCount;
}
/**
* @return the vType
*/
public String getvType() {
return vType;
}
/**
* @param vType
* the vType to set
*/
public void setvType(String vType) {
this.vType = vType;
}
/**
* @return the isTruck
*/
public boolean isTruck() {
return isTruck;
}
/**
* @param isTruck
* the isTruck to set
*/
public void setTruck(boolean isTruck) {
this.isTruck = isTruck;
}
public void initialize(int noOfWheels, String
vType, boolean isTruck) {
this.wheelsCount =
noOfWheels;
this.vType = vType;
this.isTruck = isTruck;
}
public void display() {
System.out.println("Vehicle Type :"
+ vType);
System.out.println("Wheels Count :"
+ wheelsCount);
System.out.println("is Truck :" +
isTruck);
}
// This method will check whether the two vehicle
class objects are equal or not
public boolean equals(Vehicle v) {
if
(vType.equalsIgnoreCase(v.getvType())
&& wheelsCount == v.getWheelsCount()
&& isTruck == v.isTruck()) {
return
true;
} else {
return
false;
}
}
}
====================================
====================================
// Tester.java
public class Tester {
public static void main(String[] args) {
Vehicle v1 = new
Vehicle();
v1.initialize(4, "Ford F150",
true);
Vehicle v2 = new
Vehicle();
v2.initialize(4, "Ford F150",
true);
System.out.println("First
Vehicle:");
v1.display();
System.out.println("Second
Vehicle:");
v2.display();
if (v1 == v2)
{
System.out.println("v1 is equal to v2 using ==");
} else {
System.out.println("v1 is NOT equal to v2 using ==");
}
if (v1.equals(v2))
{
System.out.println("v1 is equal to v2 using equals method");
} else {
System.out.println("v1 is NOT equal to v2 using equals
method");
}
}
}
====================================
====================================
Output:
=====================Could you plz rate me well.Thank You