Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Graphics Expert

// --------------------------------
// ----- ENTER YOUR CODE HERE -----
// --------------------------------

// --------------------------------
// --------- END USER CODE --------
// --------------------------------

/**
Simple demo program that tests the stub methods of the Figure, Triangle,
and Rectangle classes.
*/
public class FigureDemo {

public static void main(String[] args) {
Figure f1 = new Figure(7, 7);
Figure t1 = new Triangle(5, 5, 5, 10);
Figure r1 = new Rectangle(15, 15, 5, 10);

System.out.println("Testing the draw() methods:");
f1.draw();
t1.draw();
r1.draw();
System.out.println();

System.out.println("Testing the center() methods:");
f1.center();
t1.center();
r1.center();
System.out.println();

System.out.println("Testing the erase() methods:");
f1.erase();
t1.erase();
r1.erase();
}

}

Consider a graphics system that has classes for various figures, say rectangles, boxes, triangles, circles and so on. For example, a rectangle might have data members height, width, and center point, while a box and circle might have only a center point and an edge length or radius respectively. In a well designed system these would be derived from a common class, Figure. You are to implement such a system.
The class Figure is the base class. You should add only Rectangle and Triangle classes derived from Figure. Each class has stubs for methods erase and draw. Each of these methods outputs a message telling the name of the class and what method has been called. Since these are just stubs, they do nothing more than output this message. The method center calls the erase and draw methods to erase and redraw the figure at the center. Since you have only stubs for erase and draw, center will not do any "centering" but will call the methods erase and draw which will allow you to see which versions of draw and center it calls. Also, add an output message in the method center that announces that center is being called. The methods should take no arguments. Also, define a demonstration program for your classes.
For a real example, you would have to replace the definition of each of these methods with code to do the actual drawing. You will be asked to do this in Programming Project 2.
In class Figure, you should define the following methods:
public Figure(int centerX, int centerY)
public void draw()
public void erase()
public void center()
public int getCenterX()
public void setCenterX(int centerX)
public int getCenterY()
public void setCenterY(int centerY)
public String toString()
public boolean equals(Object other)
In class Rectangle, you should define:
public Rectangle(int centerX, int centerY, int width, int height)
public void draw()
public void erase()
public int getWidth()
public void setWidth(int width)
public int getHeight()
public void setHeight(int height)
public String toString()
public boolean equals(Object other)
In Triangle, you should define:
public Triangle(int centerX, int centerY, int baseLength, int height)
public void draw()
public void erase()
public int getBaseLength()
public void setBaseLength(int baseLength)
public int getHeight()
public void setHeight(int height)
public String toString()
public boolean equals(Object other)

Since all Figures have a center point, the implementation of the center method in the Figure superclass could contain the logic for moving any Figure to the center of the display. It should therefore only be necessary to implement the center method in the Figure superclass, and not in any of the subclasses.

In order for your solution to compile and execute properly within CodeMate, you should not declare the Figure, Rectangle, and Triangle classes to be public. For example, instead of:
public class Figure {
// Implementation goes here...
}
you should declare the class as:
class Figure {
// Implementation goes here...
}
The constructors in your implementation of the Triangle and Rectangle subclasses should invoke the appropriate superclass constructor.

Computer Graphics, Computer Science

  • Category:- Computer Graphics
  • Reference No.:- M91621756
  • Price:- $30

Priced at Now at $30, Verified Solution

Have any Question?


Related Questions in Computer Graphics

The saffir-simpson hurricane scale classifies hurricanes

The Saffir-Simpson Hurricane Scale classifies hurricanes into five categories numbered 1 through 5. Write an application named Hurricane that outputs a hurricane's category based on the user's input of the wind speed. CA ...

The problemyou are to search a bitmap in rgb format and

The problem: You are to search a bitmap in RGB format and count the number of pixels which match a set of colors. The bitmap will be 1024 by 1024 pixels for the purposes of explaining this problem. The set of colors will ...

Question a describe the architecture of simple raster

Question : a) Describe the architecture of simple raster graphics system? b) Explain raster scan display processor?

You have a program draw a rectangle on the screen and allow

You have a program draw a rectangle on the screen and allow the user to change the color/size of the rectangle. The program will store in the browser the settings of the color/size so that upon revisiting the page, the v ...

The problemsit is strongly recommended that you tackle the

The problems: It is strongly recommended that you tackle the following tasks in a modular way -- a separate standalone function for each task. Draw a rectangle as a Rectangle and as a Polygon. Make the lines of the Polyg ...

Please read my question if you post copy and pasted code

Please read my question if you post copy and pasted code you will get a negative review. This is java In this graphical program, you are going to simulate arcade car racing game. You need a single player that is movable ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As