0

I can't get the input value in the first static block.

This is my code:

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

    int i,people,timeai,tablenoai;
    double iprice,timebi,tablenobi;
    char decider1;
    String name;

    InputStreamReader read=new InputStreamReader(System.in);
    BufferedReader in=new BufferedReader(read);

    System.out.println("Welcome To Joel's Restaurant");
    System.out.println("How Many People Do You Have?");
    people=Integer.parseInt(in.readLine());
    System.out.println("And May I Know Your Good Name?");
    name=in.readLine();
}
    public static void sleep(The_Restaurant millis) throws InterruptedException{
    double timebi;
    int timeai;
    timebi=Math.random()*1000;
    timeai=(int)timebi;
    Thread.sleep(timeai);
}
public static void main(The_Restaurant args[])throws IOException{
    int tablenoai;
    double tablenobi;
    tablenobi=Math.random()*10;
    tablenoai=(int)tablenobi;
    System.out.println("Mr."+name+"Table For"+people+"Your Table No Is"+tablenoai);
}

Is there any way to do it?

Kalamarico
  • 5,466
  • 22
  • 53
  • 70
  • 1
    You shouldn't capitalize each and every word. Sentences like "if you notice any other errors" aren't good questions. Please also format your code to have proper indentation. – Marcin Pietraszek Nov 30 '17 at 12:41
  • "And May I Know Your Good Name?" Is this app for some kind of medieval parody restaurant? Maybe check out some modern English tutorials. No-one has spoken like about for about 300 years...if they ever did. – ADyson Nov 30 '17 at 13:31

1 Answers1

0

it is not clear what is being asked. Clearly question can be edited and improved. Since you are new to stackoverflow, probably try seeing existing question first and format it well to make it more crisp and readable. if you wondering how can you pass value read from one static method and use in another static method then probably u can use a global variable. if you are thinking to use static blocks (which would not fit in your use case it seems) then static blocks works gets executed in sequence. read this

Some problem with your code -

  • you don't need wait logic as several IO APIs waits for user input.
  • main method is always entry point from jvm, creating multiple mains doesn't mean all can be called from jvm.
  • lot's of unnecessary variables created.

Here is the small piece of code that you may take reference too -

private static int[] TABLES = new int[] {1, 2, 3, 4, 5, 6, 7};
public static void main(String[] args) {
    System.out.println("Welcome to Joel's Restaurant.");
    while (true) {
        System.out.println("please enter quit to exit. For booking write you name.");
        try (Scanner scanner = new Scanner(System.in)) {
            final String name = scanner.nextLine();
            if ("quit".equals(name.toLowerCase())) {
                break;
            }
            System.out.print("Number of people accompanying you: ");
            final int count = scanner.nextInt();
            final int randomTable = Double.valueOf(Math.random()).intValue() % 7;
            System.out.println("Mr. " + name + ", table no." + TABLES[randomTable] + " is assigned to you with count: " + count + ".");
            System.out.println();
        }
    }

}
Mohammad Adnan
  • 6,527
  • 6
  • 29
  • 47