Java Programming Question:

basically want to keep the user in a loop that displays the menu and requests a user choice again and again until the user enters choice option 0 and exits the program.

When Option 1 is chosen, I want to ask the user, "How many numbers to add?" After they put in that number, I want to ask them, "Please enter the numbers one by one." like this
56
789
4
8999
231

Then, the program will display the result by saying, "The sum is:...."
Finally the menu should be displayed again to choose from.

If Option 2 is selected:
- the user will NOT be asked how many numbers are to be multiplied. Instead, the program will accept numbers until the user enters the numer "1" which will signal the end of the number series. So the dialogue should look like this:

Please enter the numbers:

56
43
2
99
767
1
"The product is: ___"
then the menu will be displayed again and the use prompted for a choice.

This is what I have so far...

import java.io.*;

public class p2
{

private static BufferedReader stdin =
new BufferedReader( new InputStreamReader( System.in ) );

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

System.out.println( "0-Exit" );
System.out.println( "1-Compute the sum of some numbers" );
System.out.println( "2-Compute the product of some numbers" );

String inputString = stdin.readLine();
int input = Integer.parseInt(inputString);

switch(input)
{
case 0:
break;
case 1:

break;
case 2:

break;
default:
System.out.println( "Invalid Selection" );
break;
}

System.out.println( "Bye Bye" );
}
}

To achieve the desired functionality, you can use a while loop that keeps prompting the user for a choice until they enter 0. Inside the loop, based on the user's choice, you can handle the options 1 and 2 separately. Here's an updated version of your code to implement this logic:

```java
import java.io.*;

public class p2 {
private static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));

public static void main(String[] args) throws IOException {
int choice = -1;
while (choice != 0) {
System.out.println("0-Exit");
System.out.println("1-Compute the sum of some numbers");
System.out.println("2-Compute the product of some numbers");
String inputString = stdin.readLine();
choice = Integer.parseInt(inputString);

switch (choice) {
case 0:
System.out.println("Bye Bye");
break;
case 1:
computeSum();
break;
case 2:
computeProduct();
break;
default:
System.out.println("Invalid Selection");
break;
}
}
}

private static void computeSum() throws IOException {
System.out.println("How many numbers to add?");
int count = Integer.parseInt(stdin.readLine());
int sum = 0;

System.out.println("Please enter the numbers one by one:");
for (int i = 0; i < count; i++) {
sum += Integer.parseInt(stdin.readLine());
}

System.out.println("The sum is: " + sum);
}

private static void computeProduct() throws IOException {
System.out.println("Please enter the numbers:");
int product = 1;
int num;
while ((num = Integer.parseInt(stdin.readLine())) != 1) {
product *= num;
}

System.out.println("The product is: " + product);
}
}
```

Now when the user selects option 1, they will be asked to enter the number of numbers they want to add and then prompted to enter each number. The program will then calculate and display the sum.

Similarly, when the user selects option 2, they can enter multiple numbers until they enter 1, and the program will calculate and display the product. After each calculation, the menu will be displayed again to choose from.

To implement the functionality you described, you can modify and complete the code as follows:

```java
import java.io.*;

public class p2 {

private static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));

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

int input = -1;

while (input != 0) {
System.out.println("0-Exit");
System.out.println("1-Compute the sum of some numbers");
System.out.println("2-Compute the product of some numbers");

String inputString = stdin.readLine();
input = Integer.parseInt(inputString);

switch (input) {
case 0:
break;
case 1:
computeSum();
break;
case 2:
computeProduct();
break;
default:
System.out.println("Invalid Selection");
break;
}
}

System.out.println("Bye Bye");
}


private static void computeSum() throws IOException {
System.out.println("How many numbers to add?");
String countString = stdin.readLine();
int count = Integer.parseInt(countString);
int sum = 0;

System.out.println("Please enter the numbers one by one:");

for (int i = 0; i < count; i++) {
String numberString = stdin.readLine();
int number = Integer.parseInt(numberString);
sum += number;
}

System.out.println("The sum is: " + sum);
}

private static void computeProduct() throws IOException {
System.out.println("Please enter the numbers:");
int product = 1;
boolean isOneFound = false;

while (!isOneFound) {
String numberString = stdin.readLine();
int number = Integer.parseInt(numberString);

if (number == 1) {
isOneFound = true;
} else {
product *= number;
}
}
System.out.println("The product is: " + product);
}
}
```

Explanation:

1. The `while` loop is used to keep displaying the menu and accepting user choices until the user enters choice option 0.
2. The `computeSum()` method calculates the sum of input numbers. It first asks the user for the count of numbers, then it prompts the user to input the numbers one by one and adds them to the `sum` variable.
3. The `computeProduct()` method calculates the product of input numbers. It repeatedly asks the user to input numbers until the user enters the number 1, which signals the end of the number series. It multiplies the input numbers together to calculate the product.
4. The `switch` statement is used to execute the corresponding functionality based on the user's input.
5. The code gracefully handles invalid menu selections by displaying an error message.
6. The program exits and says "Bye Bye" when the user enters choice option 0.