"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 the first part of the question but not the second paragraph. I am finding it difficult using inheritance.
Below is my solution so far.Can anyone spot where I am going wrong with the inheritance?
Expand|Select|Wrap|Line Numbers
- public class Shapes_5
- {
- public static void main(String[] args)
- {
- Shapes_Values c = new Shapes_Values();
- c.setValueA(5);
- c.setValueB(14);
- c.goToPrinter();
- }
- }
- class Shapes_Values
- {
- int ValueA;
- int ValueB;
- void setValueA(int iValueA) //setter method
- {
- ValueA = iValueA;
- }
- void setValueB(int iValueB) //setter method
- {
- ValueB = iValueB;
- }
- int getValueA() //getter method
- {
- return ValueA;
- }
- int getValueB() //getter method
- {
- return ValueB;
- }
- void goToPrinter() //Outputs the coordinates of the shape
- {
- System.out.println("[" + ValueA + "," + ValueB + "]");
- }
- }
- class Orange extends Shapes_5
- {
- Shapes_Values c = new Shapes_Values();
- c.setValueRadius(2);
- }
- class Shapes_Values
- {
- int ValueRadius;
- void setValueRadius(int iValueRadius) //setter method
- {
- ValueRadius = iValueRadius;
- }
- int getValueRadius() //getter method
- {
- return ValueRadius;
- }
- }
Thanks in advance!!