Adding early CS challenge solutions

This commit is contained in:
2024-06-28 17:02:20 -04:00
parent 1c2266f4c5
commit 79772e0ee0
9 changed files with 343 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
public class Ball {
private double diameter;
private String color;
private int timesBounced;
public Ball(double newDiameter, String newColor) {
diameter = newDiameter;
color = newColor;
timesBounced = 0;
}
public double getDiameter() {
return diameter;
}
public String getColor() {
return color;
}
public int getTimesBounced() {
return timesBounced;
}
public void bounceBall() {
timesBounced++;
}
public String toString() {
return "This ball is " + color + " with a diameter of " +
diameter + " and has been bounced " + timesBounced +
" times!";
}
}

View File

@@ -0,0 +1,15 @@
public class Main {
public static void main(String[] args) {
Ball ball1 = new Ball(5, "Red");
Ball ball2 = new Ball(1, "Yellow");
for(int i = 0; i < 10; i++) {
ball1.bounceBall();
}
ball2.bounceBall();
System.out.println(ball1);
System.out.println(ball2);
}
}