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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started