Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package weather;
- import java.util.ArrayList;
- public class Sky {
- // a private ArrayList of type Cloud named clouds ****
- private ArrayList<Cloud> clouds;
- // a constructor that creates the clouds array list with
- // initial capacity of 100 ****
- public Sky() {
- clouds = new ArrayList<Cloud>(100);
- }
- public boolean add(Cloud c){
- clouds.add(c);
- return true;
- }
- public float getMeanHeight(){
- float meanHeight=0;
- for(int i=0;i<=2;i++)
- {
- meanHeight=meanHeight+clouds.get(i).getHeight();
- }
- meanHeight=meanHeight/100;
- return meanHeight;
- }
- public static void main(String[] args) {
- Cloud strat = new Cloud(100, 1000);
- if (!strat.rain().startsWith("It is raining"))
- System.out.println("Bad StratusCloud::rain");
- Cloud cumu = new Cloud(200, 2000);
- if (!cumu.rain().startsWith("It is raining"))
- System.out.println("Bad CumulusCloud::rain");
- Cloud cirr = new Cloud(300, 3000);
- if (!cirr.rain().startsWith("I cannot make"));
- System.out.println("Bad CirrusCloud::rain");
- Sky sky = new Sky();
- sky.add(strat);
- sky.add(cumu);
- sky.add(cirr);
- float mean = sky.getMeanHeight();
- if (mean < 1799 || mean > 1801)
- System.out.println("Bad mean height: expected 1800, saw " + mean);
- System.out.println("Everything (else) is ok");
- }
- }
Add Comment
Please, Sign In to add comment