uni

University stuff
git clone git://git.margiolis.net/uni.git
Log | Files | Refs | README | LICENSE

HRImpl.java (1279B)


      1 public class HRImpl implements HRInterface {
      2 	Room[] rooms = {
      3 		new Room("A", "single", 60, 25),
      4 		new Room("B", "double", 80, 40),
      5 		new Room("C", "twin", 90, 20),
      6 		new Room("D", "triple", 115, 15),
      7 		new Room("E", "quad", 140, 10),
      8 	};
      9 
     10 	public HRImpl() {
     11 		super();
     12 	}
     13 
     14 	public String list() {
     15 		String str = "";
     16 
     17 		for (Room r : rooms)
     18 			str += r.toString() + "\n";
     19 		return str;
     20 	}
     21 
     22 	public String book(String type, int num, String name) {
     23 		for (Room r : rooms) {
     24 			if (type.equals(r.type))
     25 				return r.addGuest(name, num);
     26 		}
     27 		return fail();
     28 	}
     29 
     30 	public String guests() {
     31 		String str = "";
     32 		int n = 0;
     33 
     34 		for (Room r : rooms)
     35 			n += r.totalGuests();
     36 		str += "total guests: " + n + "\n";
     37 		for (Room r : rooms) {
     38 			str += r.toString() + "\n";
     39 			if ((n = r.totalGuests()) != 0)
     40 				str += r.listGuests();
     41 		}
     42 		return str;
     43 	}
     44 
     45 	public String cancel(String type, int num, String name) {
     46 		for (Room r : rooms) {
     47 			if (type.equals(r.type))
     48 				return r.removeReserv(name, num);
     49 		}
     50 		return fail();
     51 	}
     52 
     53 	public void addListSub(String name, String type) {
     54 		for (Room r : rooms) {
     55 			if (type.equals(r.type)) {
     56 				r.addSub(name);
     57 				break;
     58 			}
     59 		}
     60 	}
     61 
     62 	private String fail() {
     63 		return "fail: room doesn't exist. available rooms types:\n" +
     64 		    list();
     65 	}
     66 }