Question: JAVA 1. /** * This is an example of Javadoc documentation. * The task is to: * 1. Describe what the doSomething method does in
JAVA
1.
/**
* This is an example of Javadoc documentation.
* The task is to:
* 1. Describe what the doSomething method does in at most 3 sentences as a Javadoc documentation.
* 2. Include a main method to call doSomething with some appropriate data and display the returned value.
*/
class DoSomething {
public static int doSomething(int[] d, int t) {
int j = 0;
while ((j < d.length) && (d[j] != t))
j++;
return j;
}
}
2.
/*
* This is a regular comment block.
* The task is to:
* 1. Modify the getDouble method to use exception handling (with an appropriate message displayed)
* and zero as the default value if a valid number is not entered. (2)
*/
import java.util.Scanner; // loads Scanner definition for our use
public class InputExample {
public static void main(String[] args) {
System.out.print("Enter your age in years: ");
double age = getDouble();
System.out.print("Enter your maximum heart rate: ");
double rate = getDouble();
double fb = (rate - age) * 0.65;
System.out.println("Your ideal fat-burning heart rate is " + fb);
}
public static double getDouble() {
Scanner input = new Scanner(System.in);
while (!input.hasNextDouble()) {
input.nextLine();
System.out.print("Invalid value; please enter an number: ");
}
double i = input.nextDouble();
return i;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
