Click here to Skip to main content
15,884,598 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am facing this error from past 10 days, and only on this project, Kindly check and try to resolve the same.

What I have tried:

Java
class HelpClassDemo
{
    void helpOn(int what)
    {
        switch(what)
        {
            case '1': System.out.println("The if:\n");
                      System.out.println("if(condition) statement;");
                      System.out.println("else statement;");
                      break;
            case '2': System.out.println("The switch:\n");
                      System.out.println("switch(expression)");
                      System.out.println("{");
                      System.out.println(" case constant");
                      System.out.println("   statement sequence");
                      System.out.println(" break;");
                      System.out.println("//...");
                      System.out.println("}");
                      break;
            case '3': System.out.println("The for:\n");
                      System.out.println("for(integer;condition;iteration)");
                      System.out.println("  statement;");
                      break;
            case '4': System.out.println("The while:\n");
                      System.out.println("while(condition)");
                      System.out.println("  statement;");
                      break;
            case '5': System.out.println("The do-while:\n");
                      System.out.println("do");
                      System.out.println("{");
                      System.out.println("  statement;");
                      System.out.println("}");
                      System.out.println("while(condition)");
                      break;
            case '6': System.out.println("The break:\n");
                      System.out.println("break; or break label;");
                      break;
            case '7': System.out.println("The continue:\n");
                      System.out.println("continue; or continue label;");
                      break;
        }
        System.out.println();
    }   
    void showMenu()
    {
        System.out.println("Help on:");
        System.out.println("  1. if");
        System.out.println("  2. switch");
        System.out.println("  3. for");
        System.out.println("  4. while");
        System.out.println("  5. do-while");
        System.out.println("  6. break");
        System.out.println("  7. continue\n");
        System.out.print("Choose one (q to quit):");
    }
    boolean isValid(int ch)
    {
        if((ch<'1')||(ch>'7')&& (ch!='q'))
            return false;
        else
            return true;
    }
    public static void main(String args[])throws java.io.IOException
    {
        char choice,ignore;
        HelpClassDemo hlpobj = new HelpClassDemo();
        
        for(;;)
        {
            do
            {
                hlpobj.showMenu();
                choice = (char) System.in.read();
                do
                {
                    ignore=(char) System.in.read();
                }
                while(ignore != '\n');
            }
            while(!hlpobj.isValid(choice));
            if(choice=='q')
              break;
            System.out.println("\n");
            hlpobj.helpOn(choice);
        }
    }
}
Posted
Updated 8-Jan-19 0:18am
v2
Comments
Richard MacCutchan 28-Jun-18 3:54am    
I just built you program and it starts up fine. Can you show exactly what commands you used to try it?

1 solution

One error I think, just try it out
You should make your class public. So instead of
class HelpClassDemo

it should be
public class HelpClassDemo

Rest is fine.
 
Share this answer
 
Comments
Richard MacCutchan 8-Jan-19 6:27am    
It does not need to be public. As I said in my comment the code runs fine. And as you can see by the date, and the (lack of) response from the OP, this is not an active question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900