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

Need help writing java code import java.beans.PropertyChangeListener; import jav

ID: 3851057 • Letter: N

Question

Need help writing java code

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

//---------------------------------------------------------------
/**
* The right triangle model. Allows users to update the base and height
* separately.
*

public class RTModel {
// Constants.
/**
* Used to signal a change in the base value property of the model.
*/
public static final String BASE_CHANGE = "Base Changed";
/**
* Used to signal a change in the height value property of the model.
*/
public static final String HEIGHT_CHANGE = "Height Changed";
/**
* The maximum size of each of the two non-hypotenuse sides of the triangle.
*/
public static final double MAX_SIDE = 100.0;
/**
* The initial size of the base.
*/
private double base = 35.0;
/**
* The initial size of the height.
*/
private double height = 35.0;
/**
* The initial size of the hypotenuse based upon base and height.
*/
private double hypotenuse = Math
   .sqrt(Math.pow(this.base, 2.0) + Math.pow(this.height, 2.0));;
/**
* Allows views to listen to generic changes in the model.
*/
private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);

// ---------------------------------------------------------------
/**
* Attaches listeners to the model.
*
* @param listener
* The listener to attach to the model.
*/
public void addPropertyChangeListener(
   final PropertyChangeListener listener) {
   this.pcs.addPropertyChangeListener(listener);
}

// ---------------------------------------------------------------
/**
* Attaches listeners to the model for a particular property.
*
* @param propertyName
* The name of the property to listen for.
* @param listener
* The listener to attach to the model.
*/
public void addPropertyChangeListener(final String propertyName,
   final PropertyChangeListener listener) {
   this.pcs.addPropertyChangeListener(propertyName, listener);
}

// ---------------------------------------------------------------
/**
* Returns the value of the model's base.
*
* @return the value of the model's base.
*/
public double getBase() {
   return this.base;
}

// ---------------------------------------------------------------
/**
* Returns the value of the model's height.
*
* @return the value of the model's height.
*/
public double getHeight() {
   return this.height;
}

// ---------------------------------------------------------------
/**
* Returns the hypotenuse.
*
* @return the hypotenuse.
*/
public double getHypotenuse() {
   return this.hypotenuse;
}

// ---------------------------------------------------------------
/**
* Assigns a value to the model's base and updates all views accordingly.
*
* @param newBase
* The base value to set.
*/
public void setBase(final double newBase) {
   this.base = Math.min(Math.max(0, newBase), RTModel.MAX_SIDE);
   this.setHypotenuse();
   // Inform listeners the model is updated.
   this.pcs.firePropertyChange(RTModel.BASE_CHANGE, null, this.base);
}

// ---------------------------------------------------------------
/**
* Assigns a value to the model's height and updates all views accordingly.
*
* @param newHeight
* The height value to set.
*/
public void setHeight(final double newHeight) {
   this.height = Math.min(Math.max(0, newHeight), RTModel.MAX_SIDE);
   this.setHypotenuse();
   // Inform listeners the model is updated.
   this.pcs.firePropertyChange(RTModel.HEIGHT_CHANGE, null, this.height);
}

// ---------------------------------------------------------------
/**
* Sets the value of the hypotenuse. (Not public since the hypotenuse cannot
* be changed independently of the base or height.)
*/
private void setHypotenuse() {
   this.hypotenuse = Math
       .sqrt(Math.pow(this.base, 2.0) + Math.pow(this.height, 2.0));
}

// ---------------------------------------------------------------
}

2. Add an entirely new view named RTSameview that does the following It has a button that sets the base and height to the same value. That value should be the average of the current base and height. Has a label that shows the common value of the base and height if both the base and height are the same, and is blank otherwise. Has a label that shows the value of the hypotenuse at any time. Has an increment button that increments both the base and height by one simultaneously and a similar decrement button. These should work even if the base and height are not the same length.

Explanation / Answer


import java.util.Scanner;

abstract class GeoObject
{
private String color = "RED";
private boolean filled;
private java.util.Date dateCreated;

protected GeometricObject()
{

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

@Override
public String toString() {
return "created on " + dateCreated + " color: " + color +
" and filled: " + filled;
}

public abstract double getArea();

public abstract double getPerimeter();


}

class Triangle extends GeometricObject
{

public double s1;
public double s2;
public double s3;
public Triangle()
{
s1=1.0;
s2=1.0;
s3=1.0;
}

public Triangle(double side1,double side2,double side3) //peremetrised constructor
{
this.s1=side1;
this.s2=side2;
this.s3=side3;
}
@Override
public double getPerimeter() //function for getting peremeter for triangle
{
return(side1+side2+side3) ;

}

@Override

public double getArea()
{
double area,s;
s=side1+side2+side3;
area = Math.sqrt(s * (s- side1) * (s - side2) * (s - side3));
return(area);

}
@Override
public String toString()//to print the data
{
String s;
s="Triangle:side1 "+ side1 +" side2 " + side2 + " side3 "+side3;
return(s);
}

private String getSide1() {
  
return null;
}

private String getPerimeter(double d) {
  
return null;
}

private String getPerimeter(String string) {

return null;
}

private String getSide3() {
  
return null;
}

private String getSide2() {
  
return null;
}


public static void main(String args[])
{

Scanner input = new Scanner(System.in);

System.out.println("Enter 3 sides of the Triangle");
double side1 = input.nextDouble();
double side2 = input.nextDouble();
double side3 = input.nextDouble();

System.out.println("Enter the color of the Triangle");
String color = input.next();

System.out.println(" Is the Triangle filled? Reply with 'True' or 'False' ");

String filled = input.next();
}


{
Triangle triangle = new Triangle(side1, side2, side3);
triangle.setFilled(isFilled());
triangle.setColor(getColor());

System.out.println("The Triangle Sides are side 1: "
+ triangle.getSide1() + " Side 2: " + triangle.getSide2()
+ " Side 3: " + triangle.getSide3());

System.out.println("The Triangle's Area is " + triangle.getArea());
System.out.println("The Triangle's Perimeter is " + triangle.getPerimeter());
System.out.println("The Triangle's Color is " + triangle.getColor());
System.out.println("Is the Triangle filled? " + triangle.isFilled());
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote