Guest User

Untitled

a guest
Jul 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. композиция — это когда один объект предоставляет другому свою функциональность частично или полностью.
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. public class MyClass {
  7. public static void main(String args[]) {
  8. WeatherObservations observation = new WeatherObservations(10.5, 760.5);
  9.  
  10. try {
  11. observation.addVisibility(10, 0, true);
  12. observation.addVisibility(10, 0, true);
  13. observation.addVisibility(10, 0, true);
  14. } catch (Throwable e) {
  15. System.out.println("Limit reached...");
  16. }
  17. }
  18. }
  19.  
  20. class Visibility {
  21. private Integer min;
  22. private Integer max;
  23. private Boolean visabilityIsAbsent;
  24.  
  25. public Visibility(Integer min, Integer max, Boolean visabilityIsAbsent) {
  26. this.min = min;
  27. this.max = max;
  28. this.visabilityIsAbsent = visabilityIsAbsent;
  29. }
  30.  
  31. public Integer getMin() {
  32. return min;
  33. }
  34.  
  35. public Integer getMax() {
  36. return max;
  37. }
  38.  
  39. public Boolean getVisabilityIsAbsent() {
  40. return visabilityIsAbsent;
  41. }
  42. }
  43.  
  44.  
  45. class WeatherObservations {
  46.  
  47. private double temperature;
  48. private double pressure;
  49. private ArrayList < Visibility > visibilities;
  50.  
  51. public WeatherObservations(double temperature, double pressure) {
  52. this.visibilities = new ArrayList < Visibility > ();
  53. this.pressure = pressure;
  54. this.temperature = temperature;
  55. }
  56.  
  57. public void addVisibility(Integer min, Integer max, Boolean visabilityIsAbsent) throws Throwable {
  58. if (visibilities.size() < 3) {
  59. Visibility visibility = new Visibility(min, max, visabilityIsAbsent);
  60. visibilities.add(visibility);
  61. } else {
  62. throw new Exception("Limit reached");
  63. }
  64. }
  65. }
Add Comment
Please, Sign In to add comment