Help with WHILE loops required please

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Donna

    #1

    Help with WHILE loops required please

    I am attempting a distance learning course in Java but am having problems
    with a task. I have completed the simple little program as listed below.

    public class Results
    {
    private static String version =
    "Module Results (version Exercise 1-3)";

    static Group myGroup = new Group();

    public static void main(String args[])
    {
    char selection;
    String myNumber = "0490011";
    Student thisStudent;

    selection = IO.readChar
    (version + "\n\nPlease input \n1. To display all student
    results\nor\n2. To display results for Student 0490011");
    switch (selection)
    {
    case '1':
    myGroup.display All();
    break;
    case '2':
    thisStudent = myGroup.findThi sStudent(myNumb er);
    thisStudent.dis play();
    break;
    default:
    IO.display (version,
    "You didn't select 1 or 2");
    }
    System.exit(0);
    }
    }


    My next task is too insert a while statement so that the user can repeat the
    menu options as often as required. The text book that I have got
    explains a while statement as follows.

    BEGIN
    continuing = true (I assume something like char = 1 or
    2)
    WHILE continuing (While char = 1 or 2 diplay menu)
    display menu
    get selection
    SWITCH selection

    and so on.

    Can this be done with a char or do I need to use the input selection as an
    integer.


    Many thanks, Any help welcome.

    Donna


  • Ryan Stewart

    #2
    Re: Help with WHILE loops required please

    "Donna" <Donna.hunt@blu eyonder.co.uk> wrote in message
    news:PgrNd.3845 8$K7.28677@fe2. news.blueyonder .co.uk...
    [...][color=blue]
    > My next task is too insert a while statement so that the user can repeat the
    > menu options as often as required. The text book that I have got
    > explains a while statement as follows.
    >
    > BEGIN
    > continuing = true (I assume something like char = 1 or
    > 2)
    > WHILE continuing (While char = 1 or 2 diplay menu)
    > display menu
    > get selection
    > SWITCH selection
    >
    > and so on.
    >
    > Can this be done with a char or do I need to use the input selection as an
    > integer.
    >[/color]
    Can what be done with a char? You know that chars work in a switch statement. In
    fact a char is an integral type. Anything you can do with an int, you can do
    with a char.


    Comment

    • Ryan Stewart

      #3
      Re: Help with WHILE loops required please

      "Donna" <Donna.hunt@blu eyonder.co.uk> wrote in message
      news:PgrNd.3845 8$K7.28677@fe2. news.blueyonder .co.uk...[color=blue]
      >I am attempting a distance learning course in Java but am having problems
      > with a task. I have completed the simple little program as listed below.[/color]
      [...]
      Also, please do not multipost. And while you're at it, confine your posts to
      comp.lang.java. help.


      Comment

      Working...