IGNOU - MCSL025 - SECTION04 - [S03_E01]

♠ Posted by Unknown in , at 10:16

IGNOU - MCSL025 - SECTION04 - [S03_E01]

/*Author: Viral Vyas

 * Write a program in Java with class Rectangle with the data fields width, 
 * length, area and colour. The length, width and area are of double type and
 * colour is of string type. The methods are set_length(), set_width(), set_colour()
 * and find_area(). Create two object of jRejcjtangle and compare their area and
 * colour. If area and color both are the same for the objects then display
 * "Matching Rectangles" otherwise display "Non matching Rectangle".

 */
package mcsl025;

//Class: Rectangle
public class S03E01Rectangle {
    private double length, width, area;
Non matching Rectangles




    public String color;
    
    //Default Constructor
    public S03E01Rectangle()
    {
        length = 0; width = 0; area = 0;
        color = null;
    }
    
    public void set_length(double l)
    { length = l; }
    
    public void set_width(double w)
    { width = w; }
    
    public void set_color(String c)
    { color = c; }
    
    public double find_area()
    {
        area = length * width;
        return(area); 
    }    
}

//Class: Main
public class S03E01Main {

    public static void main(String[] args) {
        
        S03E01Rectangle rect1 = new S03E01Rectangle();
        S03E01Rectangle rect2 = new S03E01Rectangle();
        
        rect1.set_length(5);
        rect1.set_width(6);
        rect1.set_color("Blue");
        
        rect2.set_length(7);
        rect2.set_width(8);
        rect2.set_color("Red");
        
        if((rect1.color == rect1.color) &&
                rect1.find_area() == rect2.find_area())
        {
            System.out.println("Matching Rectangles");
        }
        else
        {
            System.out.println("Non matching Rectangles");
        }        
    }
}

Output:

0 comments:

Post a Comment