help with this


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: help with this

  1. #1
    Join Date
    Apr 2003
    Posts
    6

    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);


    }
    }

  2. #2
    Join Date
    Mar 2003
    Posts
    86

    Color

    You can easily add color, the problem is you will not be able to see it with System.out
    What you can do is write a litle UI frame add your two rects, and paint them there with cooresponding colors.

    Sharbov.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center