Question: (TEST CORRECTION JAVA PROGRAMMING: WHAT AND WHY IS THE CORRECT ANSWER FOR F-I) For clarification: These were written response, so I had to create them.
(TEST CORRECTION JAVA PROGRAMMING: WHAT AND WHY IS THE CORRECT ANSWER FOR F-I)
For clarification: These were written response, so I had to create them. These questions below didn't have a multiple-choice options.
f. Write a method (including header and body) called boxSurface to calculate the surface area of a box with base of x, y and height of z, where x, y and z can be any real numbers. Use at most 5 lines, assuming one statement or header per line.
Selected Answer:
public static void boxSurface int ( int x, int y, int z)
int x; // length
int y; // width
int z; // height
int area = x * y * z;
}
---------------------------------------------------------------------------------------------------------
g. Write a method (including header and body) that returns a suffix of an integer with a specified number of digits. For example, getSuffix(12345, 2) returns 45 and getSuffix(1234567, 3) returns 567. Use at most 6 lines, one statement/header per line.
Selected Answer:
public static void int (x)
int getSuffix;
if (getSuffix == 12345, 2);
getSuffix =%10
if (getSuffix == 1234567. 3);
getSuffix =% 100
return;
---------------------------------------------------------------------------------------------------------------------------------------
h. Write a method that displays numbers from 1 to a. The numbers are separated by a comma (,) and there are 12 numbers per line. The method header is given as:
public static void displayNumber(int a){
}
Selected Answer:
public static void displayNumber(int a){
for ( int a = 1; a < 13; a ++)
System.out.println( a + " ,");
}
--------------------------------------------------------------------------------------------------------------------------------
i. Write a complete program to display the hurricane category based on the table. Prompt user to enter mph (miles per hour) speed value between 39 and 170 for each of 10 hurricanes. Scanner's nextInt() or nextDouble() can be used only once. The program invokes a method called findCategory to find the hurricane categories based on speed input from user in main method block. (Hint: You need to create a user-defined method called "findCategory" to categorize the hurricanes. The method "findCategory" accepts mph value and returns hurricane category.) Take the following speed ranges to categorize each hurricane.
| Speed | Hurricane Category |
| 39-73 | Tropical Storm |
| 74-95 | Category 1 |
| 96-110 | Category 2 |
| 111-130 | Category 3 |
| 131-155 | Category 4 |
| 156 and up | Category 5 |
-------------------------------------------------------------------------------------------------------------------
import java.util.Scanner;
public class HurricaneTest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// your code goes here
....
} // end of main( )
// define method below
.....
....
} // end of class
Selected Answer:
import java.util.Scanner;
public class HurricaneTest {
public static void main(String[] args) {
public static void int findCategory ( int i)
Scanner input = new Scanner(System.in);
int i;
while (i > 0)
{
if ( i == 39 && i <= 73)
System.out.println("Tropical Storm");
I++
if ( i == 74 && i <=95)
System.out.println("Category 1");
i++
if ( i== 96 && i <= 110)
System.out.println("Category 2");
if ( i == 111 && i <= 130)
System.out.println("Category 3");
if ( i == 131 && i <= 155)
System.out.println("Category 4");
if ( i == 156 && i >= 156)
System.out.println("Category 5");
}
return;
} // end of main( )
// define method below
public static void int findCategory ( int i)
} // end of class
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
