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
An access control system that grants users only those rights necessary for them to perform their work is operating on which secu
solmaris [256]

Answer:

B. Least privilege                

Explanation:

  • The principle of least privilege an important principle in computer security.
  • It limits the access rights for users and only grant them with the rights that are sufficient for them to perform their required task.
  • For example a user is granted privilege to execute a file or manipulate data or use only the resources that are required for them to perform a particular task.
  • This principle can be used only to limit and control access rights to system resources and applications.
  • The least privilege is beneficial as it reduces the risk of unauthorized access.
  • For example a user whose task is data entry and has nothing to do with controlling access or granting access rights to users, will only be allowed to enter data to the DB by the principle of least privilege.
7 0
3 years ago
Consider a computer system, where each processor can independently perform a separate task. given that the response time on a co
vekshin1
First four tasks = 8 seconds
Next four tasks = 8 seconds
Last two tasks = 8 seconds

The total number of seconds to perform all tasks is 24 seconds.

The throughput, which would be the number of tasks per second, is calculated by taking the number of tasks and dividing by the number of seconds:

10 tasks / 24 seconds = 5/12 or 0.4167 tasks per second
8 0
3 years ago
What's your opinion on Pokemon​ and pixeldip
faust18 [17]

Answer:

Its a good game but an amazing show. 10/10

Explanation:

7 0
2 years ago
How to work a computer cause i don't know how to
VladimirAG [237]

Answer:

power on, connect to internet, download games

6 0
3 years ago
Words have both denotative and connotative meaning. The connotative meaning is Question 2 options:
Natalka [10]

Answer:

Option b is correct answer.

Explanation:

The connotative meaning is a word's implied or secondary meaning, in addition to its literal meaning.

Connotative meaning gives an idea or a feel that invokes for a person other than literal context of the word.

Connotation tells us weather the word used is in positive context or the negative one. For example, the words childish and youthful have same denotations but connotative meaning of childish is negative while youthful lies in positive context.

i hope it will help you.

4 0
3 years ago
Other questions:
  • Liz will use a CD-R compact disk to write to more than once. Carlo will use a CD-RW compact disk to write to more than once. Who
    8·2 answers
  • If you were given a 3D microscope to use for photography, which object(s) would you most want to photograph?
    10·2 answers
  • A _________ consists of a set of computers that interconnect by means of a relatively unsecure network and makes use of encrypti
    5·1 answer
  • What is the benefit of a cloud computing infrastructure? ○ Companies have full control over the data that is hosted. ○ Companies
    11·1 answer
  • What information should be included in the closing paragraph of a thank-you letter? a. Mention skills that were omitted during t
    6·2 answers
  • Which role involves designing and creating advertisements for marketing purposes?
    14·2 answers
  • Which of the following is an easy steps to take to avoid ESSD well working on your computer?
    5·1 answer
  • February 1995, Kevin Mitnick was arrested. While on parole was he allowed to have a phone or computer?
    6·2 answers
  • We have studied machine cycle in class. Suppose that each of the four modules of machine cycle is taking 2 seconds. If there are
    5·1 answer
  • Which of these is installed only on Apple smartphones and tablets?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!