Question: So this an add method that adds elements to an array and the elements in the array have to be sorted using the compareTo method
So this an add method that adds elements to an array and the elements in the array have to be sorted using the compareTo method this is my method for it but when i test it gives a null pointer exception is there any way this code can be edited you CANNOT use the sorts.array() at all you are to use only the compareTo method to sort the elements. the first loop is supposed to find the index where to insert the element using the compareTo() method and then the second loop is supposed to shift all the elements downward after the element is inserted. Then add the element to the array at that index. Write in java, please.
public void add(String color, int radius) { SemiCircle semi1= new SemiCircle(color,radius); for(int i=0;i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
