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

Recommended Answers

All 3 Replies

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.

hi

i posted this before that one.

thanx for ur help :cheesy:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.