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 is a technique for storing or copying log events to acentralized logging server?a. Syslogb. Write­once re
Neporo4naja [7]

Answer:A) Syslog

Explanation: Syslog is the log for the messaging in the computing field.It acts as a separator for the different task that is related to messaging. The task usually are storing of message, production of the message through software,analyzing message, reporting it etc.

Other options given in the question such as WORM storage is for the storage technology,UTM is for the management for the threat situation and firewall logging is related with log/tables for firewall.

Thus, the correct option is option (A).

5 0
3 years ago
Using the College Registration example from Section 6.7.3 as a starting point, do the following:
andreev551 [17]

Answer:

Check the explanation

Explanation:

INCLUDE Irvine32.inc

TRUE = 1

FALSE = 0

.data

gradeAverage WORD ?

credits WORD ?

oKToRegister BYTE ?

str1 BYTE "Error: Credits must be between 1 and 30" , 0dh,0ah,0

main PROC

call CheckRegs

exit

main ENDP

CheckRegs PROC

push edx

mov OkToRegister,FALSE

; Check credits for valid range 1-30

cmp credits,1 ; credits < 1?

jb E1

cmp credits,30 ; credits > 30?

ja E1

jmp L1 ; credits are ok

; Display error message: credits out of range

E1:

mov edx,OFFSET str1

call WriteString

jmp L4

L1:

cmp gradeAverage,350 ; if gradeAverage > 350

jna L2

mov OkToRegister,TRUE ; OkToRegister = TRUE

jmp L4

L2:

cmp gradeAverage,250 ; elseif gradeAverage > 250

jna L3

cmp credits,16 ; && credits <= 16

jnbe L3

mov OkToRegister,TRUE ; OKToRegister = TRUE

jmp L4

L3:

cmp credits,12 ; elseif credits <= 12

ja L4

mov OkToRegister,TRUE ; OKToRegister = TRUE

L4:

pop edx ; endif

ret

CheckRegs ENDP

END main

3 0
3 years ago
1. Which of the following is NOT an example of systems software? (Points : 1)
vladimir2022 [97]
The answer is "operating systems" brcause you need that that to use the rest
' 
4 0
2 years ago
Read 2 more answers
To use patterns and observations to say what happens next
posledela
You would need to show a pic
4 0
3 years ago
Given an initialized String variable message, and given a PrintWriter reference variable named output that references a PrintWri
vredina [299]

Answer:

The output streams to this question is "output.print(message)".

Explanation:

The description of the following can be given as:

  • In the given question it is define a string datatype variable that is "message".
  • Then we create a reference variable of PrintWriter class that is "output" and call string type variable that is message by the use of the print function we print message.  
7 0
2 years ago
Other questions:
  • What was one of the main purposes of the first computer systems?
    11·1 answer
  • What is the unique impact him professionals have on coded data?
    11·1 answer
  • Which was the first wiki based website
    15·2 answers
  • Choose the sentences that describe techniques of formatting text.
    12·1 answer
  • If a 120 V appliance requires 15 A to operate, what is the resistance of the appliance?
    10·1 answer
  • Wireframing and storyboarding are helpful in which step of web development?
    13·2 answers
  • Analyze the problem statement. Select the correct answer. Vision: We want to decrease errors in our billings to clients. Issue:
    5·1 answer
  • 1. True or false: The more pixels per inch in an image, the higher the resolution is. (1 point)
    8·1 answer
  • 1. Why is photographing lightning a difficult process?
    11·2 answers
  • You're making great progress on your assignment. You've defined the purpose of your message, identified both the primary and sec
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!