1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kotegsom [21]
3 years ago
13

Design a new Triangle class that extends the abstract

Computers and Technology
1 answer:
Vaselesa [24]3 years ago
4 0

Answer:

See explaination

Explanation:

The GeometricObject

public class GeometricObject {

private String color = " white ";

private boolean filled;

private java.util.Date dateCreated;

public GeometricObject() {

dateCreated = new java.util.Date();

}

public 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 + "\n color: " + color + " and filled ";

}

}

The Triangle program

public class Triangle extends GeometricObject {

private double side1 = 1.0;

private double side2 = 1.0;

private double side3 = 1.0;

public Triangle() {

}

public Triangle(double side1, double side2, double side3) {

this.side1 = side1;

this.side2 = side2;

this.side3 = side3;

}

public double setSide1() {

return side1;

}

public double setSide2() {

return side2;

}

public double setSide3() {

return side3;

}

public void setSide1(double side1) {

this.side1 = side1;

}

public void setSide2(double side2) {

this.side2 = side2;

}

public void setSide3(double side3) {

this.side3 = side2;

}

public double getArea() {

return (side1 + side2 + side3) / 2;

}

public double getPerimeter() {

return side1 + side2 + side3;

}

public String toString() {

return " Triangle: Side 1 = " + side1 + " Side 2 = " + side2

+ " Side 3 = " + side3;

}

}

The Testprogram.

import java.util.Scanner;

public class TestTriangle {

private double side1 = 1.0;

private double side2 = 1.0;

private double side3 = 1.0;

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.println("Enter three 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();

}

{

new Triangle(side1, side2, side3);

//How do i get the information into theTriangle?

System.out.println("The Triangle Sides are \n side 1: " + side1 + "\n Side 2: " + side2 + "\n Side 3: " + side3);

System.out.println("The Triangle's Area is " + (side1 + side2 + side3) / 2);

System.out.println("The Triangle's Perimeter is "

+ (side1 + side2 + side3));

System.out.println("The Triangle's Color is " + //what goes here?);

System.out.println("Is the Triangle filled? " + //what goes here?);

}

}

You need to create a new Triangle object like this, so that you have a reference

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

// ^^^^^^ This is the most important thing you're missing. You need a reference

// point for your object. That's the only way you can access it's

// properties.

You also need to set it's filled and color properties

triangle.setFilled(filled);

triangle.setColor(color);

Then, you can invoke its methods like this:

System.out.println("The Triangle Sides are \n side 1: "

+ triangle.getSide1() + "\n Side 2: " + triangle.getSide2()

+ "\n 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());

You're able to access the GeometricObject's isFilled(), setFilled(), getColor(), and setColor() because a Triangle is a GeometricObject (extends), so it inherits all its methods.

By the way, this is not how to calculate the area of a triangle:

public double getArea() {

return (side1 + side2 + side3) / 2; // This is so wrong

}

Check out this link for correct formula

Edit: With another problem with code

public double setSide1() {

return side1;

}

public double setSide2() {

return side2;

}

public double setSide3() {

return side3;

}

/**** Should Be ******/

public double getSide1() {

return side1;

}

public double getSide2() {

return side2;

}

public double getSide3() {

return side3;

}

Edit: Triangle Formula

public double getArea() {

int p = getPerimeter() / 2

return Math.sqrt(p * ((p - side1) * (p - side2) * (p - side3));

}

You might be interested in
Which of the following resources is an example of a web-based application?
kompoz [17]
The answer will be google docs since it depends on a web and its an application. hope it helps

3 0
3 years ago
What is the page table mainly for?
postnew [5]

Answer: See explanation

Explanation:

A page table is used for the tracking and the location of different pages of a task in memory. It helps in showing the mapping of locations between the physical addresses and the virtual addresses.

A page table stores also has the page table entries and this is where the frame numbers are stored as well as the operational status.

6 0
2 years ago
While a threat intelligence analyst was researching an indicator of compromise on a search engine, the web proxy generated an al
inna [77]

Answer: the corret answer C. The analyst has prefetch enabled on the browser in use.

Explanation:

The analyst has like an indicator which is prefetch enabled on the browser in use.

7 0
2 years ago
What do you mean by an algorithm?<br>​
Over [174]
A program that can be used in many scenarios
8 0
2 years ago
The process of ensuring that web pages coded with new or advanced techniques still are usable in browsers that do not offer supp
Leya [2.2K]

Answer:

(C) progressive enhancement

Explanation:

Progressive enhancement is a web design technique that first underlines the main functionality web page and then incorporates increasingly enhanced and advanced features and design levels.

This process enables the users to use and access the basic features of the web pages. These users can use any browser to access the main contents of the web page. Progressive Enhancement also offers an advanced version of the website for those with more advanced and sophisticated computer browsers or faster internet connection.

So the user can access basic features of a web sites as well as the complex features. This process first makes sure the basic intended purpose and main contents of the web site is accessible to all users before adding complex features which are supported by different browsers and devices.

Validation is a process which checks that code of the website is as per the world wide web standards and also checks that content of web pages and design of websites is being properly displayed and the site is accessible. So this is not the correct option.

Technique of altering a web site in a way that it can appear higher in the search engine results is called optimization so this is not a correct option.

7 0
3 years ago
Other questions:
  • Florida convicted __________ people of DUI in a one-year period from 2009 to 2010.
    15·1 answer
  • What is the on board storage C:
    15·1 answer
  • A(n) monitoring vulnerability scanner is one that listens in on the network and determines vulnerable versions of both server an
    7·1 answer
  • . Two blue armies are each poised on opposite hills preparing to attack a single red army in the valley. The red army can defeat
    5·1 answer
  • What is an elliptic curve cryptosystem (ECC)?
    8·1 answer
  • The template code provided is intended to check whether an integer entered by the user is outside of the range 20-29 (inclusive)
    9·1 answer
  • Complete the statement below using the correct term.<br>Website managers use<br>every day​
    11·2 answers
  • Write the two features of a mouse.​
    9·1 answer
  • Read each question below. Then, using the drop-down menus, decide if it represents the purpose, construction, or support aspect
    11·1 answer
  • 2. As you have learned, ironically, a large part of sound production involves visual perception. How easy or difficult did you f
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!