Question:

Method.. (In Java Language)

by Guest61740  |  earlier

0 LIKES UnLike

Write a method readEduLevel that will only accept the character 'P', 'O', 'A' and 'T' which stands for "Primary", "O-level", "A-level" and "Tertiary". Lowercase is also acceptable but uppercase will be returned.

Can someone help me on this..? So, I can do other similar questions... Thanks.

 Tags:

   Report

1 ANSWERS


  1. import java.util.Scanner;

    class TEST {





    private char readEduLevel(){



    // define the input type (in our case, keyboard input)

    Scanner scInput = new Scanner(System.in);



    System.out.print("Enter Education Level: ");



    // get the user input from the keyboard

    String strKey = scInput.nextLine();



    // check if the entered character is a valid edu level

    if(strKey.equalsIgnoreCase("P") ||

    strKey.equalsIgnoreCase("O") ||

    strKey.equalsIgnoreCase("A") ||

    strKey.equalsIgnoreCase("T")){



    // return the uppercase letter of the valid input

    return strKey.toUpperCase().charAt(0);

    } else {

    // return * to know that the inputted value is invalid

    return '*';

    }

    }

    public static void main(String[] strArgs){

    TEST t = new TEST();



    // call the method to let the user input a value

    char chValue = t.readEduLevel();



    System.out.println("The return value is: " + chValue);

    }

    }

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.