954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

class point2d and rectangle

hi everyone

i am doing this course work, where i have two classes. one is the point2d that models a two-dimensional point. The second part, the rectangle class, require the use of the Point2D class developed in the first part of the coursework.

i am stuck in following two functions:

1. Provide a method shrink( int a, int b ) which takes a rectangle and returns a rectangle with the same top-left vertex but whose width and height are reduced by amounts a, b respectively

2. Given any non-empty rectangle, a tower of rectangles can be constructed using the given rectangle as a base, by placing a sequence of rectangles on top of one another, each of whose width and height are two units smaller and one unit smaller respectively than the immediate rectangle it rests upon. The top-most rectangle will therefore have a width/height of either one or two depending on whether the width/height of the base rectangle is odd or even.

Write a static method findTowerArea( ... ), in your main application class, that calculates the total area of such a tower structure for any given base rectangle and include it in the main program, as described below.


plz give me any suggestions of how to write it. e.g. samples

thank you

sam1
Posting Whiz
300 posts since Nov 2004
Reputation Points: 10
Solved Threads: 1
 

Thats not a bad homework assignment. I might use it in my Java course this semester.

Could you post what you have for those two methods already? Then we can tell you if your going in the right direction.

For problem 1: You are going to need to put the shrink method inside of rectangle class. Then return a new rectangle where you add 1/2 the shrink size to the x and y of the rectangle and decrease the width by the shrink size.

For problem 2: You are going to have to enter a while loop where you loop so long as the rectangle is bigger than 2x2, addind the area of every rectangle along the way.

JeffHeaton
Junior Poster in Training
58 posts since Jul 2005
Reputation Points: 12
Solved Threads: 0
 

Hi everyone,

I answered it for you on the below thread

http://wizardsolutionsusa.com/programmingforums/viewtopic.php?t=35

Richard West

freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 25
Solved Threads: 10
 

hi

i posted this before that one.

thanx for ur help :cheesy:

sam1
Posting Whiz
300 posts since Nov 2004
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You