class Circle
{
private double radius;
private String colour;
Circle()
{
}
Circle(double r, String c)
{
this.radius=r;
this.colour=c;
}
public void display()
{
System.out.println("Radius of circle is "+this.radius);
System.out.println("Colour of circle is "+this.colour);
}
public String getColour()
{
return (this.colour);
}
}
how calculate and display the number of these Circle objects that have the colour attribute value equals to “red”,with use the equals() or compareTo() methods to compare strings.
import javax.swing.JOptionPane;
class TestCircle
{
public static void main(String []args)
{
double rad;
String clr;
Circle test[]=new Circle[5];
for(int i=0;i<5;i++)
{
rad=Double.parseDouble(JOptionPane.showInputDialog(null,"Enter radius of circle "+(i+1)));
clr=(JOptionPane.showInputDialog(null,"Enter colour of circle "+(i+1)));
test[i] = new Circle(rad, clr);
}
for (int i=0;i<5;i++)
{
System.out.println("properties of circle "+(i+1));
test[i].display();
}
}
}