U.S. CitiesCity-Data Forum Index
Go Back   City-Data Forum > General Forums > Education
 [Register]
Please register to participate in our discussions with 2 million other members - it's free and quick! Some forums can only be seen by registered members. After you create your account, you'll be able to customize options and access all our 15,000 new posts/day with fewer ads.
View detailed profile (Advanced) or search
site with Google Custom Search

Search Forums  (Advanced)
 
Old 11-26-2010, 09:28 AM
 
Location: usa
79 posts, read 162,323 times
Reputation: 32

Advertisements

Hi guys,
I have a java programming problem that need to be solved ASAP . I tried hard but could not solve it!!!
Can someone help?
Here is the problem:
This program uses polymorphism to execute simple shapes: circles, squares, and rectangles. The mouse is used to click on a window, and wherever you click, a shape will appear randomly (each shape type has its own color: circles are green, squares are yellow, and rectangles are blue).

The implementation should make use of an ArrayList, but your ArrayList should store the shape objects themselves. For this to work, you will need to define a class for each shape object. Of course, each object will need to store its color. But also, each class will need to provide a draw() method that takes a Graphics object as argument, and draws itself with the appropriate commands on that Graphics object. You must use polymorphism to implement this program. All of your various shape classes should extend a Shape abstract class (which you also define). This will allow you to store an ArrayList of Shapes in the JPanel part of your program.

Then, modify your program so that if you click on existing shapes, they become red, but if you click on the background, you get a new shape (as before). For this to work, your shapes should implement a Boolean method (maybe call it contains) that takes a Point as argument, and returns true or false in accordance with the appropriate geometric calculation. (This is why each of your geometric objects needs its own implementation for contains().) Back in your JPanel subclass, where you are handling mouse clicks, you need to insert a check: run through your list of shapes, and determine which of them contain the point where the user just clicked. If so, change those shapes' colors to red. But if the click point was not inside any of the existing shapes, generate a random shape at that location, as you were doing in the first part of this assignment. ). Again Your Shape superclass should define abstract methods draw() and contains() (and maybe others).

Thank you sooooooooooo much for your help!!

 
Old 11-26-2010, 10:05 AM
 
12,740 posts, read 28,682,531 times
Reputation: 7314
Sorry, but this is not a homework help site. Try this: Programming Online Experts

Posters, feel free to reply to OP via DM.
__________________
Please follow THESE rules.

Any Questions on how to use this site? See this.

Realtors, See This.

Moderator - Lehigh Valley, NEPA, Harrisburg, Philadelphia, Pennsylvania, Delaware, Education and Colleges and Universities.

When I post in bold red, that is Moderator action and per the TOS can be discussed only via Direct Message.
Closed Thread

Over $104,000 in prizes was already given out to active posters on our forum and additional giveaways are planned!

Go Back   City-Data Forum > General Forums > Education
Similar Threads
Follow City-Data.com founder on our Forum or

All times are GMT -6.

© 2005-2020, Advameg, Inc. · Please obey Forum Rules · Terms of Use and Privacy Policy · Bug Bounty

City-Data.com - Archive 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35 - Top