Answered Essay: Hey guys! Can you help me with this code error?

Hey guys! Can you help me with this code error?

So here are the assignment directions:

“Create 4 other classes in the weather package: Cloud, StratusCloud, CumulusCloud, and CirrusCloud.

Cloud.java

This class needs:

1) Private float instance variables: bottom and top.

2) A ctor that takes bottom and top as args and stores them in the instance

variables. NOTE: “ctor” is an abbreviation for “constructor”.

3) A public method getHeight() that returns a float, whose value is top minus

bottom.

4) A public String method rain() that returns “It is raining”

StratusCloud.java and CumulusCloud.java

For these classes:

1) Change the class declarations so that they are subclasses of Cloud.

2) Fix the ctors so that they pass bottom and top to the superclass ctor.

CirrusCloud.java

Subclasses of Cloud inherit a rain() method that is not appropriate for cirrus clouds. Override rain() so that it returns “I cannot make rain”

Sky.java

This class holds lots of cloud instances of various types, and computes the average cloud height. It needs:

1) A private ArrayList<Cloud> called clouds.

2) A ctor that creates the clouds array list with an initial capacity of 100. Look up

the javadoc API page for ArrayList to see what ArrayList ctor to call. If you don’t

know how to do this, ask on Piazza. DON’T ask Piazza for the answer, just ask

how to find the javadoc API page.

3) A public method called add(Cloud c) that takes a cloud and adds it to the array

list. The return type of this method should be boolean, and the method should

always return true. That’s a little weird but it will make more sense later.

4) A public float method called getMeanHeight(), which returns the average height

of all the clouds in the array list.

5) A main() method. Paste in the following:

public static void main(String[] args)

{

StratusCloud strat = new StratusCloud(100, 1000);

if (!strat.rain().startsWith(“It is raining”))

System.out.println(“Bad StratusCloud::rain”);

CumulusCloud cumu = new CumulusCloud(200, 2000);
if (!cumu.rain().startsWith(“It is raining”))

System.out.println(“Bad CumulusCloud::rain”);

CirrusCloud cirr = new CirrusCloud(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”);

}

To test your work so far, run Sky as an application. Click the tiny “Run” button at the top of Eclipse (a white triangle pointing right, inside a green circle). The only output should be “Everything (else) is ok”. ”

And here is my code of the StratusCloud class:

D Sky.java D Cloud.java | | package weather; 嗢Packag × : Type Hi | D StratusCloud.ja X | >2 hw2project public class StratusCloud extends Cloud src ▼ weather public StratusCloud(float thatBottom, float thatTop) CirrusCloud.java ▼ D Cloud.java super thatBottom, thatTop); Cloud D CumulusCloud.java ▶ ED Sky.java StratusCloud.java JRE System Library [JavaSE-1.

And here is my code of the Sky class:

And here’s the error I get when I run the Sky class:

Any help is appreciated!!

D Sky.java D Cloud.java | | package weather; 嗢Packag × : Type Hi | D StratusCloud.ja X | >”2 hw2project public class StratusCloud extends Cloud src ▼ weather public StratusCloud(float thatBottom, float thatTop) CirrusCloud.java ▼ D Cloud.java super thatBottom, thatTop); Cloud D CumulusCloud.java ▶ ED Sky.java StratusCloud.java JRE System Library [JavaSE-1.

Expert Answer

 

Cloud.java

package weather;

public class Cloud {

//instance variables

private float bottom;

private float top;

//constructor that takes top and bottom as parameters and initializes the instance variables

public Cloud(float thatbottom, float thattop)

{

this.bottom = thatbottom;

this.top = thattop;

}

//method that calculates and returns height

public float getHeight()

{

//compute and return top-bottom

return this.top -this. bottom;

}

//method rain

public String rain()

{

//return a string “It is raining”

return “It is raining”;

}

}

StratusCloud.java

package weather;

//class StratusCloud which is a subclass of Cloud

public class StratusCloud extends Cloud {

//constructor that takes top and bottom as parameters

public StratusCloud(float thatbottom, float thattop)

{

//pass top and bottom to the super class constructor

super(thatbottom, thattop);

}

}

CumulusCloud.java

package weather;

//class CumulusCloud which is a subclass of Cloud

public class CumulusCloud extends Cloud {

//constructor that takes top and bottom as parameters

public CumulusCloud(float thatbottom, float thattop)

{

//pass top and bottom to the super class constructor

super(thatbottom, thattop);

}

}

CirrusCloud.java

package weather;

//class CirrusCloud which is a subclass of Cloud

public class CirrusCloud extends Cloud {

//constructor that takes top and bottom as parameters

public CirrusCloud(float thatbottom, float thattop)

{

//pass top and bottom to the super class constructor

super(thatbottom, thattop);

}

//override the rain method

public String rain()

{

return “I cannot make rain”;

}

}

Sky.java

package weather;

import java.util.ArrayList;

public class Sky {

//declare an Arraylist

private ArrayList<Cloud> clouds;

//In the constructor instantiate the Arraylist with a capacity 100

public Sky()

{

clouds = new ArrayList<Cloud>(100);

}

//method add that takes variable of type Cloud as parameter and return a boolean

public boolean add(Cloud c)

{

//add c to the arraylist

clouds.add(c);

//return true

return true;

}

//method that computes and returns the Mean height

public float getMeanHeight()

{

float sum = 0;

//loop through the array list and compute the sum of the heights

for(int i = 0; i < clouds.size(); i++)

{

sum = sum + clouds.get(i).getHeight();

}

//compute and return average height

return sum / clouds.size();

}

public static void main(String[] args) {

//declare an object to StratusCloud by passing 100 and 1000 as parameters

StratusCloud strat = new StratusCloud(100, 1000);

//if the rain method doesn’t return It is raining print Bad StratusCloud::rain

if (!strat.rain().startsWith(“It is raining”))

System.out.println(“Bad StratusCloud::rain”);

//declare an object to CumulusCloud by passing 200 and 2000 as parameters

CumulusCloud cumu = new CumulusCloud(200, 2000);

//if the rain method doesn’t return It is raining print Bad StratusCloud::rain

if (!cumu.rain().startsWith(“It is raining”))

System.out.println(“Bad CumulusCloud::rain”);

//declare an object to CirrusCloud by passing 300 and 3000 as parameters

CirrusCloud cirr = new CirrusCloud(300, 3000);

//if the rain method doesn’t return I cannot make rain print Bad StratusCloud::rain

if (!cirr.rain().startsWith(“I cannot make”))

System.out.println(“Bad CirrusCloud::rain”);

//create an object for Sky class

Sky sky = new Sky();

//add a stratus cloud using add method

sky.add(strat);

//add a cumulus cloud using add method

sky.add(cumu);

//add a cirrus cloud using add method

sky.add(cirr);

//get the mean height

float mean = sky.getMeanHeight();

//check if mean height is less than 1799 or greater than 1801 if yes then print bad mean

if (mean < 1799 || mean > 1801)

System.out.println(“Bad mean height: expected 1800, saw ” + mean);

//else print everything is ok

System.out.println(“Everything (else) is ok”);

}

}

Output:

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.