public class ICA06 {
final static Scanner cin = new Scanner(System.in);
final static Bag friends = new LinkedBag();
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
char cmd;
out.println("CPS 151 ICA 06 by ________________");
out.print(" A/C/F/R/P/S/Q? ");
cmd = Character.toUpperCase(cin.next().trim().charAt(0));
while(cmd != 'Q') {
if (cmd == 'A')
add();
else if (cmd == 'C')
count();
else if (cmd == 'F')
find();
else if (cmd == 'R')
remove();
else if (cmd == 'S')
out.println("The bag has " + friends.size() + " items");
else if (cmd == 'P')
out.println(friends);
else
out.println("Invalid command");
out.print(" A/C/F/R/P/S/Q? ");
cmd = Character.toUpperCase(cin.next().trim().charAt(0));
} // end loop
} // end main
private static void add() {
String name = getWord("Enter friend's first name: ");
friends.add(name);
out.println("Name added");
}
private static void find() {
out.print("Enter friend's first name: ");
String name = getWord("Enter friend's first name: ");
if (friends.find(name))
out.println("The name " + name + " is in bag");
else
out.println("The name " + name + " is not in bag");
}
private static void remove() {
String name = getWord("Enter friend's first name: ");
if (friends.remove(name))
out.println("The name " + name + " was removed");
else
out.println("The name " + name + " is not in bag, cannot remove");
}
public static void print() {
out.println(friends);
}
private static void count() {
String name = getWord("Enter friend's first name: ");
out.println("The name occurs " + friends.count(name) + " times in the bag");
}
static String getWord(String prompt) {
out.print(prompt);
return cin.next();
}
} // end class
//-------------------------- interface Bag
interface Bag {
void add(T item);
boolean remove(T item);
boolean find(T item);
int count(T item);
int size();
@Override
String toString();
} // end interface
//-------------------------- class LinkedBag
class LinkedBag implements Bag{
private Node head;
public LinkedBag() {
head = null;
}
@Override
public void add(T item) {
}
@Override
public boolean remove(T item) {
return false;
}
@Override
public boolean find(T item) {
return false;
}
@Override
public int count(T item) {
return 0;
}
@Override
public int size() {
return 0;
}
public String toString() {
return "";
}
} // end class LinkedBag
//-------------------------- class Node
class Node {
public T data;
public Node next;
// Constructor 0
public Node() {
this(null);
}
// Constructor 1
public Node(T data) {
this(data, null); // use Constructor 2 specifying both instance variables
}
// Constructor 2
public Node(T data, Node next) {
this.data = data;
this.next = next;
}
} // end class
ul AT&T? ??12:12 @ * 13% Textbook reference: Generic class examples in Chapter 18 (section 18.2). ple codes on Isidore: Bag interface, ArrayBag class, IntLinkedList class. . reate a standard Java application using NetBeans Name it ICAD6 Let NetBeans create the main class for you. . Delete the code created by NetBeans and copy-paste code from ICAO6 Start.txt. This includes the main (client) class, generic Bag interface, generic Node class, and a skeleton generic class that implements the methods specified in the Bag interface (as stubs). Generic typing considerations: Specify as little about the type as is necessary to support your code. In this case constraining the type parameter is not necessary. Remember that all non primitive types in Java support the .equals() method, and that is all we need to implement the Bag interface methods. Do not forget to add your name in the output identification (sign-on) printin. Add header block comments at top of the program text Sample Output The output would be the same as what you would get from the Array based implementation. Submit the source code and sample output using the submission template. Name this document youruserid ICAO6.docx. 2018-03-22