Answered Essay: Create a Java project titled "hw2project", click the src icon and create a package called "weather".Create 5 classes within the

Create a Java project titled “hw2project”, click the src icon and create a package called “weather”.Create 5 classes within the weather package: Sky, Cloud, StratusCloud, CumulusCloud, and CirrusCloud. The class names, as well as the package name, must be spelled and capitalized exactly as shown here

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. The only output
should be “Everything (else) is ok”.

Sky2.java
Lastly, implement Sky in a somewhat different way. When one class holds many
references to instances of another class, we say (for example) that Sky “aggregates”
clouds. Sky aggregates by owning an array list. Sky2 will aggregate by being (in a
sense) an array list. That is, Sky2 will extend ArrayList<Cloud>.
Create class Sky2 in the weather. The Sky2 ctor will need to explicitly call the correct
superclass ctor, so that the initial capacity is 100.
Copy getMeanHeight() from Sky. You need to change it so that it traverses the
correct list of clouds, which is the instance of Sky2 that is executing
getMeanHeight(). Huge hint: its name is “this”.
What about adding clouds to Sky2? You could just copy add() from Sky and then
make a simple change. But there is an even simpler way.
Paste in the main() method from the Sky class. Change the line “Sky sky = new
Sky()” to “Sky2 sky = new Sky2()” To test Sky2, run it as an application.

Finally, export your work as a jar file called “CS46BHW2.jar”.

Expert Answer

 

I am not able to see option to upload jar here

so pasting all the classes .

Cloud.java

package weather;

public class Cloud {

private float bottom;

private float top;

Cloud(float bottom, float top) {

this.bottom = bottom;

this.top = top;

}

public float getHeight() {

return top – bottom;

}

public String rain() {

return “It is raining”;

}

}

CirrusCloud.java

package weather;

public class CirrusCloud extends Cloud{

CirrusCloud(float bottom, float top) {

super(bottom, top);

}

public String rain() {

return “I cannot make rain”;

}

}

StratusCloud.java

package weather;

public class StratusCloud extends Cloud{

StratusCloud(float bottom, float top) {

super(bottom, top);

}

}

CumulusCloud.java

package weather;

public class CumulusCloud extends Cloud{

CumulusCloud(float bottom, float top) {

super(bottom, top);

}

}

Sky.java

package weather;

import java.util.ArrayList;

public class Sky {

private ArrayList<Cloud> clouds;

Sky(){

clouds = new ArrayList<Cloud>(100);

}

public boolean add(Cloud c){

clouds.add(c);

return true;

}

public float getMeanHeight(){

float totalHeight = 0;

int totalClouds = clouds.size();

for(Cloud c: clouds){

totalHeight += c.getHeight();

}

return totalHeight/totalClouds;

}

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”);

}

}

Sky2.java

package weather;

import java.util.ArrayList;

public class Sky2 extends ArrayList<Cloud> {

private static final long serialVersionUID = 192989469958086558L;

Sky2() {

new ArrayList<Cloud>(100);

}

public float getMeanHeight() {

float totalHeight = 0;

int totalClouds = this.size();

for (Cloud c : this) {

totalHeight += c.getHeight();

}

return totalHeight / totalClouds;

}

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”);

Sky2 sky2 = new Sky2();

sky2.add(strat);

sky2.add(cumu);

sky2.add(cirr);

float mean = sky2.getMeanHeight();

if (mean < 1799 || mean > 1801)

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

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

}

}

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.