2024_Programming_Training_D.../CS7 - Challenge Solution/Main.java

46 lines
1.2 KiB
Java

/*
CS7 Challenge Solution
Original Challenge Description:
Write a class Ball with the following:
Characteristics
diameter (double)
color (string)
timesBounced (int)
Behaviors
bounceBall
getDiameter
getColor
getTimesBounced
Create 2 Balls
Ball 1
Diameter: 5
Color: Red
Bounce the ball 10 times
Ball 2
Diameter: 1
Color: Yellow
Bounce the ball 1 time
Print all the values for both balls
*/
public class Main {
public static void main(String[] args) {
//Create two balls, one 5 units in diameter and red,
//and another that's one unit in diameter and yellow
Ball ball1 = new Ball(5, "Red");
Ball ball2 = new Ball(1, "Yellow");
//Using a for loop, bounce ball1 10 times
for(int i = 0; i < 10; i++) {
ball1.bounceBall();
}
//Bounce ball2 once
ball2.bounceBall();
//Print information about both ball1 and ball2
System.out.println(ball1);
System.out.println(ball2);
}
}