Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Java NetBeans project. Make sure including your OUTPUT. Make sure the c

ID: 3860323 • Letter: C

Question

Create a Java NetBeans project. Make sure including your OUTPUT. Make sure the code will work in NetBeans IDE 8.0.2.

Write a class named CarPlate encapsulating the concept of a car license plate, assuming that it has the following attributes: the plate number, the state, and its color. Write a client program that creates three CarPlate objects and writes them to a file as objects, then reads them from the file as objects, outputs a description of each of the objects using the toString method (which the CarPlate class should override), and outputs the number of objects. When reading the objects, you should assume that you do not know the number of objects in the file and detect the end of file when an EOFException is thrown by the readObject method.

Explanation / Answer

Code:

public class CarPlate
{
  
private String plateNumber;
private String plateState;
private String plateColor;

public CarPlate()
{

plateNumber="";
plateState="";
plateColor="";

}
public CarPlate(String num, String state, String color)
{
setPlate(num, state, color);

}
public String toString()
{

return ("Plate number" is a "
+plateState+" " + " plate that is "+plateColor+" in color.");
  

}
public boolean equals(Object o)
{
CarPlate plate = (CarPlate) o;
return plateState.equals(plate.plateState) && plateNumber.equals(plate.plateNumber);
}
public void setPlate(String num, String state, String color)
{
  
plateNumber=num;
plateState=state;
plateColor=color;
  
}

public String getPlateNumber(String num)
{
return plateNumber;
}
public String getPlateState(String state)
{
return plateState;
}
public String getPlateColor(String color)
{
return plateColor;
}
}