Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

//I want to display expected output. however, I don\'t know what is wrong. thank

ID: 3777835 • Letter: #

Question

//I want to display expected output. however, I don't know what is wrong. thank you

import java.util.Scanner;

public class Exercise11_01 {

   public static void main(String[] args) {

      Scanner input = new Scanner(System.in);

      System.out.print("Enter three sides: ");

      double side1 = input.nextDouble();

      double side2 = input.nextDouble();

      double side3 = input.nextDouble();

  

      Triangle triangle = new Triangle(side1, side2, side3);

  

      System.out.print("Enter the color: ");

      String color = input.next();

      triangle.setColor(color);

  

      System.out.print("Enter a boolean value for filled: ");

      boolean filled = input.nextBoolean();

      triangle.setFilled(filled);

      System.out.println("The area is " + triangle.getArea());

      System.out.println("The perimeter is "

   + triangle.getPerimeter());

      System.out.println(triangle);

      }

   }

class Triangle extends GeometricObject {

  

   private double side1;

   private double side2;

   private double side3;

  

   public Triangle(double s1, double s2, double s3) {

   side1=s1;

   side2=s2;

   side3=s3;

   }

  

   public double getside1()

   { return side1; }

  

   public double getside2()

   { return side2; }

   public double getside3()

   { return side3; }

  

   public double getArea() {

       double s= (side1 +side2+side3)/2 ;

       double area = s* (s-side1)*(s-side2)*(s-side3);

       return Math.pow(area, 0.5);

   }

  

   public double getPerimeter(){

       return (side1 +side2+ side3);

   }

  

   public String toString()

   {

       return "Triangle: side1 = " +side1 + " side2 = " +side2 + " side3 = " +side3;

   }

   public static void main(String[] args){

       double s1, s2,s3;

       String color;

       boolean filled;

      

       Scanner input = new Scanner(System.in);

      

       System.out.println("Enter color: ");

       color = input.nextLine();

      

       System.out.println("Enter sides: ");

       s1 = input.nextDouble();

       s2 = input.nextDouble();

       s3 = input.nextDouble();

      

       System.out.println("Fill triangle or not: ");

       filled = input.nextBoolean();

      

       Triangle t = new Triangle(s1, s2, s3);

      

       t.setColor(color);

       t.setFilled(filled);

      

       System.out.println("Sides of " + t.toString());

       System.out.println("Area of Triangle " + t.getArea());

       System.out.println("Perimeter of triangle " + t.getPerimeter());

       System.out.println("Color of the Triangle is " + t.getColor());

       System.out.println("is triangle filled " + t.isFilled());

  

   }

  

  

  

}

abstract class GeometricObject

{

   private String color = "white";

   private boolean filled;

   private java.util.Date dateCreated;

  

   protected GeometricObject(){

       dateCreated = new java.util.Date();

   }

   protected GeometricObject(String color, boolean filled){

       dateCreated = new java.util.Date();

       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;

   }

   public java.util.Date getDateCreated(){

       return dateCreated;

   }

   public String toString(){

       return "created on " +dateCreated + " color: "+color+ " and filled: " + filled;

   }

   public abstract double getArea();

  

   public abstract double getPerimeter();

}

Incorrect Hint: The input for this test is 34.5 56.4 36.9 black true The expected output pattern is 616. 127.80000000000001. (Note that the symbols are the separators for matching terms. They are not part of the expected output.

Explanation / Answer

You need to make three java files to get output.

1. Exercise11_01.java

2. Triangle.java

3. GeometricObject.java

Save the data in these three file and run 1st or 2nd file.

Add import java.util.Scanner; in Triangle.java file

You will get output.

1. Exercise11_01.java

import java.util.Scanner;
public class Exercise11_01 {
    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        System.out.print("Enter three sides: ");

        double side1 = input.nextDouble();

        double side2 = input.nextDouble();

        double side3 = input.nextDouble();

        Triangle triangle = new Triangle(side1, side2, side3);

        System.out.print("Enter the color: ");

        String color = input.next();

        triangle.setColor(color);

        System.out.print("Enter a boolean value for filled: ");

        boolean filled = input.nextBoolean();

        triangle.setFilled(filled);

        System.out.println("The area is " + triangle.getArea());

        System.out.println("The perimeter is "

         + triangle.getPerimeter());

        System.out.println(triangle);

      }

    }

2. Triangle.java

import java.util.Scanner;
class Triangle extends GeometricObject {

    private double side1;

    private double side2;

    private double side3;

    public Triangle(double s1, double s2, double s3) {

     side1=s1;

     side2=s2;

     side3=s3;

    }

    public double getside1()

    { return side1; }

    public double getside2()

    { return side2; }

    public double getside3()

    { return side3; }

    public double getArea() {

        double s= (side1 +side2+side3)/2 ;

        double area = s* (s-side1)*(s-side2)*(s-side3);

        return Math.pow(area, 0.5);

    }

    public double getPerimeter(){

        return (side1 +side2+ side3);

    }

    public String toString()

    {

        return "Triangle: side1 = " +side1 + " side2 = " +side2 + " side3 = " +side3;

    }

    public static void main(String[] args){

        double s1, s2,s3;

        String color;

        boolean filled;

        Scanner input = new Scanner(System.in);

        System.out.println("Enter color: ");

        color = input.nextLine();

        System.out.println("Enter sides: ");

        s1 = input.nextDouble();

        s2 = input.nextDouble();

        s3 = input.nextDouble();

        System.out.println("Fill triangle or not: ");

        filled = input.nextBoolean();

        Triangle t = new Triangle(s1, s2, s3);

        t.setColor(color);

        t.setFilled(filled);

        System.out.println("Sides of " + t.toString());

        System.out.println("Area of Triangle " + t.getArea());

        System.out.println("Perimeter of triangle " + t.getPerimeter());

        System.out.println("Color of the Triangle is " + t.getColor());

        System.out.println("is triangle filled " + t.isFilled());

   }

}

3. GeometricObject.java

abstract class GeometricObject

{

    private String color = "white";

    private boolean filled;

    private java.util.Date dateCreated;

    protected GeometricObject(){

        dateCreated = new java.util.Date();

    }

    protected GeometricObject(String color, boolean filled){

        dateCreated = new java.util.Date();

        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;

    }

    public java.util.Date getDateCreated(){

        return dateCreated;

    }

    public String toString(){

        return "created on " +dateCreated + " color: "+color+ " and filled: " + filled;

    }

    public abstract double getArea();

    public abstract double getPerimeter();

}

Output :-

Enter three sides: 34.5
56.4
36.9
Enter the color: black
Enter a boolean value for filled: true
The area is 616.7889833646517
The perimeter is 127.80000000000001
Triangle: side1 = 34.5 side2 = 56.4 side3 = 36.9