• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can someone have a look

 
Chris Lavery
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everybody, ive done some coding for one of the tasks in my assignment but i cant really check it out fully until later on, so i was wondering if someone could tell me if it looks to meet the criteria it needs to.
Thanks in advance
Chris

2)You'll then need a class, say TopicManager, which maintains a list of most-recently updated TopicInfos; one of the fields of this class will be the list of current topics.

public class TopicManager
{
private static final int MAX_ITEMS = 100;
private ItemList items = null;
private int noItems = 0;


public TopicInfo update(int tid)
{

if (items == null) return null;


if (items.head().getID() == tid)
{
return items.head();
}

ItemList til = items;
TopicInfo ti;

while (til != null)
{
ti = til.head();
if (ti.getID() == tid)
{
til.pop();
items = new ItemList(ti,items);
return ti;
}
// ilPrev = il;
til = til.next();
}
return null;
}


public void addNew(TopicInfo ti)
{
if (noItems == 0)
{
items = new ItemList(ti);
}
else
{
items = new ItemList(ti,items);
}
if (noItems == MAX_ITEMS)
{
items.removeLast();
}
else
{
noItems++;
}
}


public TopicInfo[] getTopics()
{
TopicInfo[] tis = new TopicInfo[noItems];
ItemList il = items;

int i = 0;
while (i < noItems)
{
tis[i] = il.head();

il = il.next();
i++;
}
return tis;
}


public boolean isIn(int ID)
{
boolean found = false;
ItemList til = items;

while ((! found) && til != null)

{
found = (til.head().getID() == ID);
til = til.next();
}
return found;
}


}
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No code review, just some advice:
1. Google: test-driven development
2. Google: unit test
3. Visit www.junit.org
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic