Initial Commit

This commit is contained in:
Bradley committed 2024-05-14 18:45:10 -04:00
commit c90b3a95fe
10 files changed
+421

No files matched your search

+12
View 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
View 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;
}
}