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
The Office ____ is a temporary storage area. Warehouse Clipboard Storehouse Gallery
yanalaym [24]
The answer is The Office Clipboard.

In most Microsoft Windows, Office Clipboard is used as a temporary storage for some software applications such as Microsoft Office Applications. It allows you to store up to 24 items either texts or graphics. For example, when you copy a text from one location this text will be temporarily stored in the clipboard until you paste them to another location.
4 0
3 years ago
Which of the following best describes Roblox?
liberstina [14]

Answer:

B. An online platform for game creation!

Explanation:

Roblox is a massively multiplayer online and game creation system platform that allows users to design their own games and play a wide variety of different types of games created by other users.

--

Hope this helps! ✧.·:

6 0
3 years ago
Read 2 more answers
Create a class named CollegeCourse that includes the following data fields: dept (String) - holds the department (for example, E
frez [133]

Answer:

The answer to this question can be given as:

code:

class CollegeCourse  

{

String Dept;

int CourseNumber;

double Credits;

double fee;

}

Explanation:

We all know that class is a collection of data members and member functions. In the above code we use the following syntax for class declaration that can be given as:

Syntax of class declaration :

class class_name

{

data member & member function

}

In the above code firstly we declare a class that is CollegeCourse. In this class, we define a variable that name and datatype is already given in the question that is String Dept, int CourseNumber, double Credits, double fee. In the variables first variable data type is string. It is used for store string value like ('us','xxx','aaa').The second variable datatype is an integer. It is used for store integer value like (1,23,5,56). The third and fourth variable datatype is the same that is double. This data type is used to store the floating-point value.

5 0
3 years ago
Which file format produces a lock-down version of an access database? accdb accdb-be accde accdb-e
jek_recluse [69]

The file format that produces a lock-down version of an access database is called; ACCDE

<h3>How to Identify Access Database?</h3>

ACCDB files are the default Microsoft Access database format in Access 2007 and later versions while the ACCDE format is a read-only, compressed version.

Now, the file format that produces a lock down version of an access database is called ACCDE file which is a Microsoft Access Execute Only Database file used to protect an ACCDB file.

Read more about Access Database at; brainly.com/question/9745438

#SPJ1

8 0
1 year ago
Why procedures are used and what must be the lastexecutable instruction in a<br><br> procedure?
Art [367]

Answer:

Procedure are used to create and modifying the programs. Basically, it is grouping of instruction that can be used give direction of the flow of program. Control are given to the next term once the execution of the instruction get over. The steps of procedure are:

procedure are first executed the declaration instruction and then coding the procedure, then it will return to the directories and the last executable instruction is the termination of procedure.

4 0
2 years ago
Other questions:
  • David would like to send a letter to more than one hundred people. He would like the letter to have names and addresses inserted
    7·1 answer
  • The first digital keyboard was the DX-7, introduced by the Yamaha company in 1983.
    15·1 answer
  • You are in charge of designing a menu tree for navigating 1,250 books in a digital library. Present an argument of whether the m
    12·1 answer
  • Mateo could not find the undo command or shortcut. He should _____.
    15·2 answers
  • What is software that helps a computer operate efficiently and keeps track of data on a computer?
    14·1 answer
  • Write a program with a function that accepts a string as an argument and returns a copy of the string with the first character o
    11·1 answer
  • In 4-bit sign magnitude representation, what is the binary encoding of the number -5?
    15·1 answer
  • Your organization network diagram is shown in the figure below. Your company has the class C address range of 199.11.33.0. You n
    8·1 answer
  • What does a pencil icon in the row selector area indicate?
    7·1 answer
  • A man-in-the-middle attack or impersonation are likely to result in problems with
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!