Sale!

ECE 39595 Homework 5 Solution

Original price was: $35.00.Current price is: $30.00. $25.50

Category:

Description

5/5 - (4 votes)

For HW 5 we will write a Java program that defines and uses a linked list interface to that forces
implementors of the interface to support very basic linked list functionality. The file Main.java
contains the main function. Your code should work with it and produce output similar to what
is shown in the file output.txt. Your code does not have to have the same number of lines
listed below, these are basically guidelines to let you know approximately how long the code
will be.
Note that I am ok with output like that in output1.txt or output2.txt. This means that the orders
I ask for elements to be placed into the linked list in public IntList(IntList n, int data) and public
LongList(LongList n, long data) is relaxed.
You will create three .java files with the following functionality:
MyList.java (6 lines, including blank lines, in my implementation): This defines the MyList
interface, which defines two abstract methods:
public MyList next( );
public void printNode( );
IntList.java (20 lines, including blank lines, in my implementation): This defines the IntList
class which implements the MyList interface.
This class has two fields, next, which is a IntList reference, and data, which is an int.
The class defines a constructor and several functions:
public IntList(IntList n, int data) which adds n to the tail of the linked list.
public int getData( ) which returns the value of data;
public IntList next( ) which returns the next node in the linked list. Note that this is the
implementation of public MyList next( ); in the MyList interface.
public void printNode( ) which uses System.out.print to print the kind of node, and the value of
data. Note that this is the implementation of public void printNode( ); in the MyList interface.
LongList.java (20 lines, including blank lines, in my implementation): This defines the LongList
class which implements the MyList interface. The functions are very similar to those in IntList.
This class has two fields, next, which is a LongList reference, and data, which is a long.
The class defines a constructor and several functions:
public LongList(LongList n, long data) which adds n to the front of the linked list;
public long getData( ) which returns the value of data;
public LongList next( ) which returns the next node in the linked list;
public void printNode( ) which uses System.out.print to print the kind of node, and the value of
data. Note that this is the implementation of public void printNode( ); in the MyList interface.
What should be turned in.
Your .java files should be in a directory called userid, where userid is your Purdue login name. It
should be possible for a grader to go into userid and execute javac HW5.java followed by java
HW5 and to compile and execute your program. Your directory should contain no .class files.
Zip up the userid directory and turn it in. Do not use other compression schemes (e.g. .rar files
or .7z files) unless you have no choice. If you don’t have a choice, email me and let me know
why.