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]
4 years ago
13

Design a new Triangle class that extends the abstract

Computers and Technology
1 answer:
Vaselesa [24]4 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
Is bit stuffing necessary in the control or address field in theHDLC protocol? why?
steposvetlana [31]

Answer:

Many network and communication protocols require bit stuffing for the following purposes: to avoid the interpretation of data as control information. For example, with six consecutive 1 bits, X.25 uses the bit stuffing,signal the beginning and end of a frame.

High-level Data link control (HDLC) is a bit-oriented protocol for point-to-point and multi-point communication.P/F bits are present in HDLC control field.

So,Yes bit stuffing is necessary in control field.

7 0
4 years ago
Which of the following binary numbers is equivalent to decimal 4?
melomori [17]

Answer:

b so easy

Explanation:

5 0
3 years ago
Read 2 more answers
What are some good apps to download to screenshot your screen?
LenaWriter [7]

Answer:

AZ Screen Recorder.

Firefox ScreenshotGo Beta.

Screenshot Touch.

Screen Master.

Most personal assistant apps

7 0
3 years ago
The four general functions of any application program are: data storage, data access logic, application logic and presentation l
miv72 [106K]

Answer:

True is the correct answer to the above question.

Explanation:

  • An application program is used for specific tasks. It is a program with some specified lines of instruction which instruct the computer to process any task.
  • When a user wants to create an application program or project then he can do it with the help of four parts. which are as follows:-
  1. There needs some presentation which can be called as front-end, which is the graphics interface for the user of that program. It facilities the user to drag and drop options for the user of the project.
  2. The second thing is data storage, which is used to store the data of the project.
  3. The third thing is data access logic, which is used to create a logic to extract or add the data to the database.
  4. The fourth thing is application logic which is used to send the data or present the data to the user in front-end design.
  • The above question-statement also wants to states the same which is described above. Hence true is the correct answer to the above question.

5 0
3 years ago
A particular BI analysis might require data from an ERP system, an e-commerce system, and a social networking application, but s
maxonik [38]

Answer:

Data not integrated.

Explanation:

The Integration of data is the method of integrating data from various outlets into one consistent, coherent view.Integration starts  with the process of intake, which involves steps such as washing, ETL simulation and integration.

The data which is not represent  primary key/foreign key  relationship such a data is known data not integrated In this given question the BI is analysed the data from the ERP system and other from e-commerce system as well as from networking application the data is not described in primary key/foreign key relationships this kind of data is known as data not integrated .

8 0
4 years ago
Other questions:
  • What type of operating system runs a dedicated electronic device such as a smart thermostat?
    5·1 answer
  • Why is it important to use standard english when applying for a job
    13·2 answers
  • write code to declare variables for s0 with a value of 12.0, v0 with a value of 3.5, a with a value of 9.8, and t with a value o
    13·1 answer
  • The largest distribution of software cost will be when in the programs life cycle?
    12·1 answer
  • Which features can Danica use to fix the issue
    5·1 answer
  • First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects).
    6·1 answer
  • How are the monsters related to humans
    5·1 answer
  • What operation can be performed using the total feature ​
    13·1 answer
  • The _____ Tag surrounds all content that will be visible on your web page for all to users to see on that website.
    13·1 answer
  • A brief contains an initial definition statement of the design aim and defines any constraints?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!