Question: hi, i very much need help with my java program steps. The current step im on confuses me which is step 4 as i dont

hi, i very much need help with my java program steps. The current step im on confuses me which is step 4 as i dont understand what it wants me to do. so for step 4, we are altering the current program I wrote which is just finding the user's age through methods and calling it:

import java.util.Scanner;

public class Assignment { public static void main (String [] args) { Scanner scan = new Scanner(System.in); System.out.println("What is your age?"); int age = scan.nextInt(); scan.nextLine(); checkAge(age); } public static int checkAge(int age) { if (age < 18) System.out.println("You are a minor"); else if (age < 65) System.out.println("You are an adult"); else System.out.println("You are a senior"); return age; } }

However, step 4 as I mentioned confuses me as to what it wants me to do exactly. here is what is asks me to do:

4. Follow the steps to change the definition checkAge method such that instead of writing a message on the screen, the method returns a String as output.

a. change the method header by setting the output data type to String instead of void (in my case its 'int' in the checkAge method)

b. declare a string variable, called output, inside the checkAge method.

c. change the body of the if-else branches to assign the string to the variable output instead of writing the message on the screen. For example, the first body of the first branch will be as follows: output = "Minor";

d. add a return statement at the end of the checkAge method to return the output string.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!