Whenever I try to scale the shape, nothing happens and then the console stops responding to input.
Here is the set scale command:
case 7: do
{
System.out.println("\nEnter scale factor");
scale=input.nextDouble();
}
while(scale<0);
Shape.setScaleFactor(scale);
break;
Here is the scale shape command
case 4: for(i=0; i<s.length; i++)
{
if(s[i]!=null)
{
s[i].scaleShape();
}
}
break;
Here is the main method variables:
int i=0;
int m=0;
double scale;
boolean exit=false;
Shape[] s = new Shape[10];
Here are all the relevant methods in the shape class;
private static double scaleFactor;
public static double getScaleFactor()
{
return scaleFactor;
}
//Set ScaleFactor
public static void setScaleFactor(double x)
{
scaleFactor=x;
}
Here is the scaleshape method in the rectangle subclass
private double base;
private double height;
@Override public void scaleShape()
{
base=base*getScaleFactor(); height=height*getScaleFactor();
}
public abstract void scaleShape();
Here is the set scale method in the circle class:
private final double pi = Math.PI;
private double radius;
@Override public void scaleShape()
{
radius*=getScaleFactor();
}
My guess is that your problem is here:
What happens if you add some logging?
If you don’t get what you’re expecting, it might be worthwhile to read in a
Stringinstead just to see what input you’re actually getting. You can always read a String, log it, then useDouble.valueOf(String)to convert it.Another possibility is that it’s working, but you never reset
scaleand this is in some sort of loop, so it just continues scaling the shape forever but never stops to ask for input again.