Consider a graphics system that has classes for many figures

Assignment Help Computer Graphics
Reference no: EM13950916

// --------------------------------
// ----- 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.

Reference no: EM13950916

Questions Cloud

How would you try to handle it in planning your research : Describe two dilemmas that a counselor might face in attempting to plan research with clinical populations. Why are they ethical dilemmas? What principles of ethical research are involved? How would you try to handle it in planning your research
Why a powerpoint presentation would be appropriate. : If you would use sound in the presentation, tell us what type of sound would be used and why it would be appropriate to include it
Company return on equity : Calculate the company's return on equity and explain whether the managers are providing a good return on the capital provided by the company's shareholders. Diagram and explain the operating cycle of a service company.
How you can create an environment for young children : Choose four of the criteria for developing concept explorations. Explain why these are important. Discuss how you can create an environment for young children that promotes using the five senses
Consider a graphics system that has classes for many figures : 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.
Assume that the assistant to the manager : Assume that the assistant to the manager, using fundamental analysis, develops estimates of expected rate of returns, labeled (Ri), for these stocks. Determine which stock(s) the manager of Alma Funds should include in his portfolio.
Determine the coordinates of the point b where the water : The water sprinkler, positioned at the base of a hill, releases a stream of water with a velocity ofv = 33 ft/s as shown in (Figure 1). Assume that the hill is defined by the equation y=(0.05x2)ft and neglect the size of the sprinkler. Determine the ..
How much are cash dividends : 1. How much are cash dividends? 2. What was the amount of the cash receipt from the sale of plant assets?
Identify biases-concerns : Comment on this design. Identify biases, concerns, and why you might question any results. Suggest an improved design. Be sure to specify your design completely; include a diagram if appropriate; discuss how you would implement your study.

Reviews

Write a Review

Computer Graphics Questions & Answers

  Create a simple warm-up program using your g3d

Create a simple warm-up program using your G3D programming and graphics environment.

  Shadow effect while rolling a sphere

Shadow effect while rolling a sphere as well as the options of shading and lighting.

  Relative positioning and interactive positioning

Relative Positioning and Interactive Positioning by Dragging and Clicking and some Simple Animation

  Draw a teapot at the global origin

Draw a teapot at the global origin

  Concepts of computer graphics

Concepts of Computer Graphics and develop a program using OpenGL

  The security policy document outline

Using the GDI Case Study below, complete the Security Policy Document Outline

  Develop the image manipulations

Develop the image manipulations

  What does resolution mean

What does resolution mean How is resolution connected to ppi and dpi units

  Differentiate between a bitmap image and a vector image

Differentiate between a bitmap image and a vector image Explain the following terms

  Essential elements of a design pattern

configuration of an Iterator pattern, patterns could be used in a Library System, Singleton, Template, Decorator, Façade,What does Alexander means by the following declaration "But it is impossible to form anything which has the temperament of natu..

  Framework of user interface design

design of user interfaces, natural mapping, GUI applications, web page design different to designing for printed media, risks exposed in this "phone as individual proxy" approach, interaction designers of ubicomp applications, Storyboards are usual..

  What are the factors affecting picture composition

Define picture composition What are the factors affecting picture composition. Elaborate on each factor Describe the basic lines present in a composition

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd