I need help with this code in JAVA. Please leave comments as Iam trying to learn. There are three parts to this. I have providedmy sample code as well.
Part 1 is to create the node class which will be a privatenested class within my MyNodeBag class. Part 2 is to create thebag. Be sure to use the node class for handling of the bag. Part 3will entail additional methods. Some already in part 2 in additionto creating a copyBag(MyNodesBag) method, which will copy theparameter bag into the bag that the method is being calledupon.
public class MyNodeBag<T> implementsSimpleNodeBag<T> {
int size = 0;
Node<T> head = new Node<T>();
// @SuppressWarnings("hiding")
private class Node<T> {
/*
* create a node class here - remember all a node must haveis:
* 1) information about its data
* 2) what node comes next
*
*/
T data;
Node<T> next;
}
/**
*implement the methods from the interface provided
*
add print statements within your methods
/*
public int getCurrentSize() {
// TODO Auto-generated method stub
return 0;
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean add(T t) {
// TODO Auto-generated method stub
return false;
}
@Override
public T remove() {
// TODO Auto-generated method stub
return null;
}
@Override
public void clear() {
// TODO Auto-generated method stub
head = new Node<T>();
}
@Override
public void concatenateBag(MyNodeBag<T> bag) {
// TODO Auto-generated method stub
}
@Override
public void copyBag(MyNodeBag<T> bag) {
// TODO Auto-generated method stub
}
public static void main(String[] args) {
//Main method for testing
mybag1.concatenateBag(Mybag2);
}
}
----------------------------------------------------------------------------------------------------------------------
public interface SimpleNodeBag<T>{
/**
* @return
*/
public int getCurrentSize();
/**
* @return
*/
public boolean isEmpty();
/**
* @param t
* @return
*/
public boolean add(T t);
/**
* @return
*/
public T remove();
/**
*
*/
public void clear();
/**
* @param bag
*/
public void concatenateBag(MyNodeBag<T> bag);
/**
* @param bag
*/
public void copyBag(MyNodeBag<T> bag);
}
I need help with this code in JAVA. Please leave comments as I am trying to learn. There are three parts to this. I have
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am