Please explain your answer Assume that you have the followin

Please explain your answer

Assume that you have the following Bag object, myBag, with n String data: Baglnterface myBag = new ArrayBag(); Write Java statements that create a newBag object which contains non-duplicate data in myBag. Example: if myBag contains data: \"hello\", \"Hello\", \"world\", \"hello\", \"james\", \"james\" newBag object should contain: \"hello\", \"Hello\", \"world\", \"james\"

Solution

public class abc { public static void main(String[] args) throws Exception{ Scanner c = new Scanner(new File(\"ac.txt\")); ArrayList a = new ArrayList(); while (c.hasNext()){ a.add(c.next()); } c.close(); ArrayList b = new ArrayList(); // int p; for(p=0; p<=a.size()-13; p=p+14){ String str = a.get(p)+\" \"+a.get(p+1); b.add(str); int q; for(q=2; q<14; q++){ b.add(list.get(p+q)); } int r; for(r=0; r<=ds.size()-12; r=r+13){ b.get(r); } } } }
Please explain your answer Assume that you have the following Bag object, myBag, with n String data: Baglnterface myBag = new ArrayBag(); Write Java statements

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site