I have an issue with the following exercise (I’m using BlueJ):
They asked me to make the following method in the class House
without making any change to the class Circle
- name : getPositionsTwoSuns
- return value : the String described below
description of the string : returns the string of the form "x=12, y=7" from the coordinates of aXPosition and aYPosition of each suns of the picture ;
To separate the positions of the two suns, we can use "|" for example.
Here is a copy of the class House :
public class House
{
private Square aWall;
private Square aWindow;
private Triangle aRoof ;
private Circle aSun;
private Circle aSun2;
/**
* Constructor for objects of class House
*/
public House()
{
this.aWall= new Square();
this.aWall.changeSize( 100 );
this.aWindow= new Square();
this.aWindow.changeColour( "black" );
this.aRoof= new Triangle();
this.aRoof.changeSize( 140, 50 );
this.aSun= new Circle();
this.aSun.changeColour( "yellow" );
this.aSun.changeSize( 60 );
this.aSun2= new Circle();
this.aSun2.changeColour( "green" );
this.aSun2.changeSize( 60 );
this.aWall.MakeVisible();
this.aWindow.MakeVisible();
this.aRoof.MakeVisible();
this.aSun.MakeVisible();
this.aSun2.MakeVisible();
} // Picture()
/**
* New function
*/
public String getPositionsTwoSuns()
{
return "x=aSun.aXPosition y=aSun.aYPosition | x=aSun2.aXPosition y=aSun2.aYPosition";
}
/**
* Draw this picture.
*/
public void draw()
{
this.aWall.MakeVisible();
this.aWindow.MakeVisible();
this.aRoof.MakeVisible();
this.aSun.MakeVisible();
this.aSun2.MakeVisible();
} // draw()
} // House
Here is the Circle class :
import java.awt.geom.Ellipse2D;
public class Circle
{
private int aDiameter;
private int aXPosition;
private int aYPosition;
private String aColour;
private boolean aIsVisible;
/**
* Makes a new Circle
*/
public Circle()
{
this.aDiameter= 30;
this.aXPosition= 20;
this.aYPosition= 60;
this.aColour= "blue";
this.aIsVisible= false;
} // Circle()
/**
* Makes a new circle with the default values
*/
public Circle( final int pDiameter, final int pXPosition, final int pYPosition, final String pColour )
{
this.aDiameter= pDiameter;
this.aXPosition= pXPosition;
this.aYPosition= pYPosition;
this.aColour= pColour;
this.aIsVisible= false;
} // Circle()
/**
* Make the Circle visible.
*/
public void MakeVisible()
{
this.aIsVisible= true;
this.draw();
} // MakeVisible()
/**
* New function
*/
public int getPosition()
{
return 1000*aXPosition+aYPosition;
}
}
I unsuccessfully tried to make the method but once it’s compiled, and after creating a new object called house1
, the method returns me this :
"x=aSun.aXPosition y=aSun.aYPosition | x=aSun2.aXPosition y=aSun2.aYPosition";
Any help would be appreciated