Advertisement
KNikov

Untitled

Jul 7th, 2016
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.82 KB | None | 0 0
  1. public class HomeCreator {
  2.  
  3.     public Home createHome(List<String> args, List<Child> children) {
  4.         String command = args.get(0);
  5.         double[] values = args.stream().skip(1).mapToDouble(Double::parseDouble).toArray();
  6.         Home home = null;
  7.         switch (command) {
  8.             case "YoungCoupleWithChildren":
  9.                 home = registerYoungCoupleWithKids(values, children);
  10.                 break;
  11.             case "YoungCouple":
  12.                 home = registerYoungCouple(values);
  13.                 break;
  14.             case "OldCouple":
  15.                 home = registerOldCouple(values);
  16.                 break;
  17.             case "AloneYoung":
  18.                 home = registerYoungAlone(values);
  19.                 break;
  20.             case "AloneOld":
  21.                 home = registerOldAlone(values);
  22.                 break;
  23.  
  24.         }
  25.         home.calculateSalaries();
  26.         home.calculateConsumption();
  27.         return home;
  28.     }
  29.  
  30.     private YoungCoupleWithChildren registerYoungCoupleWithKids(double[] values, List<Child> children) {
  31.         return new YoungCoupleWithChildren(new Adult(values[0]), new Adult(values[1]), values[2],
  32.                 values[3], values[4], children);
  33.     }
  34.  
  35.     private YoungCouple registerYoungCouple(double[] values) {
  36.         return new YoungCouple(new Adult(values[0]), new Adult(values[1]), values[2],
  37.                 values[3], values[4]);
  38.     }
  39.  
  40.     private OldCouple registerOldCouple(double[] values) {
  41.         return new OldCouple(new Adult(values[0]), new Adult(values[1]), values[2], values[3], values[4]);
  42.     }
  43.  
  44.     private YoungAlone registerYoungAlone(double[] values) {
  45.         return new YoungAlone(new Adult(values[0]), values[1]);
  46.     }
  47.  
  48.     private OldAlone registerOldAlone(double[] values) {
  49.         return new OldAlone(new Adult(values[0]));
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement