daily pastebin goal
38%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.           public static void main(String[] args) {
  3.            
  4.             Triangle triangle = new Triangle(1, 1.5, 1);
  5.             triangle.setColor("yellow");
  6.             triangle.setFilled(true);
  7.  
  8.             System.out.println(triangle);
  9.             System.out.println("The area is " + triangle.getArea());
  10.             System.out.println("The perimeter is "
  11.               + triangle.getPerimeter());
  12.             System.out.println(filled);
  13.            
  14.           }
  15.         }
  16.  
  17.         class GeometricObject {
  18.             private String color = "yellow";
  19.             private boolean filled;
  20.             private java.util.Date dateCreated;
  21.        
  22.         /** Construct a default geometric object */
  23.             public GeometricObject() {
  24.                 dateCreated = new java.util.Date();
  25.             }
  26.         /** Geometric object with specified color */   
  27.             public GeometricObject(String Color, boolean filled) {
  28.                 dateCreated = new java.util.Date();
  29.                 this.color = color;
  30.                 this.filled = filled;
  31.             }
  32.            
  33.             public String getColor() {
  34.                 return color;
  35.             }
  36.         /** Set a new color */
  37.             public void setColor(String color) {
  38.                 this.color = color;
  39.             }
  40.         /** Returned filled. Since filled is boolean, its get method is named is Filled*/
  41.             public boolean isFilled() {
  42.                 return filled;
  43.             }
  44.         /** Set a new filled */
  45.             public void setFilled(boolean filled) {
  46.                 this.filled = filled;
  47.         /** Get dataCreated */
  48.             }
  49.             public java.util.Date getDateCreated() {
  50.                 return dateCreated;
  51.             }
  52.         /** Return a string representation of this object */
  53.             public String toString() {
  54.                 return "created on " + dateCreated + "\ncolor: " + color + "and filled: " + filled;
  55.             }
  56.        
  57.             }
  58.  
  59.         class Triangle extends GeometricObject {
  60.            
  61.             double side1 = 1.0;
  62.             double side2 = 1.0;
  63.             double side3 = 1.0;
  64.            
  65.             /** A no-arg constructor that creates a default triangle. */
  66.             public Triangle (){
  67.                 side1 = 1.0;
  68.                 side2 = 1.0;
  69.                 side3 = 1.0;   
  70.             }
  71.             /** A constructor that creates a triangle with the specified side1, side2, and side3. */
  72.             public Triangle (final double side1, final double side2, final double side3){
  73.                 this.side1 = side1;
  74.                 this.side2 = side2;
  75.                 this.side3 = side3;
  76.             }
  77.             /** The accessor methods for all three data fields. */
  78.             public void setSide1(final double side1) {
  79.                 this.side1 = side1;
  80.             }
  81.             public double getSide1(){
  82.                 return side1;
  83.             }
  84.            
  85.             public void setSide2(final double side2) {
  86.                 this.side2 = side2;
  87.             }
  88.             public double getSide2(){
  89.                 return side2;
  90.             }
  91.            
  92.             public void setSide3(final double side3) {
  93.                 this.side3 = side3;
  94.             }
  95.             public double getSide3(){
  96.                 return side3;
  97.             }
  98.             /** Method for Area */
  99.             public double getArea() {
  100.                 double s = (side1 + side2 + side3)/2;
  101.                 double area = Math.sqrt(s * (s-side1) * (s-side2) * (s-side3));
  102.                 return area;
  103.             }
  104.             /** Method for perimeter */
  105.             public double getPerimeter() {
  106.                 return side1 + side2 + side3;
  107.             }
  108.             /** Method for description */
  109.             public String toString() {
  110.                 return "A Triangle with the following dimensions: (1, 1.5, 1).\n";
  111.             }
  112.            
  113.             public boolean setFilled(){
  114.                 return filled;
  115.                
  116.             }
  117.            
  118.            
  119.            
  120.  
  121. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top