Answered step by step
Verified Expert Solution
Question
1 Approved Answer
We've just received a feature request from the Basketballs R Us management! They've decided to start shipping basketballs without air in them, instead of inflated.
We've just received a feature request from the Basketballs R Us management! They've decided to start shipping basketballs without air in them, instead of inflated. We need to add a method to the Basketball simulation for deflating a Basketball: public void deflate () after which isDribbleable should return false. Add this method, and add a few lines to BasketballTest to verify that it's working. public class Basketball { * Inflation status of this Basketball. private boolean is Inflated; * Diameter of this Basketball. * private double diameter; * Constructs an uninflated Basketball with the given diameter. * @param givenDiameter * the diameter for this Basketball * public Basketball (double givenDiameter) isInflated = false; diameter = givenDiameter; * Returns the diameter of this Basketball. return diameter of this Basketball * public double getDiameter ! return diameter: 1 * Determines whether this Basketball can be dribbled. * @return true if the basketball is inflated, false otherwise * public boolean isDribbleable // can be dribbled only if it is inflated return isInflated; * Returns the circumference of this Basketball. * @return * circumference of this Basketball public double getCircumference // PI times the diameter double result = Math.PI * diameter: return result; * Inflates this Basketball. public void inflate isInflated = true; package lab2; /** * Try out the Basketball class. public class BasketballTest /** * Entry point. * public static void main(String[] args) { // Construct an instance and examine its attributes Basketball b = new Basketball (4.0); System. out. println (b. getDiameter()); System.out.println(b. isDribbleable()); // Construct another instance with a diameter of 6 Basketball b2 = new Basketball (6.0); // Inflate the first one b. inflate(); // First one is now dribbleable System.out.println("First basketball: + b. isDribbleable ()); // Second one is unchanged System. out.println("Second basketball: + b2. isDribbleable()); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started