Home /
Expert Answers /
Computer Science /
question-8-a-why-would-a-class-implement-the-comparable-interface-what-is-the-method-of-the-comp-pa957
(Solved): QUESTION 8 (a) Why would a class implement the Comparable interface? What is the method of the Comp ...
QUESTION 8 (a) Why would a class implement the Comparable interface? What is the method of the Comparable interface? (4 marks) (b) Given below is a class Car that has attributes Make and regNum. Your task is to rewrite the code so that it implements the Comparable interface. The ordering is based on regNum only. public class Car \{ private String make, regNum; public Car(String \( m \), String \( n \) ) \{ make \( =m \); regNum \( =n \); \} public String makeO \{ return make; \} public String regNum0 0 return regNum; \} public void setMake(String m) make=m; \} public void setRegNum(String \( n \) ) \{ \} regNum=n; public String toString 0 \{ return make +" - "+ regNum; \} \}