|
-
help with this
1-Write a class named Rectangle to represent rectangles. The data field are width and height. Use double for width and height. You need to provide the accessor methods for the properties and methods findArea()
2. Write a client program to create two rectangle with the following descriptions any length and width
the first rectangle must be red and the second yellow
I got the rectangel and the are but how do i setcolor
public class Rectangle {
private double length;
private double width;
public Rectangle(double l, double w)
{
length = l;
width = w;
}
public double calculateArea()
{
return length * width;
}
public static void main(String[] args) {
double r1 = 0;
double r2 = 0;
Rectangle rectangle1 = new Rectangle(10,10);
Rectangle rectangle2 = new Rectangle(10,20);
r1 = rectangle1.calculateArea();
r2 = rectangle2.calculateArea();
System.out.println("rectangle1 area " + r1);
System.out.println("rectangle2 area " + r2);
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks