Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA help: create a class with the following SIX methods: Restrictions: 1.You mu

ID: 3847243 • Letter: J

Question

JAVA help: create a class with the following SIX methods:

Restrictions:

1.You must use an array of int. You may NOT use ArrayLists and other collections. If in

doubt, ask.

2.Do not add to the instance variables.

3.You may add private methods to support the other methods if desired.

1. OrderedList (int)

a. create an array of the size indicated by the parameter

b. if the parameter is less than 2, create an array of size 2

2. size(): int

a. return the size of the array (maximum number of values that can currently be stored)

3. numEntries():int

a.return the number of integers currently stored in the array

b.this number will range from 0 to the size of the array

4. insert (int): void

a.insert an integer into the array so that the elements are in ascending order

b.do not allow for duplicates in the array

c.if the array is full, do not insert the value

d.do not sort the array

5. delete (int): void

a.find the integer in the array and remove it

b.if the value is not in the array, do nothing

c.if the value is in the array, remove it so that the elements remain in ascending order

6. toString(): String

a. return the values in the array so that all values are separated by a space

b. the string should be “1 2 3” not “1 2 3 “

OrderedList list: int count: int OrderedList(int) Size 0: int numEntries0: int insert (int void delete (int): void toString(): String

Explanation / Answer

package codechef_beg;

public class Chegg_sol {
static int a[];
static int count=0;
   public static void OrderedList(int n)
   {
       if(n<=2)
       {
           a=new int[2];
       }
       else
       {
       a=new int[n];
       }
   }
   public static int size()
   {
       int si=a.length;
       return(si);
   }
   public static int numEntries()
   {
       int c=0;
       for(int i=0;i<a.length;i++)
       {
           if(a[i]!='')
               c++;
       }
       return c;
   }
   public static void insert(int num)
   {
       int flag=1;
       for(int i=0;i<a.length;i++)
       {
           if(num==a[i])
           {
               flag=0;
               break;
           }
       }
       if(count<a.length && flag==1)
       {
           count++;
           a[count]=num;
       }
       int temp;
       for(int i=0;i<a.length;i++)
       {
           for(int j=i+1;j<a.length;j++)
           {
               if(a[i]>a[j])
               {
                   temp=a[j];
                   a[j]=a[i];
                   a[i]=temp;
               }
           }
       }
   }
   public static void delete(int nu)
   {
       int flag=0;
       int point=0;
       int temp;
       for(int i=0;i<a.length;i++)
       {
           if(nu==a[i])
           {
               flag=1;
               point=i;
           }
       }
       if(flag==1){
       for(int i=point;i<a.length;i++)
       {
           temp=a[i+1];
           a[i]=temp;
          
       }
       }
   }
   public static String toStrig()
   {
       String s="";
       for(int i=0;i<a.length;i++)
       {
           s=s+String.valueOf(a[i])+" ";
       }
       return s;
   }

}