Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following HypotenuseCalculator application / driver (i.e. it has the main() method and can be run) class that is designed to calculate a hypotenuse

Consider the following HypotenuseCalculator application / driver (i.e. it has the main() method and can be run) class that is designed to calculate a hypotenuse of a specific right triangle:

____________________________________________________________________________

class HypotenuseCalculator {

public static void main(String[] args){

int constant = 2;

float a = 2.0f;

float b = 3.5f;

double result;

a = a + constant + 1;

result = calculateHypotenuse(a, b);

System.out.println("Hypotenuse is: " + result);

}

public static float calculateHypotenuse(float givenA, float givenB){

double a;

double b;

float c;

a = givenA;

b = givenB;

c = Math.sqrt(Math.pow(a, 2.0) + Math.pow(b, 2.0));

return c;

}

}

____________________________________________________________________________

Your task is to edit this Java class file to:

A) provide Java comments to:

all individual statements with single-line comments (to explain their purpose). Your comments should be clear, to the point, and unambiguous. Try to you use the following verbs and nouns (in correct form: call or calling, etc.), among others, where appropriate:

declare, initialize, calculate, call, assign, return, variable, method, parameter, value.

all code blocks (class, method, etc.) with multi-line comments (to explain their purpose and provide additional information if necessary):

possible additional information (you can make up data) for class:

purpose,

author(s),

version,

last updated.

possible additional information (you can make up data) for methods:

purpose,

author(s),

version,

last updated,

parameters if any,

return values if any.

B) correct / modify the code to:

get rid of compilation issues by using casting (NOTE: you cannot change date types within the code!),

update your to comments to show where implicit and explicit casting is used.

use the shortcut operator ++ in the statement below

a = a + CONSTANT + 1;

without changing its behavior.

Corrected code after compilation should output this line:

Hypotenuse is: 6.103277683258057

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago