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;i0;index--) { semi[index+1]=semi[index]; } } semi[numSemiCircle]=semi1; numSemiCircle++; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!