This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please help - Need advice

 
Rob Shan Lone
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ya, at the bottom I have listed the criteria. I need to create a basic graphics package. However I need advice on the most effective and efficient simple way of doing this?
I am very keen to start off with a switch statement, is this the right thing to do for this occassion? Please take a look at my code and help me come up with a working model. The coffee is brewing guys I got the notes and the books out but I'm kinda stumped. By the way I am only a student so please constuctive critism if any.
My first question is what should the next step be and what layout should work?
Rob

===============================================================
Hello I have been given this task to do:
Develop a basic graphics package.
Use the Shape class inheritance hierarchy shown below.
a. Limit yourself to two dimensional shapes such as squares, rectangles, triangles and circles.
b. Interaction with the user must be demonstrated.
c. Let the user specify the position, size and shape to be used in drawing each shape.
d. The user can specify many items of the same shape.
e. As you create each shape, place a Shape reference to each new shape object into an array.
f. Each class has its own draw method. Write a polymorphic screen manager that walks through the array sending draw messages to each object in the array to form a screen image.
g. Redraw the screen image each time the user specifies an additional shape. Investigate the methods of class Graphics to help draw each shape.
Shape
/ \
TwoDimensionalShape ThreeDimensionalShape
/ | \ / | \
Circle Square Triangle Sphere Cube Tetrahedron
====================================================================
[ January 03, 2004: Message edited by: Michael Ernest ]
[ January 03, 2004: Message edited by: Tony Alicea ]
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edited code for readability.
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Added imports...
 
Rob Shan Lone
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this look better?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Shape extends JFrame
{
public class TwoDimensionalShape
{
public class Circle
{
}
public class Square
{
}
public class Triangle
{
}
}

public class ThreeDimensionalShape
{
public class Sphere
{
}
public class Cube
{
}
public class Tetrahedron
{
}
}

public Shape( )
{
super( "Drawing lines, rectangles and ovals" );
setSize( 400, 165 );
show( );
}

public void main( String args[] )
{
Shape Shape = new Shape();
}
}
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Shan Lone:
Does this look better?

Rob, try using [CODE] tags to surround your source code, that will preserve the whitespace and make it more readible. (same goes for your little Shape / TwoDimensionalShape diagram) Good Luck
 
Rob Shan Lone
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys if the Shape class inheritance hierarchy
is this what my code should look like?
===================shape
==================/-----\
=========2 dimension shape-----------3 dimension shape
=======/--------|------\----------/-----|----\
====circle--square--triangle===sphere--Cube--Tetrahedron

I got to
1) Develop a basic graphics package.
Use the Shape class inheritance hierarchy shown below.
a. Limit yourself to two dimensional shapes such as squares, rectangles, triangles and circles.
b. Interaction with the user must be demonstrated.
c. Let the user specify the position, size and shape to be used in drawing each shape.
d. The user can specify many items of the same shape.
e. As you create each shape, place a Shape reference to each new shape object into an array.
f. Each class has its own draw method. Write a polymorphic screen manager that walks through the array sending draw messages to each object in the array to form a screen image.
g. Redraw the screen image each time the user specifies an additional shape. Investigate the methods of class Graphics to help draw each shape.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic