class Employee{ String name; int income; Employee prev; Employee next; Employee(String name, int income, Employee next, Employee prev){ this.name = name; this.income = income; this.prev = prev; this.next = next; } } class Iterator{ Employee current; List list; Iterator(List list){ this.list = list; this.toBegin(); } void toBegin(){ this.current = this.list.head; } void next(){ if (!this.list.isEmpty()) this.current = this.current.prev; } void add(String name, int income){ if(this.list.isEmpty()) { Employee newItem = new Employee(name, income,list.head,list.head); this.list.head.prev = newItem; this.list.head.next = newItem; } else{ this.toBegin(); this.next(); while(income < this.current.income) next(); Employee newItem = new Employee(name, income, this.current.next, this.current); this.current.next = newItem; newItem.next.prev = newItem; } } void remove(){ this.current.prev.next = this.current.next; this.current.next.prev = this.current.prev; this.toBegin(); } } class List{ Employee head = new Employee("",0,null,null); boolean isEmpty(){ return (this.head.next == null); } Iterator getIterator(){ return new Iterator(this); } void ascendingPrint(){ if(this.head.next != null){ Employee next = this.head.next; System.out.println(next.name + "\t" + next.income); while(next.next != this.head){ next = next.next; System.out.println(next.name + "\t" + next.income); } System.out.println(); } } void descendingPrint(){ if(this.head.prev != null){ Employee next = head.prev; System.out.println(next.name + "\t" + next.income); while(next.prev != this.head){ next = next.prev; System.out.println(next.name + "\t" + next.income); } System.out.println(); } } } public class Cv05Pr1{ public static void main(String[] args){ List staff = new List(); String command = new String(); String name = new String(); int income; Iterator iterator = staff.getIterator(); System.out.println("* Martin Sloup (A04735)"); System.out.println(); System.out.println("* Commands: "); System.out.println("* add - add new employee"); System.out.println("* list - list the staff"); System.out.println("* exit, quit, end - for exit"); do { System.out.println(); System.out.print("> "); command = VstupData.ctiString(); command = command.toLowerCase(); System.out.println(); if (command.equals("add")) { System.out.print("Name: "); name = VstupData.ctiString(); System.out.print("Income: "); income = VstupData.ctiInt(); iterator.add(name, income); System.out.println(); System.out.println("Employee with name '" + name + "' was added."); } else if (command.equals("list")) { System.out.println("Ascending print of list:"); staff.ascendingPrint(); System.out.println("Descending print of list:"); staff.descendingPrint(); } else if (command.equals("end")) { } else if (command.equals("exit")) { } else if (command.equals("quit")) { } else { System.out.println("Error: Unkown command '" + command + "'!!!"); } } while (!command.equals("exit") && !command.equals("quit") && !command.equals("end")); System.out.println("Bye, bye..."); } }