Requirements: Using Java Create a new project named p3, with the following classes: ointList – this has the following members member variables (not static): a private integer array reference called list a private integer called count member methods (all public, not static): intList(int size) // the constructor. It allocates the array of the requested size and list references it. It also sets count to 0, as the list is currently empty. boolean insert(int val) // If there is room in the list, it inserts val at the beginning of the list and returns true; otherwise returns false without changing the list. boolean add(int val) // If there is room in the list, it adds val at the end of the list and returns true; otherwise returns false without changing the list. int delete(int index) // If index is “valid” for the list, it deletes the list entry at that index, returning the value that was stored there. Otherwise, it returns -1. Int find(int val) // If val is on the list, it returns the first index (starting from the top of the list, that val is found. If val is not found on the list, it returns -1 void print() // prints the list from top to bottom op3 – this as the following member(s) member methods (public) public static void main(String[] args) oThis instantiates an intList called myList. oPrint your name to the output. oIt then does a loop on the range of [0 .. 10) doing the following Insert the loop variable (e.g., i) into the list Add the loop variable to the end of the list oIt prints the list oIt reports on the results of the attempt to find “2” on the list. oIt reports on the results of the attempt to find “20” on the list oIt reports on the results of deleting index 8 of the list oIt reports on the results of deleting index 15 of the list oIt prints the list

44 0

Get full Expert solution in seconds

$1.97 ONLY

Unlock Answer

Program should be different from any other program, Thank you:)

Output should be identical with this

At index 0 there is: 9
At index 1 there is: 8
At index 2 there is: 7
At index 3 there is: 6
At index 4 there is: 5
At index 5 there is: 4
At index 6 there is: 3
At index 7 there is: 2
At index 8 there is: 1
At index 9 there is: 0
At index 10 there is: 0
At index 11 there is: 1
At index 12 there is: 2
At index 13 there is: 3
At index 14 there is: 4
At index 15 there is: 5
At index 16 there is: 6
At index 17 there is: 7
At index 18 there is: 8
At index 19 there is: 9
find(2) returned: 7
find(20) returned: -1
delete(8) returned: 1
delete(15) returned: 6
At index 0 there is: 9
At index 1 there is: 8
At index 2 there is: 7
At index 3 there is: 6
At index 4 there is: 5
At index 5 there is: 4
At index 6 there is: 3
At index 7 there is: 2
At index 8 there is: 0
At index 9 there is: 0
At index 10 there is: 1
At index 11 there is: 2
At index 12 there is: 3
At index 13 there is: 4
At index 14 there is: 5
At index 15 there is: 7
At index 16 there is: 8
At index 17 there is: 9

EXPERT ANSWER

intList.java





public class intList 
{
	private int list[];
	private int count;
	
	// constructor
	public intList(int size)
	{
		list = new int[size];
		count = 0;
	}
	
	// method to insert a value at the beginning
	public boolean insert(int val)
	{
		if(count<list.length)
		{
			if(count == 0)
			{
				list[count] = val;
			}
			else
			{
				for(int j=count;j>=0;j--)
				{
					list[j+1] = list[j];
				}
				
				list[0] = val;
			}
			count++;
			return true;
		}
		else
		{
			return false;
		}
	}
	
	// method to add a value at the end
	public boolean add(int val)
	{
		if(count<list.length)
		{
			list[count] = val;
			count++;
			return true;
		}
		else
		{
			return false;
		}
	}
	
	// method to delete
	public int delete(int index)
	{
		if(count!=0 && index<count)
		{
			int temp = list[index];
			for(int j=index+1;j<count;j++)
			{
				list[j-1] = list[j];
			}
			list[count-1] = 0;
			
			count--;
			
			return temp;
		}
		else
		{
			return -1;
		}
	}
	
	// method to find a value in the list
	public int find(int val)
	{
		for(int i=0;i<count;i++)
		{
			if(list[i]==val)
			{
				return i;
			}
		}
		
		return -1;
	}
	
	// method to print the list
	public void print()
	{
		for(int i=0;i<count;i++)
		{
			System.out.println("At index "+i+" there is: "+list[i]);
		}
	}
}




p3.java





// class p3 to test the class intList
public class p3 
{
	public static void main(String[] args) 
	{
		// instantiating
		intList myList = new intList(20);
		
		// looping 10 times
		for(int i=0;i<10;i++)
		{
			// adding at front and beginning
			myList.insert(i);
			myList.add(i);
		}
		
		// printing list
		myList.print();
		
		// printing the results of find and delete
		System.out.println("find(2) returned: "+myList.find(2));
		
		System.out.println("find(20) returned: "+myList.find(20));
		
		System.out.println("delete(8) returned: "+myList.delete(8));
		
		System.out.println("delete(15) returned: "+myList.delete(15));
		
		// printing the list again
		myList.print();
	}
}




SAMPLE OUTPUT