Given below are two classes, a Farm class, and a subclass of the Farm class, the
ID: 3682164 • Letter: G
Question
Given below are two classes, a Farm class, and a subclass of the Farm class, the DairyFarm class.
public class Farm{
private String owner;
private int acres;
public Farm(String who, int acres){
owner = who;
this.acres = acres;
}
public String getOwner(){return owner;}
public void setOwner(String newOwner){owner = newOwner;}
public int getAcres(){return acres;}
}
public class DairyFarm extends Farm{
private int cows; // number of cows on farm
public DairyFarm(String who, int acres, int ct){
super(who,acres);
cows = ct;
}
public int getCows(){return cows;}
public void setCows(int c){cows = c;}
}
In the box below enter the text of a new method, to be added to the DairyFarm class, called cowDensity, which takes no arguments, and which returns (as a double value) the number of cows per acre on a DairyFarm.
Enter your code in the box below
Explanation / Answer
public double cowDensity(){
return (double)(cows)/(getAcres());
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.