Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Code says I need while statement?

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Code says I need while statement?

    Hi i really need help with my java program it keeps saying i need to have a while statement at the end and i have no idea why if anyone could help it would be greatly appreciated


    /**
    * Write a description of class Cinema here.
    *
    * @author (your name)
    * @version (a version number or a date)
    */
    public class Cinema
    {
    public static void main (String args[]) throws Exception
    {
    BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
    String title ="*******************Welcome To Cinema Enterpriso************";
    String list[]=new String[20];//This is where I store my movie names.
    list[0]="Iron Man 3";
    list[1]="Spawn";
    list[2]="Man of Steel";
    list[3]="Titanic";
    list[4]="Avatar";
    list[5]="Thor 2";
    list[6]="Mamma Mia!";
    list[7]="The Hobbit Part 2";
    list[8]="Batman";
    list[9]="Superman";

    String city [] = new String[10];//This section is used for storing the locations of the cinemas.
    city[0]="Leeds";
    city[1]="Manchester";
    city[2]="London";
    city[3]="Bradford";
    city[4]="Birmingham";

    String cityN, movie, size;
    String ans="Q";
    String ans1="Q";
    int flag=0, flag1=0, flag2=0, flag3=0, flag4=0, quantity, date, drink, tot_drink, snack, tot_snack, fd;
    int tot_fd=1, tot_d,d,ch;



    do
    {
    System.out.println();
    System.out.println(title);
    System.out.println("****************************** ************************");
    System.out.println();
    System.out.println("<<<<< Select The Location Of Your Cinema >>>>>");

    do
    {
    if(flag>0)
    System.out.println("**Invalid input please try again**");
    System.out.println("****************************** *****************");
    System.out.println("** Leeds, Manchester, London, Bradford, Birmingham **");
    System.out.println();
    System.out.print("Enter the correct name for the city of your choice :");
    cityN=br.readline();
    for(int i=0;i<5;i++)
    {
    if (city[i].equalsIgnoreCase(cityN))
    {
    flag=0;
    break;
    }
    else
    flag++;
    }
    }while (flag1!=0);
    System.out.println(title);
    System.out.println("****************************** **************************");
    System.out.println("\f");
    System.out.println(title);
    System.out.println("****************************** ***************************");
    System.out.println("<<<Select which date you wish to see the movie >>>");
    do
    {
    System.out.println("****************************** *********************");
    System.out.println("** 1. Monday, 1 April [2013] **");
    System.out.println("** 2. Tuesday, 2 April [2013] **");
    System.out.println("** 3. Wednesday, 3 April [2013] **");
    System.out.println("** 4. Thursday, 4 April [2013] **");
    System.out.println("** 5. Friday, 5 April [2013] **");
    System.out.println("** 6. Saturday, 6 April [2013] **");
    System.out.println("** 7. Sunday, 7 April [2013] **");
    System.out.println();
    System.out.print("Enter the correct number for the date you wish to see the movie :");
    date=Integer.parseInt(br.readline());
    if((date>=1)&&(date<=7))
    flag2=0;
    else
    {
    System.out.println("*** Invalid input please try again ***");
    flag2++;
    }while(flag2!=0);
    System.out.println("\f");
    System.out.println(title);
    System.out.println("****************************** ********************");
    System.out.println("<<< Please enter the number of tickets >>>");
    System.out.println("****************************** ********************");
    System.out.print("Enter the number of tickets :");
    quantity=Integer.parseInt(br.readLine());
    System.out.println("****************************** *********************");
    System.out.println("\f");
    System.out.println(title);
    System.out.println("****************************** *********************");
    {
    System.out.println("<<< Movie Selection >>>");
    do
    {
    if (flag3>0)
    System.out.println("*** Invalid input please try again ***");
    System.out.println("****************************** **************** Now Showing ************************************************** ******");
    System.out.println("Movie name Rating Price Seats A/V");
    System.out.println();
    System.out.println("Iron Man 3 12 £5.00 200");
    System.out.println("Spawn 15 £5.00 50");
    System.out.println("Man of Steel 12 £5.00 200");
    System.out.println("Titanic 12 £5.00 50");
    System.out.println("Avatar 12 £5.00 50");
    System.out.println("Thor 2 12 £5.00 200");
    System.out.println("Mamma Mia! PG £5.00 50");
    System.out.println("The Hobbit Part 2 12 £5.00 200");
    System.out.println("Batman 15 £5.00 50");
    System.out.println("Superman U £5.00 50");
    System.out.println();
    System.out.print("Enter the name of your selected movie :");
    movie=br.readline();
    for (int i=0;i<10;i++)
    {
    if(list[i].equalsIgnoreCase(movie))
    {
    flag3=0;
    break;
    }
    else
    flag3++;
    }
    }while (flag3!=0);
    System.out.println();
    System.out.println("<<< Please collect your bill >>>");
    System.out.println("****************************** ***********************");
    System.out.println("Movie Selected :"+movie);
    System.out.println("The total cost is £"+(quantity*5));
    System.out.print("Your seats numers are ");
    for (int i=1;i<=quantity;i++)
    {
    System.out.print(135+i+" ");
    }
    System.out.println();
    }
    System.out.println("****************************** ***************************");
    System.out.println("************** Thank You For Buying Tickets *************");
    System.out.println();
    System.out.println("****************************** ***************************");
    System.out.println("To quit buying tickets enter 'Q' ");
    ans=br.readline();

    System.out.println("\f");
    System.out.println(title);
    System.out.println("****************************** ***************************");
    do
    {
    System.out.println("*************Cinema Enterpriso Snack Bar*************");
    System.out.println();
    System.out.println("***************** Section : Beverages ***************");
    System.out.println("***************** All Beverage £2.00 ****************");
    System.out.println("1. Coca Cola 2. Tango");
    System.out.println("3. Fanta 4. Dr Pepper");
    System.out.println("5. Sprite 6. Coke Zero");
    System.out.println();
    String flagC1=new String();
    System.out.print("Do you want to buy anything here? (Y/N):");
    flagC1=br.readLine();
    System.out.println();
    if (flagC1.equalsIgnoreCase("Y"))
    {
    System.out.print("Choose your beverage by entering the number :");
    bvrg=Integer.parseInt(br.readline());
    System.out.print("Enter the total number of beverage you want to buy :");
    tot_bvrg=Integer.parseInt(br.readline());
    System.out.println("****************************** *******************");
    System.out.println();
    System.out.println("<<< Section 1 Bill >>>");
    System.out.println("****************************** *******************");
    if(bvrg>1 && bvrg <=6)
    System.out.println("The total cost is £"+(tot_bvrg*2));
    System.out.println();
    }
    else
    System.out.println();
    System.out.println("****************************** ***********************");
    System.out.println("**************** Section : Snacks *******************");
    System.out.println();
    System.out.println();
    System.out.println("7. Pop Corn [Small] £2.00 8. Pop Corn [Reg] £3.00");
    System.out.println("9. Pop Corn [Large] £4.00 9. Pop Corn [XL] £5.00");
    String flagC2=new String();
    System.out.println();
    System.out.print("Do you want anything here? (Y/N):");
    flagC2=br.readLine();
    System.out.println();
    if(flagC2.equalsIgnoreCase("Y"))
    {
    System.out.println("Choose your snack by entering the number");
    snck=Integer.parseInt(br.readLine());
    System.out.println();
    System.out.println("Enter the number of snacks you want to buy");
    tot_snck=Integer.parseInt(br.readLine());
    System.out.println("****************************** ******************");
    System.out.println();
    System.out.println("<<< Section 2 Bill >>>");
    System.out.println("****************************** ******************");
    if(snck=7)
    System.out.println("Total cost is £"+(tot_snck*2));
    else if(snck=8)
    System.out.println("Total cost is £"+(tot_snck*3));
    else if(snck=9)
    System.out.println("Total cost is £"+(tot_snck*4));
    else if(snck=9)
    System.out.println("Total cost is £"+(tot_snck*5));
    }
    else
    System.out.prinln();
    System.out.println("To quit buying food enter 'Q'");
    ans1=br.readLine();
    }while((ans1.equalsIgnoreCase("Q"))!=true);
    }
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Code says I need while statement?

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    saying i need to have a while statement at the end
    Please copy the full text of the error message and paste it here. It has important info about the error.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member Chris.Brown.SPE's Avatar
    Join Date
    May 2008
    Location
    Fort Wayne, Indiana
    Posts
    190
    Thanks
    1
    Thanked 31 Times in 31 Posts

    Default Re: Code says I need while statement?

    Wow, there are errors all through this code you are going to have to deal with. I'll start with helping you out with your do/while problem. You have a couple "do" statements that are missing "while" statements. I would recommend checking each do/while statement to make sure each one has a while at the end of it (HINT: you're missing 2). After you get that fixed we can get onto your other errors. Mostly typos.
    Writing code is your job, helping you fix and understand it is mine.

    <-- Be sure to thank and REP (Star icon) those who have helped you. They appreciate it!

  4. The Following User Says Thank You to Chris.Brown.SPE For This Useful Post:

    jake143 (March 28th, 2013)

  5. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Code says I need while statement?

    Please read the forum rules. Double posts are not allowed, and doing so doesn't win any favors (actually, the opposite) with unpaid volunteers trying to help. I have removed your other post

  6. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Code says I need while statement?

    Quote Originally Posted by copeg View Post
    Please read the forum rules. Double posts are not allowed, and doing so doesn't win any favors (actually, the opposite) with unpaid volunteers trying to help. I have removed your other post
    Sorry I didn't realise it posted the first time. It won't happen again

    --- Update ---

    Thanks for the tip ill check it out later as I'm out all day today so I can't do it today

  7. #6
    Junior Member
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Code says I need while statement?

    Quote Originally Posted by Chris.Brown.SPE View Post
    Wow, there are errors all through this code you are going to have to deal with. I'll start with helping you out with your do/while problem. You have a couple "do" statements that are missing "while" statements. I would recommend checking each do/while statement to make sure each one has a while at the end of it (HINT: you're missing 2). After you get that fixed we can get onto your other errors. Mostly typos.

    So what do I do? Do I get rid of the "do" statements or do I put "while" statements on the end and if so I'm not sure what to put in the while statements

    --- Update ---

    Quote Originally Posted by Chris.Brown.SPE View Post
    Wow, there are errors all through this code you are going to have to deal with. I'll start with helping you out with your do/while problem. You have a couple "do" statements that are missing "while" statements. I would recommend checking each do/while statement to make sure each one has a while at the end of it (HINT: you're missing 2). After you get that fixed we can get onto your other errors. Mostly typos.
    I got the program working now thanks for all your help

  8. #7
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: Code says I need while statement?

    There are quite a few syntax errors and other problems. I'm surprised you wrote such a lot of code without discovering the simple ones?!? (did you copy it from somewhere? )

    Maybe you could refer to some guides that talk about incremental code development:
    "Develop in little steps, compiling and running after making each small step. These steps can be very small - even after adding just one statement you might want to compile and test the program again. " (ref)

    You should also revise the comparison == and the assignment =

    The while and do-while Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)
    Your biggest error is the missing while in the do while loop. There are particular instances when a do while loop is preferable. Make sure you really need to use them. Your code is quite difficult to read. I'm not sure of your level of experience, but I suggest breaking the program up into smaller, more manageable chunks (methods).

    Fix the small errors first, like the undeclared variables.

Similar Threads

  1. [SOLVED] A Loop statement and a switch statement issue
    By sternfox in forum Loops & Control Statements
    Replies: 13
    Last Post: March 7th, 2013, 04:19 PM
  2. Replies: 9
    Last Post: February 24th, 2013, 06:51 PM
  3. Replacing an If statement with a Switch statement
    By logi in forum Loops & Control Statements
    Replies: 9
    Last Post: February 4th, 2013, 12:21 AM
  4. Replies: 3
    Last Post: January 25th, 2013, 06:53 AM
  5. [SOLVED] What's Wrong With My Code: If Statement.
    By Java Programmer in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 9th, 2012, 08:31 PM