-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlant.java
80 lines (67 loc) · 2.03 KB
/
Plant.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
public class Plant
{
// Instance variables decalred below.
private String name;
private int height; // it gives us current height.
// is the plant edible or not.
private boolean edible;
//Default constructor that assigns name, height and edible to default values.
public Plant()
{
name = "No Name Plant";
height = 0;
edible = false;
}
// Parameterized which only accepts and assigns the name.
public Plant(String name)
{
this.name = name; // this.name is used to differentiate between local and instance variable.
height = 0;
edible = false;
}
// Parameterized which accepts and assigns all the instance variables.
public Plant(String name, int height, boolean edible)
{
// again here this. is used to differentiate between local and instance variables.
this.name = name;
this.height = height;
this.edible = edible;
}
// -+-+-+ Accessor Methods for each variable -+-+-+
// It returns name of the plant.
public String getName()
{
return name;
}
// This method returns height in centimeter.
public int getHeight()
{
return height;
}
// returns true or false as in edible or not.
public boolean getEdible()
{
return edible;
}
// -+-+-+ Mutator Methods for each variable -+-+-+
// sets the current name to newName.
public void setName(String newName)
{
name = newName;
}
// sets the current height to the height passsed as a parameter.
public void setHeight(int height)
{
this.height = height;
}
// sets current boolean value of edible to newEdible.
public void setEdible(boolean newEdible)
{
edible = newEdible;
}
// Following method returns true, if the other and the object which called it has the same name.
public boolean equals(Plant other)
{
return (name.equals(other.getName()));
}
}