0

Can somebody please help me understand what the output of this code would be. I believe I am getting the wrong output due to some technical problems with my computer.

public class SetDemo {

	public static void main(String[] args) {
		SetInherit inherit = new SetInherit();
	      SetComposition comp = new SetComposition();
	      System.out.println(inherit);
	      inherit.add(1);
	      System.out.println(inherit);
	      inherit.add(1);
	      System.out.println(inherit);
	      inherit.add(2);
	      System.out.println(inherit);
	      inherit.add(3);
	      System.out.println(inherit);
	      inherit.add(3);
	      System.out.println(inherit);
	      inherit.add(4);
	      
	      System.out.println(comp);
	      comp.add(1);
	      System.out.println(comp);
	      comp.add(1);
	      System.out.println(comp);
	      comp.add(2);
	      System.out.println(comp);
	      comp.add(3);
	      System.out.println(comp);
	      comp.add(3);
	      System.out.println(comp);
	      comp.add(4);

	}
}
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by stultuske
0

This is SetComposition;

public class SetComposition implements ISet {
	private BoundedBag b;

	public boolean add(int theValue) {
		return b.add(theValue);
	}

	public SetComposition() {
		b = new BoundedBag();
	}

	public boolean contains(int theValue) {
		return b.contains(theValue);
	}

	public boolean remove(int theValue) {
		return b.remove(theValue);
	}

	public int size() {
		return b.size();
	}
}

This is SetInherit;

public class SetInherit extends BoundedBag implements ISet {
	public SetInherit(){
		super();
	}

This is ISet:

public interface ISet {
	boolean add(int theValue);	
	boolean contains(int theValue);	
	boolean remove(int theValue);	
	int size();	String toString();
}
0

and what is 'BoundedBag'? most times, trouble in output are not technical problems of your computer, it's just a difference between what a developer should've written, and what he actually wrote.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.