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

Write the code for the ColorConstants interface. This interface should declare c

ID: 3696272 • Letter: W

Question

Write the code for the ColorConstants interface. This interface should declare constants for the colors red, white, and black and assign the int values 1, 2, and 3 to those constants. Write the code for the AutoReader interface. This interface should declare two methods. The first one, named getAuto, should accept an id and return an Automobile object for the automobile with that id. The second one, named getAutosByColor, should accept an integer that represents a color in the ColorConstant interface and return a string that contains the ids of all the automobiles that are that color. Write the code for the AutoTextFile class. Simulate the getAuto method by creating a new Automobile object with the id that's passed to the method. Don't worry about setting the values of the other instance variables. Simulate the getAutosByColor method by using a switch statement to return a string of numbers depending on which color is specified (you choose the numbers). If an invalid color number is specified, return a null.

Explanation / Answer

interface ColorConstants // interface colorconstants

{

final int red=1; // red constant variable if you declare variable as final it would becom constant

final int white=2;

final int black=3;

}

interface AutoReader // interface AutoReader

{

public Automobile getAuto(int id); // method getAuto

public String getAutosByColor(int color); // method getAutosByColor

}

class AutoTextFile extends Automobile implements AutoReader // AutoTxtFile implementing AutoReader interface extends Automobile class based on the diagram

{

int id=111;

Automobile object=new Automobile(id); // creating object of Automobile

public Automobile getAuto(int id) // implementing interface methods here

{

Automobile auto=new Automobile(id);

return auto; // returning auto -Automobile object with id

}

public String getAutoByColor(int color) // implementing getAutoColor method that returns string

{

switch(color) // switch for specified color

{

case 1: System.out.println("Red color automobile ids");

return "All ids of automobiles which are red in color"; // Here you can return the ids of that color with full implementations of the all classes and codes

break;

case 2: System.out.println("White color automobiles ids");

return "All ids of automobiles which are white in color";

break;

case 3: System.out.println("Black color automobiles ids");

return "All ids of automobiles which are Black in color";

break;

default: return null; // if no color specified returning null value

}

}

}