Java program The following is the data type class Triangle that is defined to ho
ID: 3745001 • Letter: J
Question
Java program
The following is the data type class Triangle that is defined to hold the information of a triangle and some actions access those information. However, the class Triangle is not complete yet.
public class Triangle {
//A. ........
priviate double base; private double height;
//B. no-argument constructor
//C. parameter constructor
//D.method calculate area of triangle
//E. method toString to create the string output of a triangle }
In a word document, provide the answers of the following questions:
1.What is the name to call lines listed in a. Select good answers:
2.Provide the code of no-argument constructor, parameter constructor
3.Provide the code of mutator methods and accessor methods of variables, base and heigh
4.Provide the code to calculate and return the area of a triangle
Provide the code to create the output of a triangle as below if its base = 6.5 and height = 5.25
TRIANGLE Base = 6.5 Height = 5.25 Area = 34.125
Java program
The following is the data type class Triangle that is defined to hold the information of a triangle and some actions access those information. However, the class Triangle is not complete yet.
public class Triangle {
//A. ........
priviate double base; private double height;
//B. no-argument constructor
//C. parameter constructor
//D.method calculate area of triangle
//E. method toString to create the string output of a triangle }
In a word document, provide the answers of the following questions:
1.What is the name to call lines listed in a. Select good answers:
2.Provide the code of no-argument constructor, parameter constructor
3.Provide the code of mutator methods and accessor methods of variables, base and heigh
Explanation / Answer
public class Triangle { //A. ........ private double base; private double height; //B. no-argument constructor public Triangle() { height = 0; base = 0; } //C. parameter constructor public Triangle(double base, double height) { this.base = base; this.height = height; } //D.method calculate area of triangle public double area() { return base * height; } //E. method toString to create the string output of a triangle @Override public String toString() { return "TRIANGLE Base = " + base + " Height = " + height + " Area = " + area(); } public static void main(String[] args) { Triangle triangle = new Triangle(6.5, 5.25); System.out.println(triangle); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.