Interface:

import java.awt.Rectangle;

public interface Doubler
{
	public void makeDouble(Rectangle newRectangle);
}
import java.awt.Rectangle;

public class RectangleDoubler implements Doubler
{
	private double x, y, width, height;
	RectangleDoubler()
	{
		x = 0.0;
		y = 0.0;
		width = 0.0;
		height = 0.0;
	}//end of default constructor
	public void makeDouble(Rectangle newRectangle)
	{
		x = newRectangle.getX();
		y = newRectangle.getY();
		width = newRectangle.getWidth();
		height = newRectangle.getHeight();

		width*=2;//doubling the width
		height*=2;//doubling the height

		newRectangle.setFrame(x, y, width, height);//setting the Rectangle into new parameters.
	}//end of doubleMethod()
}//end of class

Tester Class:

import java.awt.Rectangle;

public class RectangleDoublerTester
{
	public static void main(String[] args)
	{
		Rectangle box = new Rectangle(5, 10, 20, 30);
		RectangleDoubler doubler = new RectangleDoubler();
		Rectangle box2 = doubler.makeDouble(box);

		System.out.println(box);
		System.out.println("Box Expected:  x=5, y=10, width=20, height=30");
		System.out.println(box2);
		System.out.println("Box2 Expected: x=5, y=10, width=40, height=60");
	}//end of main
}//end of Tester class

I'm stuck on a homework program. Which we have to double the width and height of the Rectangle. The Tester class is set by our teacher, it can't be change.

I keep getting the error:
incompatible types at line 9 in the Tester class.

Rectangle box2 = doubler.makeDouble(box);

Also, how can I return an object? Do I have to set my method into another type?

have your makeDouble() method return a Rectangle. So something like

public interface Doubler {
     public Rectangle makeDouble(Rectangle newRectangle);
}

Thank You!

Every function declared in an interface is inherently public, so you don't need a explicit visibility modifier, also, if you don't provide a constructor with a visibility modifier the constructor will by default assume the visibility of the class it is declared in, but you should explicitly declare the visibility anyways for clarity.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.