For this assignment, you will
Node class to be generic, and test it, LinkedList class that is a singly-linked list of Node objects,Senator to hold information about a member of the US Senate,
Each class will be in a separate file. Each class is public.
Convert the Node class in the following file to be generic.
public class Node { protected Object item; protected Node next; Node( Object itemArg ) { item = itemArg; next = null; } Node( Object itemArg, Node nextArg ) { item = itemArg; next = nextArg; } public static void main( String [] args ) { Node firstNode = new Node(new String("last")); firstNode = new Node(new String("middle"),firstNode); firstNode = new Node(new String("first"),firstNode); for (Node current = firstNode; current != null; current = current.next) { System.out.println((String)current.item + ' '); } } }
Notice that even the Node class includes a main method, for testing.
Edit this file so that Node is a generic class with a parameterized type for item. Test it by creating a node to hold a String, like in the orignal code. Then test it by creating a node that holds items of type Integer, the int wrapper class.
Write a generic LinkedList class that uses your generic Node class.
The nodes in the linked list are singly-linked and the list starts
with a dummy node. Implement the methods required to successfully run the following tests.
public static void main( String [] args) {
LinkedList<String> list = new LinkedList<String>();
list.insert(0,new String("middle"));
list.insert(0,new String("first"));
list.insert(2,new String("last"));
System.out.println(list);
LinkedList<Double> listd = new LinkedList<Double>();
listd.insert(0,new Double(3.14));
listd.insert(0,new Double(23.123));
listd.insert(0,new Double(-0.32));
System.out.println(listd);
listd.remove(1);
System.out.println(listd.get(1));
System.out.println("Size of listd is " + listd.size());
System.out.println(listd);
}
Your output should look like
first middle last -0.32 23.123 3.14 3.14 Size of listd is 2 -0.32 3.14
Write a Senator class that holds for a senator
String,char, 'D', 'R', or 'I'String, like 'CO',int.
The class must include a constructor and a toString method. Include a main method to test it, such as
public static void main(String [] args) { Senator member = new Senator("Chuck Anderson", 'D', "CO", 67); System.out.println(member); }
which should result in
Chuck Anderson (D-CO) 67
Write a new class named Voting that performs the following steps. The senators' voting information was obtained from this Washington Post web site.
LinkedList object,Your output should look exactly like the following, except that the full list of senators will appear in your output. Also, the final average percentages will not be 44.4%. In your calculations, ignore senators who are Independents, marked by 'I' instead of 'D' or 'R'.
Ron Wyden (D-OR) 96 Roger Wicker (R-MS) 91 Sheldon Whitehouse (D-RI) 97 Jim Webb (D-VA) 87 Mark Warner (D-VA) 92 George Voinovich (R-OH) 69 David Vitter (R-LA) 92 Tom Udall (D-NM) 96 Mark Udall (D-CO) 92 . . . Lamar Alexander (R-TN) 84 Daniel Akaka (D-HI) 97 Average party line vote percentages: R 44.4% D 44.4%
First, make sure your code compiles and runs correctly on our Linux workstations.
Then, tar together into a file named pa1.tar your files
On Linux, do this wtih
tar cvf pa1.tar LinkedList.java Node.java Senator.java Voting.java
Then, on RamCT, click on “Programming Assignment 1” and submit your tar file. You may continue to submit new versions until the deadline of Thursday, September 12th, 10:00 PM.