Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Advanced Java Programming with Object-Oriented Programming Design VERY IMPORTANT

ID: 3724482 • Letter: A

Question

Advanced Java Programming with Object-Oriented Programming Design

VERY IMPORTANT NOTE!!: This program for the question below MUST USE at least 2 CLASSES, getters/setters, etc and other object-oriented design (OOD) concepts because I'm in a more advanced Java class that requires me to utilize the concepts mentioned above. Also, I need detailed, but brief comments to most, if not all of the code to explain what is being used in the code and what is does so I have a better understanding of the code. I've seen answers to the question below already posted, however they don't utilize object-oriented design (OOD) concepts such as a minumum of two classes, getters/setters, etc which is required for this advanced Java programming class. So please......answer the question and meet the requirements for this question. Here's to hoping this works out and if it does, I'll give a thumbs up, I promise!!!

Define a method hypotenuse that calculates the hypotenuse of a right triangle when the lengths of the other two sides are given. The method should take two arguments of type double and return the hypotenuse as a double . Incorporate this method into an application that reads values for side1 and side2 and performs the calculation with the hypotenuse method. Use Math methods pow and sqrt to determine the length of the hypotenuse for each of the triangles in Fig. 6.15. [ Note: Class Math also provides method hypot to perform this calculation.]

Triangle Side 1 Side 2 1 3.0 4.0 2 5.0 12.0 3 8.0 15.0

Explanation / Answer

import java.io.*;
import java.util.Scanner; // Class containg method for Scanner operation
import java.lang.Math.*;

class getters{


double side1,side2,hyp;
  
void getdata() // function to get input from user
{
Scanner input = new Scanner(System.in); // using scanner to get user input
System.out.println("Enter the lengths of two sides of the right triangle to find the hypotenuse");
side1=input.nextDouble();
side2=input.nextDouble();
hyp = hypotenuse(side1,side2); // calling the method hypotenuse
input.close();
  
}
  

double hypotenuse(double a,double b)
{
double c;
c=( (Math.pow(a,2)) + (Math.pow(b,2)) ); //using math method pow
return (Math.sqrt(c)); //using math method sqrt
}
}

class setters extends getters /*inheriting class getters. So class setters can use the member variables and member functions of base class, getters */

{
  
void display()
{
System.out.println("Hypotenuse is:"+hyp);
}

}


public class MyClass {

public static void main(String args[]) {

setters s2=new setters(); //object of the derived class, setters

s2.getdata(); // calling base class method

s2.display();
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote