Initial Commit
This commit is contained in:
12
CS7 - Demo/Main.java
Normal file
12
CS7 - Demo/Main.java
Normal file
@@ -0,0 +1,12 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Tree oakTree = new Tree("Oak", 10, .5); //Height and width are in whatever units you want
|
||||
Tree pineTree = new Tree("Pine", 25, 1.25);
|
||||
|
||||
System.out.println(oakTree);
|
||||
oakTree.grow(5, .5);
|
||||
|
||||
System.out.println(oakTree);
|
||||
System.out.println(pineTree);
|
||||
}
|
||||
}
|
||||
32
CS7 - Demo/Tree.java
Normal file
32
CS7 - Demo/Tree.java
Normal file
@@ -0,0 +1,32 @@
|
||||
public class Tree {
|
||||
private String typeOfTree;
|
||||
private double height;
|
||||
private double width;
|
||||
|
||||
public Tree(String newTypeOfTree, double newHeight, double newWidth) {
|
||||
typeOfTree = newTypeOfTree;
|
||||
height = newHeight;
|
||||
width = newWidth;
|
||||
}
|
||||
|
||||
public String getTypeOfTree() {
|
||||
return typeOfTree;
|
||||
}
|
||||
|
||||
public double getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public double getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void grow(double heightAdd, double widthAdd) {
|
||||
height += heightAdd;
|
||||
width += widthAdd;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Type of Tree: " + typeOfTree + " Height: " + height + " Width: " + width;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user