Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Can anyone provide the program for this?

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can anyone provide the program for this?

    Write a class named Triangle in Java that extends class GeometricObject. The Triangle class contains:
    • Three double properties named side1, side2, and side3 with default values 1.0 to denote three sides of the triangle.
    • A no-arg constructor that creates a default triangle.
    • A constructor that creates a triangle with the specified side1, side2, and side3.
    • The get methods for all three properties.
    • A method named getArea() that returns the area of this triangle.
    o Use following formula to compute the area of a triangle.

    ​s = (side1 + side2 + side3) / 2


    • A method named getPerimeter() that returns the perimeter of this triangle.
    • A method named toString() that returns a string description for the triangle.
    o The toString() method is implemented as follows:
    return "Triangle: side1 = " + side1 + " side2 = " + side2 +" side3 = " + side3;

    Below is the source code for the GeometricObject class.

    public class GeometricObject {
    private String color = "white";
    private boolean filled;

    /* Default constructor */
    protected GeometricObject() {
    }

    /* Another constructor */
    protected GeometricObject(String color, boolean filled) {
    this.color = color;
    this.filled = filled;
    }

    public String getColor() {
    return color;
    }

    public void setColor(String color) {
    this.color = color;
    }

    public boolean isFilled() {
    return filled;
    }

    public void setFilled(boolean filled) {
    this.filled = filled;
    }
    }
    The test class has been provided below.

    public class TestTriangle {
    public static void main(String[] args) {
    Triangle triangle = new Triangle(3, 2.5, 4);
    triangle.setColor("yellow");
    triangle.setFilled(true);
    System.out.println(triangle);
    System.out.println("The area is " + triangle.getArea());
    System.out.println("The perimeter is " + triangle.getPerimeter());
    System.out.println(triangle);
    }
    }






    2/2


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Can anyone provide the program for this?

    What have you tried?

Similar Threads

  1. Can anyone provide code for following problem?
    By rohith1236 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 24th, 2012, 02:23 AM
  2. Java application using C++.Also provide some links and sample code
    By jazz2k8 in forum Java Native Interface
    Replies: 5
    Last Post: July 23rd, 2008, 06:01 AM