The question is below and it is the only one I cant for a project due tomarrow.
Question.
Write a class called shapes that accepts two variables into its constructor called a and b. Along with the getter and setter methods required, write a method called toPrinter() to output the coordinates of the shape in the following format: [a, b].
Next write a class called orange that is a child class of shapes. This time the constructor accepts in a, b (centre of the orange), and a radius. Override the toPrinter() method in the orange class to include outputting the radius, as well as a and b. Write a method to get the area of the orange. Include any relevant classes to run and test the application.
I can do the first part but not the second.
This is what I have so far.
Code: (Java)
class Shapes
{
public static void main(String[] args)
{
Shapes x = new Shapes(5,6);
x.toPrinter();
}
protected double a;
protected double b;
public Shapes(double a, double b)
{
this.a = a;
this.b = b;
}
public double geta()
{
return a;
}
public double getb()
{
return b;
}
protected void seta(double ia)
{
a = ia;
}
protected void setb(double ib)
{
b = ib;
}
void toPrinter()
{
System.out.println("The coordinates are [" + a +","+ b + "]");
}
}
class Orange extends Shapes
{
Orange y = new Orange(a,b,7);
y.area();
y.toPrinter();
private double radius;
private double area;
public Orange (double a, double b, double radius)
{
super(a,b);
this.radius = radius;
}
void area()
{
this.area = (3.14) *(radius) * (radius);
}
void toPrinter()
{
System.out.println("The coordinates are [" + a +","+ b + "]");
System.out.println("The radius is " + radius);
System.out.println("The area is " + area);
}
public double getradius()
{
return radius;
}
public double getarea()
{
return area;
}
protected void setradius(double iradius)
{
radius = iradius;
}
protected void setarea(double iarea)
{
area = iarea;
}
}
// the orange class is on a seperate java file. when i go to compile it, an error shows up saying:
Orange.java:5: <identifier> expected
y.area();
Orange.java:6: <identifier> expected
y.toPrinter();
^
2 errors