Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8845991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:52:03+00:00 2026-06-14T11:52:03+00:00

Possible Duplicate: Switch Statement with Strings in Java Ok, basically i want to know

  • 0

Possible Duplicate:
Switch Statement with Strings in Java

Ok, basically i want to know if this is possible and how to do it. I have a menu and i want this switch statement to recognize chars or a string that was entered by the user.

I have a little menu program that I am writing:

import java.util.*;
import java.io.*;
import java.io.File;
import java.io.FileReader;

public class Personnel
{
    // Instance Variables
    private static String empName;
    private static double wage;

    public static void main(String[] args) throws Exception
    {

        clearScreen();
        question();
        printMenu();
        exit();
    }

    public static void clearScreen()
    {
        System.out.println("\u001b[H\u001b[2J");
    }

    private static void exit()
    {
        System.exit(0);
    }

    private static void printMenu()
    {
        System.out.println("\t------------------------------------");
        System.out.println("\t|Commands: n - New employee        |");
        System.out.println("\t|          c - Compute paychecks   |");
        System.out.println("\t|          r - Raise wages         |");
        System.out.println("\t|          p - Print records       |");
        System.out.println("\t|          d - Download data       |");
        System.out.println("\t|          u - Upload data         |");
        System.out.println("\t|          q - Quit                |");
        System.out.println("\t------------------------------------");
        System.out.println("");
    }

    private static void question()
    {
        System.out.println("Enter command: ");
        Scanner q = new Scanner(System.in);
        // String input = q.nextLine();

        switch (q.nextLine())
        {
        case "n":
            System.out.println("Enter the name of new employee: ");
            Scanner stdin = new Scanner(System.in);
            System.out.println("Hourly (h) or salaried (s): ");
            Scanner stdin2 = new Scanner(System.in);
            if (stdin2.equals("h"))
            {
                System.out.println("Enter hourly wage: ");
                Scanner stdin3 = new Scanner(System.in);
            }
            else
            {
                System.out.println("Enter annual salary: ");
                Scanner stdin4 = new Scanner(System.in);
            }
            break;

        /*
         * case 9:
         *      System.out.println ("Please proceed."); 
         *      new InputMenu(); 
         *      break; 
         * default: 
         *      System.err.println ("Unrecognized option" ); break;
         */
        }
    }
}

What i am trying to do is make this menu work so that you can type in a command then i will write methods to run depending on what command was typed in. Is switch statement the best way to do this? After they enter in the info i need it to “break” back to the main menu. And anytime during the entire program, if they enter q then the program exits. I’m not sure the best way to go about doing this.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:52:04+00:00Added an answer on June 14, 2026 at 11:52 am

    Using String in switch-case statements is supported in jdk 7. Please refer this link for an example: http://docs.oracle.com/javase/7/docs/technotes/guides/language/strings-switch.html

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Switch Statement with Strings in Java I am trying to use switch
Possible Duplicate: Switch Statement With Strings in Java? Does the switch statement in Java
Possible Duplicate: Why was the switch statement designed to need a break? I have
Possible Duplicate: Why can't variables be declared in a switch statement? I have a
Possible Duplicate: Is it safe to assume strict comparison in a Javascript switch statement?
Possible Duplicate: Why can't variables be declared in a switch statement? How can a
Possible Duplicate: C# - Is there a better alternative than this to ‘switch on
Possible Duplicate: Switch Case on type of object (C#) I have a method signature
Possible Duplicate: Is there a native jQuery function to switch elements? I have list
Possible Duplicate: Switch statement fallthrough in C#? The following code is illegal in C#

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.