Computers and Technology

I would like assistance regarding this Java Edhesive Assignment. Create a class RightTriangle which implements the API exactly as described in the following Javadoc.

Don't forget - you will need to use the Pythagorean theorem to find the hypotenuse (and therefore the perimeter) of a right triangle. You can find the area of a right triangle by multiplying the base and height together, then dividing this product by 2.

Use the runner_RightTriangle file to test the methods in your class; do not add a main method to your RightTriangle class.

Hint 1 - Javadoc only shows public methods, variables and constructors. You will need to add some private member variables to your RightTriangle class to store the necessary information. Think carefully about what information actually needs to be stored and how this will need to be updated when methods change the state of a RightTriangle object.

Hint 2 - As in the previous lesson's exercise it's helpful to add your method/constructor headers and any dummy returns needed before implementing each one properly. This will allow you to test your code using the runner class as you go along.

Runner Code:
import java. util. Scanner;

public class runner_RightTriangle{
public static void main(String[] args){
Scanner scan = new Scanner(System. in);
RightTriangle t = new RightTriangle();
String instruction = "";
while(!instruction. equals("q")){
System. out. println("Type the name of the method to test. Type c to construct a new triangle, q to quit.");
instruction = scan. nextLine();
if(instruction. equals("getArea")){
System. out. println(t. getArea());
}
else if(instruction. equals("getBase")){
System. out. println(t. getBase());
}
else if(instruction. equals("getHeight")){
System. out. println(t. getHeight());
}
else if(instruction. equals("getHypotenuse")){
System. out. println(t. getHypotenuse());
}
else if(instruction. equals("getPerimeter")){
System. out. println(t. getPerimeter());
}
else if(instruction. equals("toString")){
System. out. println(t);
}
else if(instruction. equals("setBase")){
System. out. println("Enter parameter value:");
double arg = scan. nextDouble();
t. setBase(arg);
scan. nextLine();
}
else if(instruction. equals("setHeight")){
System. out. println("Enter parameter value:");
double arg = scan. nextDouble();
t. setHeight(arg);
scan. nextLine();
}
else if(instruction. equals("equals")){
System. out. println("Enter base and height:");
double bs = scan. nextDouble();
double ht = scan. nextDouble();
RightTriangle tOther = new RightTriangle(bs, ht);
System. out. println(t. equals(tOther));
scan. nextLine();
}
else if(instruction. equals("c")){
System. out. println("Enter base and height:");
double bs = scan. nextDouble();
double ht = scan. nextDouble();
t = new RightTriangle(bs, ht);
scan. nextLine();
}
else if(!instruction. equals("q")){
System. out. println("Not recognized.");
}
}
}
}

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 21:00, calmicaela12s
The mode is generally used when delivering a presentation to an need now
Answers: 1
image
Computers and Technology, 22.06.2019 00:20, kcameronanderso
What’s resistance in an electrical circuit ?
Answers: 1
image
Computers and Technology, 22.06.2019 23:30, jhonpiper
For her science class, elaine is creating a presentation on weather in the united states. she wants to make the presentation beautiful and interesting by drawing simple cloud or wave shapes. which is the best way for elaine to draw these shapes?
Answers: 1
image
Computers and Technology, 23.06.2019 07:30, kimhoss2
What are ways to switch windows in excel? check all that apply. on the status bar, click the windows button, and then click the file name. on the task bar, click to display the excel jump list, and then click the file name. on the view tab, in the window group, click switch windows, and then click the file name. on the review tab, in the viewing group, click files, and then click the file name.
Answers: 1
Do you know the correct answer?
I would like assistance regarding this Java Edhesive Assignment. Create a class RightTriangle which...

Questions in other subjects:

Konu
English, 13.02.2020 03:24