Computers and Technology

Given class Triangle (in file Triangle. java), complete main() to read and set the base and height of triangle1 and of triangle2, determine which triangle's area is larger, and output that triangle's info, making use of Triangle's relevant methods.

Ex: If the input is:

3.0 4.0
4.0 5.0
where 3.0 is triangle1's base, 4.0 is triangle1's height, 4.0 is triangle2's base, and 5.0 is triangle2's height, the output is:

Triangle with larger area:
Base: 4.00
Height: 5.00
Area: 10.00
Here is class Triangle:

public class Triangle {
private double base;
private double height;

public void setBase(double userBase){
base = userBase;
}
public void setHeight(double userHeight) {
height = userHeight;
}

public double getArea() {
double area = 0.5 * base * height;
return area;
}

public void printInfo() {
System. out. printf("Base: %.2f\n", base);
System. out. printf("Height: %.2f\n", height);
System. out. printf("Area: %.2f\n", getArea());
}
}

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 19:30, bstine6678
When creating a presentation in libre office impress, where does the editing of slides take place? a. the slides panel b. the center panel c. the tasks panel, under the masters pages tab d. the tasks panel, under the layouts tab
Answers: 1
image
Computers and Technology, 23.06.2019 15:00, abelxoconda
1. which of the following statements are true about routers and routing on the internet. choose two answers. a. protocols ensure that a single path between two computers is established before sending packets over it. b. routers are hierarchical and the "root" router is responsible for communicating to sub-routers the best paths for them to route internet traffic. c. a packet traveling between two computers on the internet may be rerouted many times along the way or even lost or "dropped". d. routers act independently and route packets as they see fit.
Answers: 2
image
Computers and Technology, 23.06.2019 20:00, boo3972
Match the file formats with the types of multimedia they can store
Answers: 2
image
Computers and Technology, 24.06.2019 03:00, greenhappypiggies
Using a conditional expression, write a statement that increments numusers if updatedirection is 1, otherwise decrements numusers. ex: if numusers is 8 and updatedirection is 1, numusers becomes 9; if updatedirection is 0, numusers becomes 7.
Answers: 1
Do you know the correct answer?
Given class Triangle (in file Triangle. java), complete main() to read and set the base and height o...

Questions in other subjects: