The USDA maintains a slew of sensors in the backcountry that track snow fall tot
ID: 3782864 • Letter: T
Question
The USDA maintains a slew of sensors in the backcountry that track snow fall totals You are going to build a class to represent a Snotel site and a Driver to manipulate it (add snow, print stuff) A Snotel site will consist of a name (such as "Shower Falls"), an elevation (such as S100). current snow depth (such as 13.4). and snow water equivalent, swe, (such as 2.7) - this is the depth of water on the ground if we melted all the snow at the site. We will assume that snow does not melt. After signing into one of the lab computers, open up the Blue J environment and create a new project called Inlab2 Within the Inlab2 project, create a new class called Snotel Site Create instance variables m the Snotel Site class to fit the specifications detailed m the Problem Statement. (You can name the variables however you see fit) Make a constructor that takes the name of the site and elevation, but not the snow depth or swe, and sets the correct variables. Make a "get method" for each instance variable. Make a printlnfo method that will print the name, elevation, current snow on the ground, and swe, Make it read well, like tins: Shower Falls. S100: 10.5 inches for 2.1 niches of water. Make a method that will add snow to the snow depth and update the The input parameter will represent the amount of new snow that has fallen. The snow depth will be updated (just add the new snow to it). The will also be updated by adding 20% of the new snow amount (e.g. if the is 5. and 10 niches of snow falls, the will now be 7). In the hilab2 project, create a class called Driver with a main method like we did in class. Maui method header: public static void main(Stmig[] args) Within the main method, create a variable that can hold an instance of die SnotelSite class. Create an instance of the SnotelSite class where the name is "Shower Falls" and elevation is 8100 and store this instance in die variable you created Create a second instance of SnotelSite with parameters of your choosing and store in another variable. Simulate a storm by calluig the method you made to modify the snow depth on each SnotelSite instance. Call printlnfo on each instance to see die results (check to make sure it did what it should). Simulate another storm and also prmt diose results (i.e. you should be simulating two storms and printing data two times for each instance ui the Driver). Test all this by running the main method m Driver (right click Driver, select void mani(Strmg[] args). select "ok") and check that the output is correct.Explanation / Answer
// SnotelSite.java
public class SnotelSite {
public SnotelSite(String name, double elevation) {
this.name = name;
this.elevation = elevation;
}
private String name;
private double elevation;
private double depth;
private double swe;
public String getName() {
return name;
}
public double getElevation() {
return elevation;
}
public double getDepth() {
return depth;
}
public double getSwe() {
return swe;
}
public void printInfo()
{
System.out.println(getName() + ", " + getElevation() + ": " +
getDepth() + " inches for " + getSwe() +
" inches of water");
}
public void addSnow(double snow)
{
this.depth += snow;
this.swe += snow*(0.2);
}
}
// Driver.java
public class Driver {
public static void main(String[] args) {
SnotelSite snotelSite = new SnotelSite("Shower Falls", 8100);
SnotelSite snotelSite2 = new SnotelSite("Falls Shower", 6000);
System.out.println("Simulating storm");
snotelSite.addSnow(100);
snotelSite.printInfo();
snotelSite2.addSnow(100);
snotelSite2.printInfo();
System.out.println("Simulating storm");
snotelSite.addSnow(50);
snotelSite.printInfo();
snotelSite2.addSnow(40);
snotelSite2.printInfo();
}
}
/*
Sample output
Simulating storm
Shower Falls, 8100.0: 100.0 inches for 20.0 inches of water
Falls Shower, 6000.0: 100.0 inches for 20.0 inches of water
Simulating storm
Shower Falls, 8100.0: 150.0 inches for 30.0 inches of water
Falls Shower, 6000.0: 140.0 inches for 28.0 inches of water
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.