public class App {
public static void main (String[] args) throws IOException {
BufferedReader we = new BufferedReader(new InputStreamReader(System.in));
PrintWriter wy = new PrintWriter(new OutputStreamWriter(System.out),true);
PrintWriter bl = new PrintWriter(new OutputStreamWriter(System.out),true);
List lista = new List(); // lista z danymi
bl.println("hello");
bl.print("> "); bl.flush();
for (String instr=we.readLine(); instr!=null; instr=we.readLine())
try {
instr = instr.trim();
if (instr.length()==0||instr.startsWith("//")) // linia pusta lub komentarz
throw new NullPointerException();
String[] token = instr.split("\\p{Blank}+");
if (token[0].equals("insert")||token[0].equals("i")) {
if (token.length<3 || (token.length>3 && !token[3].startsWith("//")) )
throw new IllegalArgumentException();
int value=Integer.parseInt(token[2]);
int pos=Integer.parseInt(token[1]);
lista.Insert(pos,value);
wy.format("wstawienie: lista[%s] <- %s\n",pos,value);
}
else if (token[0].equals("delete")||token[0].equals("d")) {
if (token.length<2 || (token.length>2 && !token[2].startsWith("//")) )
throw new IllegalArgumentException();
int pos=Integer.parseInt(token[1]);
lista.Delete(pos);
wy.format("usunięcie: lista[%s]\n",pos);
}
else if (token[0].equals("read")||token[0].equals("r")) {
if (token.length<2 || (token.length>2 && !token[2].startsWith("//")) )
throw new IllegalArgumentException();
int pos=Integer.parseInt(token[1]);
wy.format("element: lista[%s] = %s\n",pos,lista.Read(pos));
}
else if (token[0].equals("length")||token[0].equals("l")) {
if (token.length<1 || (token.length>1 && !token[1].startsWith("//")) )
throw new IllegalArgumentException();
wy.format("ilość elementów: %s\n",lista.Length());
}
else if (token[0].equals("print")||token[0].equals("p")) {
if (token.length<1 || (token.length>1 && !token[1].startsWith("//")) )
throw new IllegalArgumentException();
wy.format("lista: %s\n",lista.toString());
}
else
throw new NoSuchMethodException(token[0]);
}
catch (NoSuchMethodException ex)