Menu

[solved]-Trianglejava Load Default Template Public Class Triangle Fixme Private Instance Variables Q39027963

Triangle.java Load default template... public class Triangle { // FIXME: private instance variables base and height go here pProgram errors displayed here Triangle.java:6: error: missing method body, or declare abstract public Triangle (double b, douObjective Fill in the class methods for a Triangle class to access (get) and mutate (set) the instance field variables base a

how to fix the error?

Triangle.java Load default template… public class Triangle { // FIXME: private instance variables base and height go here private double base; private double height; // constructor public Triangle (double b, double h); public static void main(String[] args) base = b; height = h; // FIXME: set the base public void setBase(double b) 17 i base = b; // FIXME: set the height public void setHeight(double h) height = h; 1/ FIXME: get the base public double getBase return base; // FIXME: get the height public double getHeighr() return height; // FIXME: get the area of triangle public double getArea return 0.5*height*base; 42 } // end class Triangle 43 Program errors displayed here Triangle.java:6: error: missing method body, or declare abstract public Triangle (double b, double h); Triangle.java:9: error: non-static variable base cannot be referenced from a static context base = b; Triangle.java:9: error: cannot find symbol base = b; symbol: variable b location: class Triangle Triangle.java:10: error: non-static variable height cannot be referenced from a static context height = h; Triangle.java:10: error: cannot find symbol height = h; symbol: variable h location: class Triangle 5 errors Objective Fill in the class methods for a Triangle class to access (get) and mutate (set) the instance field variables base and height. Background Reading ZyBooks Chapter 7 Task Create four methods for the Triangle class that allow the user to retrieve (get) or update (set) the private variables of the class. 1. Declare two variables of type double positioned in the code just below the class declaration (line 3). One variable is base, the other is height. 2. Write a public method setBase () with a parameter double b that sets base to b. 3. Write a public method setHeight() with a parameter double h that sets height to h. 4. Write a public method getBase() with no parameters that returns the value of base. 5. Write a public method getHeight() with no parameters that returns the value of height. 6. Write a public method getArea ( ) with no parameters that returns one-half base times height. Show transcribed image text Triangle.java Load default template… public class Triangle { // FIXME: private instance variables base and height go here private double base; private double height; // constructor public Triangle (double b, double h); public static void main(String[] args) base = b; height = h; // FIXME: set the base public void setBase(double b) 17 i base = b; // FIXME: set the height public void setHeight(double h) height = h; 1/ FIXME: get the base public double getBase return base; // FIXME: get the height public double getHeighr() return height; // FIXME: get the area of triangle public double getArea return 0.5*height*base; 42 } // end class Triangle 43
Program errors displayed here Triangle.java:6: error: missing method body, or declare abstract public Triangle (double b, double h); Triangle.java:9: error: non-static variable base cannot be referenced from a static context base = b; Triangle.java:9: error: cannot find symbol base = b; symbol: variable b location: class Triangle Triangle.java:10: error: non-static variable height cannot be referenced from a static context height = h; Triangle.java:10: error: cannot find symbol height = h; symbol: variable h location: class Triangle 5 errors
Objective Fill in the class methods for a Triangle class to access (get) and mutate (set) the instance field variables base and height. Background Reading ZyBooks Chapter 7 Task Create four methods for the Triangle class that allow the user to retrieve (get) or update (set) the private variables of the class. 1. Declare two variables of type double positioned in the code just below the class declaration (line 3). One variable is base, the other is height. 2. Write a public method setBase () with a parameter double b that sets base to b. 3. Write a public method setHeight() with a parameter double h that sets height to h. 4. Write a public method getBase() with no parameters that returns the value of base. 5. Write a public method getHeight() with no parameters that returns the value of height. 6. Write a public method getArea ( ) with no parameters that returns one-half base times height.

Expert Answer


Answer to Triangle.java Load default template… public class Triangle { // FIXME: private instance variables base and height go h… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *