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

Qn1 a) Can a void method have a return statement? If your answer is yes, in what

ID: 3704228 • Letter: Q

Question

Qn1

a) Can a void method have a return statement? If your answer is yes, in what form?

Write appropriate method headings for the following methods:

b) Calculate and return the sum of two decimal numbers.

c) Compute and return the average speed of a car, given the distance traveled (as in int) and traveling time (in hours and minutes of type int).

d) Given the radius of a circle, output the area of the circle.

e) Given a student’s name and three test scores (of type int), output the student’s name and average test score.

f) Given a number, return true if the number is a prime; otherwise, return false.

g) Given the cost of an item and the sales tax (as a decimal number), return the total sale price.

h) Given a decimal number, output the square root if the number is nonnegative; otherwise, output an appropriate error message.

Explanation / Answer

Hi friend, Question is long. As per the chegg guideline, please post only 4 parts in a post.


a) Can a void method have a return statement? If your answer is yes, in what form?

Ans: Yes, A void method can have return statement.
   It is empty return statement.

   void function() {

       // statements
       return; // return statement
   }
  

Write appropriate method headings for the following methods:
b) Calculate and return the sum of two decimal numbers.

Ans:   double sum(double x1, double x2);

c) Compute and return the average speed of a car, given the distance traveled (as in int) and traveling time (in hours and minutes of type int).

Ans: double averageSpeed(int distance, int hour, int minute);

d) Given the radius of a circle, output the area of the circle.
  
   void area(double radius);

Please DONT forgot to rate my answer. We are working hard for you Guys!!