I\'m having trouble with this, can someone help. Plant Germination Observation *
ID: 3627422 • Letter: I
Question
I'm having trouble with this, can someone help.Plant Germination Observation **:
Write a program that has two classes: a driven class called MapleTree, and a driver class called MapleTreeDriver.
The driver should:
• Create an object called tree from the MapleTree class.
• Call the plant method to record the planting of the seed.
• Call the germinate method to record the first observation of a seedling and record its height.
• Call the dumpData method to display the current values of all instance variables.
The driven class should contain three private instance variables, plantDate, height, and heightDate. The two dates are to be entered as text in the format, dd/mm/yyyy. This class must include a plant method, a germinate method, and a dumpData method. The plant method prompts the user for and inputs the date of planting. The germinate method prompts the user for and inputs the date on which a seedling is first observed. It also prompts the user for and inputs the height of that seedling above the surface of the soil in meters. (Of course, this will be a fractional value.) The dumpData method prints the current value of all instance variables.
Sample session:
Enter plant date (dd/mm/yyyy): 15/04/2003
Enter germination date (dd/mm/yyyy): 12/06/2003
Enter observed height in meters: 0.007
Plant date = 15/04/2003
Germinate date = 12/06/2003
Initial height = 0.0070 meters
Explanation / Answer
please rate - thanks
import java.util.*;
public class MapleTree
{private String plantDate,heightDate;
private double height;
Scanner in=new Scanner(System.in);
public MapleTree()
{}
public void plant()
{System.out.print("Enter plant date (dd/mm/yyyy): ");
plantDate=in.nextLine();
}
public void germinate()
{System.out.print("Enter germination date (dd/mm/yyyy): ");
heightDate=in.nextLine();
System.out.print("Enter observed height in meters: ");
height=in.nextDouble();
}
public void dumpData()
{System.out.println("Plant date = "+plantDate);
System.out.println("Germinate date = "+heightDate);
System.out.println("Initial height = "+height);
}
}
-----------------------------------------
public class MapleTreeDriver {
public static void main(String[] args)
{
MapleTree tree= new MapleTree();
tree.plant();
tree.germinate();
tree.dumpData();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.