Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java Main Task 1: Modify the ListInterface Java interface we have discussed in class lectures. Sub task 1) change Object to Comparable Note that Comperable

java

Main Task 1: Modify the ListInterface Java interface we have discussed in class lectures.

Sub task 1) change Object to Comparable

Note that Comperable is an interface. Objects that inherit from Comperable have a method compareTo(). compareTo() can be used in an algorithm you will have to write for the lab.

You can find a brief summary on compareTo() at these web pages:

http://chortle.ccsu.edu/java5otes/chap53b/ch53B_2.htmlLinks to an external site.

https://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html#compareTo(T)Links to an external site.

and at other web pages you can search for.

Sub task 2) change the name of the interface from ListInterface to ComparableListInterface

ListInterface is specified in a PDF file that is linked to below. It is also specified in the textbook for the class. You may use either the PDF file or the textbook to refer to its source code.

Main Task 2: Modify the ListArrayBased class we have discussed in class lectures.

ListArrayBased is also specified in a PDF file that is linked to below. It is also specified in the textbook for the class. You may use either the PDF file or the textbook to refer to its source code. Please note the following corrections to the textbooks source code:

public void add(int index, Object item) throws ListIndexOutOfBoundsException

{

if (numItems >= MAX_LIST) // Use >= instead of >

for (int pos = numItems 1; pos >= index; pos--) // insert 1 after numItems

public void remove(int index) throws ListIndexOutOfBoundsException

{

for (int pos = index + 1; pos ; pos++) //

ListIndexOutOfBoundsException is also specified in a PDF file that is linked to below. It is also specified in the textbook for the class. You may use either the PDF file or the textbook to refer to its source code.

Modify ListArrayBased by performing the following:

1) change the name of the class from ListArrayBased to ComparableListArrayBased

2) change ListInterface to ComparableListInterface

3) change Object to Comparable

4) add a method corresponding to the following UML:

+isInAscendingOrder() : boolean {query}

isInAscendingOrder returns true if the list is in ascending sorted order, else returns false

Test your solution by writing a driver program. The driver program will have a main() method and is the program that is run at the command line. You may give your driver program any name you like. The driver program should perform a loop, ask for input, and display output in the following way (note that the output in bold is what the user inputs):

Input a list of integers: 5 9 101 183 4893

Your list of integers is in ascending order.

Do you want to continue (y): y

Input a list of integers: 5 9 101 183 48

Your list of integers is not in ascending order.

Do you want to continue (y): y

Input a list of integers: 5 4 100 101 183 4893

Your list of integers is not in ascending order.

Do you want to continue (y): y

Input a list of integers: 5 9 101 101 183 4893

Your list of integers is in ascending order.

Do you want to continue (y): y

Input a list of integers: -48 -7 0 5 9 101 183

Your list of integers is in ascending order.

Do you want to continue (y): y

Input a list of integers: 14

Your list of integers is in ascending order.

Do you want to continue (y): y

Input a list of integers:

Your list of integers is in ascending order.

Do you want to continue (y): n

What to submit for the lab:

your program listing, including the solution

a capture the results of the program runs as shown above. You may submit captures of the program run as either a text file that has all of the output of the driver program, or as an image file that has all of the output of the driver program.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

public class ListIndexoutOfBoundsException extends IndexOutOfBoundsException f public ListIndexOutofBoundsException (string s) super (s): end constructor y end ListIn dexoutofBoundsException Also, the exception ListException is needed when the array storing the list becomes full. Here is the exception ListException: public class ListException extends RuntimeException f public ListException(String s) t super (s) I/ end constructor // end ListException public class ListIndexoutOfBoundsException extends IndexOutOfBoundsException f public ListIndexOutofBoundsException (string s) super (s): end constructor y end ListIn dexoutofBoundsException Also, the exception ListException is needed when the array storing the list becomes full. Here is the exception ListException: public class ListException extends RuntimeException f public ListException(String s) t super (s) I/ end constructor // end ListException

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

Creating A Database In Filemaker Pro Visual QuickProject Guide

Authors: Steven A. Schwartz

1st Edition

0321321219, 978-0321321213

More Books

Students also viewed these Databases questions