Below shown are the 3 classes, I developed. When I run ElementTest.java, I cannot see the output. I am unable to put it in debug also. I am using JBuilder tool for editing, compling & running the code. I am expecting it to print the error message
"Trying to add duplicate Element" which was coded in file Element.java
----------------- File Element.java --------------------------
package testexamples;
public class Element {
private
String name;
public Element(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
----------------- File Set.java --------------------------
package testexamples;
import java.util.Vector;
public class Set {
private String name;
private Vector elements;
public Set(String name) {
this.name = name;
elements = new Vector();
}
public void addElement(Element el) {
if(! elements.contains( el )) {
elements.addElement(el);
}
else {
System.out.println(" Trying to add Duplicate Element:"+ el);
}
}
}
----------------- File ElementTest.java ----------------------
package testexamples;
import java.util.*;
import java.io.*;
public class ElementTest{
public ElementTest() {
FileOutputStream fos = null;
try {
fos = new FileOutputStream("log.txt");
} catch (Exception e) {
System.out.println(e);
System.exit(1);
}
PrintStream ps = new PrintStream(fos);
Element e1 = new Element("e1");
Element e2= new Element("e2");
Element e3= new Element("e3");
Element e4= new Element("e1");
Element e5= new Element("e2");
Set s1= new Set("s1");
Set s2= new Set("s2");
s1.addElement(e1);
s1.addElement(e2);
s1.addElement(e3);
s1.addElement(e4);
s1.addElement(e1);
s2.addElement(e1);
// s2.removeElement(e1);
s2.addElement(e1); // etc ...
// list of the elements in the set
ps.println("Here is the list of the elements");
ps.close();
}
public void main(String[] args) {
ElementTest elementTest = new ElementTest();
elementTest.invokedStandalone = true;
while(true);
}
private boolean invokedStandalone = false;
}