CSSE2002/7023 Tute Week 5 1 XFiles The following class maintains a collection of
ID: 3900135 • Letter: C
Question
CSSE2002/7023 Tute Week 5 1 XFiles The following class maintains a collection of strings all begining with X. class XFiles I public LinkedList files; public void add (String s) f if (s.charAt (0)--'X') I files .add (s); public void remove (String s) { files .remove (s); public List getWords ) return files; . Fix the above code, so it won't throw any exceptions [without using try/catch] » Find two ways to break the invariant for this class 2 Black box testing The following class tracks how many passengers are on a bus public class Bus {[ public Bus (int capacity); int getCurrent (); int getAverageCount (); //average passengers between stops void stop (int on, int off); // Passenger changeover at a bus stop how many on the bus right nou //passengers get off before any new get on 1. What would you test? ie what situations and inputs would you test. You don't need to specify expected output.Explanation / Answer
1. FIXED CODE :
public class XFiles {
public LinkedList<String> files;
public XFiles()
{
files=new LinkedList<>();
}
public void add(String s)
{
if(s == null)
System.out.println("Can't insert empty String");
else if(s.charAt(0)=='X')
files.add(s);
}
public void remove(String s)
{
if(files.contains(s))
files.remove(s);
else
System.out.println(s+" not exist");
}
public List<String>getWords()
{
return files;
}
}
ii:
1st XFiles A= new XFiles();
and 2nd A.add(null);