Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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());
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote