Reputation: 1
Very new to java and having an issue on a lab assignment. The problem I'm having is at the bouncing part, as I have it right now it gives me IllegalFormatConversionException: d!=Ball
. I've tried various options with my, thus far, limited knowledge, with the printf
statement and the other error I'm mostly encountering then is Cannot find symbol. any hints to help me understand how to get this to print "bouncing 14 times" will be greatly appreciated.
public class Ball
{
private double size;
public double getSize()
{
return size;
}
public void setSize(double s)
{
if(s >= 0)
{
size = s;
}
}
public void roll()
{
}
public void bounce(int numberOfBounces)
{
}
}
public class BallApp
{
public static void main(String[] args)
{
Ball myBall = new Ball();
myBall.setSize(5);
System.out.printf("Ball with size %.0f\n", myBall.getSize());
myBall.roll();
System.out.println("rolling...");
myBall.bounce(14);
System.out.printf("bouncing %d times", myBall);
myBall.setSize(7);
System.out.printf("Size %.0f\n", myBall.getSize());
}
}
the end outcome should read
Ball with size 5
rolling . . .
bouncing 14 times
size: 7
Upvotes: 0
Views: 94
Reputation: 1763
You need to have a method that returns you the number of bounces that already happened. Like:
public int getBounces(){
return this.bounces;
}
Then you could do
myBall.bounce(14);
System.out.printf("bouncing %d times", myBall.getBounces());
But you have to increment the bounces counter in the bounce method first.
Upvotes: 3