1 Replies - 5473 Views - Last Post: 07 May 2009 - 04:19 PM Rate Topic: -----

#1 LindaSmith   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 04-May 09

Generic LinkedList implementation in java Visitor pattern

Posted 07 May 2009 - 09:09 AM

I'm stuck up in the coding. This is an interesting and challenging task. I'm trying to implement the generic LinkedList in visitor pattern. Any help on this is greatly appreciated. Thanks.

Implement a simple generic linked list in Java.

 The List interface must include the following operations
o add
o forEach
o size
 Do not use any of the classes in the Java Collections Framework. Do not extend them or use them in your implementation. The purpose of this project is to demonstrate understanding basic object oriented data structures, not familiarity with the existing APIs.
 The interface and implementation of the list should use Java generics.
o None of the methods should take or return java.lang.Object
o No casting should be necessary.
o The instanceof operator should not be used.
 The list should not allow null elements. -
 The list interface should not expose an iterator, but will have a forEach method that takes a Visitor object as its argument. The visitor interface should also be generic.
 Provide three implementations of the visitor interface:
o The first should concatenate a list of objects into a String.
o The second should compute the average of a list of BigDecimals.
o The third should do both of the above and override toString to print the list and the average. This object only has to work for lists of BigDecimals.
 Provide 100% unit test coverage using JUnit.
 Deliver the completed assignment in a common archive format (zip, tar.gz, bzip) with an Ant build.xml file at the root of the extracted archive.
o The default Ant task in the project should compile the project and run the tests which demonstrate the completeness of the solution.
o It can be assumed that Ant 1.7.0 is configured on the machine which will run the tests.

This is the code I've come up with. Please guide me how do I move forward.

public class Main
public static void main (String[] args)
List<BigDecimal> list; //Initialization omitted

list.add(new BigDecimal("5"));
list.add(new BigDecimal("25"));
list.add(new BigDecimal("13"));
list.add(new BigDecimal("4928"));

Visitor<BigDecimal> visitor; ///Initialization omitted



And produce output similar to this:

The list of numbers is 5 25 13 4928 The average is 1242.75


Attached File(s)

Is This A Good Question/Topic? 0
  • +

Replies To: Generic LinkedList implementation in java Visitor pattern

#2 BigAnt   User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 102
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: Generic LinkedList implementation in java Visitor pattern

Posted 07 May 2009 - 04:19 PM

Have you tried anything for code yet? The code you provided just uses the Java API.

I would see the Java List interface as a guideline as what to start with: http://java.sun.com/.../util/List.html

Also do you understand how a LinkedList works? I would start there and get this working before worrying about the Visitor.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1