Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

Students also viewed these Databases questions

Question

Describe voluntary benefits.

Answered: 1 week ago

Question

What is management growth? What are its factors

Answered: 1 week ago