This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Micro Frontends in Action and have Michael Geers on-line!
See this thread for details.
Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Problem with brackets and switch statements.

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I've been working on a school project for the past couple weeks in an object oriented design class. I'm stumped on something that seems simple so I need some new eye. I've talked to a friend taking another java class (gui based), I've spent hours playing with brackets and break; lines. I think I'm just mentally exhausted so it was suggested I ask for some help.

I'm using Dr. Java. Went through and corrected all the dumb little errors I've made (mostly capitalization, misspellings, etc.) but the last two still remain. They seem so simple yet for the life of me I can't figure it out. It has to be something I'm completely not seeing, or I'm trying to code beyond my skill by using multiple switch statements to do submenus. Here are the errors:

2 errors found:
File: C:\..\StoreMain.java [line: 162]
Error: Syntax error on token "{", } expected after this token
File: C:\..\StoreMain.java [line: 196]
Error: Syntax error on token "{", } expected after this token

Here is the code, I'm only including everything in the main where errors occur. I've isolated the problem to here, everything else compiles fine when I comment out the bad code. Keep in mind this is nowhere near finished, I just wanted to get basic functionality up and running. I still need to add error checking and a lot of other housekeeping code, format things to make them look presentable, etc. We weren't provided any data to start with so I built it to accept new data/objects and was going to input some test data on my own to get started but I can't even get to that point.

Thanks in advance!

 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A switch statement can contain case statements, but not other code. You need to move the while loops elsewhere.
 
Anthony Ford
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was quick, thanks a lot!
 
Marshal
Posts: 70370
283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will always find it hard to find compiler errors if you write that much code. Write no more than 10 lines, compile it, and look for the errors. It is much easier like that.

And welcome to the Ranch
 
Everybody! Do the Funky Monkey! Like this tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic