sathana

Sky

Sep 13th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. package weather;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. public class Sky {
  6. // a private ArrayList of type Cloud named clouds ****
  7. private ArrayList<Cloud> clouds;
  8. // a constructor that creates the clouds array list with
  9. // initial capacity of 100 ****
  10. public Sky() {
  11. clouds = new ArrayList<Cloud>(100);
  12.  
  13. }
  14. public boolean add(Cloud c){
  15. clouds.add(c);
  16. return true;
  17. }
  18. public float getMeanHeight(){
  19. float meanHeight=0;
  20. for(int i=0;i<=2;i++)
  21. {
  22. meanHeight=meanHeight+clouds.get(i).getHeight();
  23. }
  24. meanHeight=meanHeight/100;
  25. return meanHeight;
  26. }
  27. public static void main(String[] args) {
  28. Cloud strat = new Cloud(100, 1000);
  29. if (!strat.rain().startsWith("It is raining"))
  30. System.out.println("Bad StratusCloud::rain");
  31. Cloud cumu = new Cloud(200, 2000);
  32. if (!cumu.rain().startsWith("It is raining"))
  33. System.out.println("Bad CumulusCloud::rain");
  34. Cloud cirr = new Cloud(300, 3000);
  35. if (!cirr.rain().startsWith("I cannot make"));
  36. System.out.println("Bad CirrusCloud::rain");
  37. Sky sky = new Sky();
  38. sky.add(strat);
  39. sky.add(cumu);
  40. sky.add(cirr);
  41. float mean = sky.getMeanHeight();
  42. if (mean < 1799 || mean > 1801)
  43. System.out.println("Bad mean height: expected 1800, saw " + mean);
  44. System.out.println("Everything (else) is ok");
  45. }
  46. }
Add Comment
Please, Sign In to add comment