Results 1 to 2 of 2
Thread: Construct a rectangle
- 01-27-2010, 05:38 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 1
- Rep Power
- 0
Construct a rectangle
Hello, I have seen problems similar to mine but I have had no luck piecing other problems together to get my own end result... Here is the problem.
Write a PerimeterTester program that constructs a Rectangle object and then computes and prints its perimeter. Use the getWidth and getHeight methods. Also print the expected answer.
Here is what I have so far..
import java.awt.Rectangle;
public class assignment2
{
public static void main(String[] args)
{
Rectangle box = new Rectangle(5, 10, 20, 30);
// Move the rectangle
box.translate (15,25);
from this point I have no clue where to go with it.
- 01-27-2010, 06:14 AM #2
Senior Member
- Join Date
- Oct 2009
- Location
- California,US
- Posts
- 201
- Rep Power
- 4
first make a constructor which constructs the Rectangle with width and rectangle as its parameters
thenJava Code:public Rectangle(int w,int h) {..}
write respective getters methods for width and height.
and using main method and calculating respective perimeters for the rectangle.
2nd way ..
Java Code:import java.awt.Rectangle; public class assignment2 { public static void main(String[] args) { Rectangle box = new Rectangle(5, 10, 20, 30); // over here 20 and 30 is the width and //height by http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Rectangle.html#Rectangle(int, int, int, int) // Move the rectangle //box.translate (15,25); <----- why?aernt you trying to find perimeter? so try using 2(box.getWidth()+box.getHeight())=perimeter
Similar Threads
-
[SOLVED] Array Programming Construct?
By iPetey in forum New To JavaReplies: 3Last Post: 04-09-2009, 02:53 AM -
How to construct my finished program?
By matpj in forum New To JavaReplies: 0Last Post: 01-14-2009, 05:37 PM -
[SOLVED] Construct parents using tree path.
By Melki in forum AWT / SwingReplies: 2Last Post: 09-23-2008, 04:54 PM -
How to construct checkbox in rtf document using iText?
By soumyanil in forum Advanced JavaReplies: 0Last Post: 07-28-2008, 11:05 AM -
hi there i am stuck with a construct can anyone help???
By sonal in forum New To JavaReplies: 3Last Post: 12-05-2007, 02:22 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks