Java [Constructor Problem]

Nenad

~Choco Coronet~ Omnomnom
Reaction score
137
Been a while since i asked for help (mostly cause I was doing well), but now I've run into a problem.

This is what I'm supposed to do:

Write a class called GCircle (public class GCircle extends GObject implements ...)

The purpose of this class is to easily be able to draw circles.

GCircle must have the following methods:

GCircle(double) [constructor]

getRadius()

setRadius(double)

In addition, GCircle must implement necessary methods from the superclass and implemented interfaces. You must decide which of the interfaces GScalable, GFillable and GResizable it makes sense to implement, and hence which additional methods that must be implemented.

As you may have noticed I need to use an extension program called ACM, of which the libraries are found here: Link..

That being said I'm having a serious problem with making the constructor. I just don't understand how to make a constructor that works such as:

public GCircle(double x)
{
??? GOval(x,x)
}
profit.

I need to use the GOval class (at least i believe so) because i need to draw a circle, and it will draw a circle when i use the class, but i can't get it to work. This class is invoked from another class, GSpriteProgram, which is basically this:

Code:
import acm.graphics.GCanvas;
import acm.program.GraphicsProgram;

public class GSpriteProgram extends GraphicsProgram {
	
	public void run() {
		GCircle circle = new GCircle(20.0);
		circle.setLocation(50, 20);
		GSprite sprite = new GBouncingObject("workspace/sprite1.png");
		sprite.setSpeed(20, 30);
		add(circle);
		add(sprite);
	}
}

I've already written the sprite code and that code works properly, but this code does not create a circle because i lack the proper constructor. Therefore i'm stumped, if you need any more information ask me so i can get passed this issue.
 

Nenad

~Choco Coronet~ Omnomnom
Reaction score
137
Code:
public class GCircle extends Gobject implements GScalable, GFillable {
private double radius;

public GCircle(double x)
{
super(x,x);
radius = x/2;
}

public double getRadius()
{
  return this.radius;
}

public void setRadius(double x)
{
 this.radius = x/2;
}

}

Edit: FIXED. Extended GOval rather than GObject. ^^
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top