I've got a problem here that's been giving me some real trouble and I really cant even get an idea of what to do. here's the assignment and my code so far.
Create a system using an ArrayList which stores and manipulates names. Using standard input constantly prompt user for the following ..
Enter command or quit: (if they enter quit -- quit program)
Commands:
add <name>: add the String<name>to ArrayList;change <name> <newName>: change all items in ArrayList which have<name>to<newName>;delete <name>: delete all items in Arraylist which are<name>;print: print the ArrayList;amount: display the amount of items in ArrayList.
System must work... and have proper error messages..
import java.util.*;
public class NameManipulation {
static Scanner console = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("enter a command, or quit!");
ArrayList<String> names = new ArrayList<String>();
String command = console.next();
int size = names.size();
for (String x = null; size; x++) {
if (command == "add") {
String assignment = console.next();
names.add(assignment);
}
if (command == "change") {
String newname = console.next();
names.set(names.size, newname);
}
if (command == "delete") {
String delete = console.next();
if (delete == names)
;
names.remove();
}
if (command == "print") {
System.out.println(names);
}
if (command == "amount") {
amount = (names.size - 1);
System.out.println(amount);
}
if (command == "quit") {
System.out.println("You just quit!");
break;
} else
System.out.println("command not found!");
System.out.println(names);
}
}
}
==. Useequals().;(like inif (delete == names)case ).