Connecting Tech Pros Worldwide Forums | Help | Site Map

reached end of file while parsing

Newbie
 
Join Date: Jul 2007
Posts: 13
#1: Jul 17 '07
Hi,can somebody help me, I am trying to compile a programm but have an error
it is called reached end of file while parsing?? Anyone mind th have a look for some help

public class records
{
public static void main (String args[]){
System.out.println("Enter name");
float name = Keyboard.readInt();

switch (name) {
case Ryan:
System.out.println ("I.D. 0569290(M) SURNAME Mifsud GROUP NO 1");
break;

switch (name) {
case Robert:
System.out.println ("I.D. 086790(M) SURNAME Vella GROUP NO 3");
break;

switch (name) {
case Victor:
System.out.println ("I.D. 0548790(M) SURNAME Cassar GROUP NO 5");
break;

switch (name) {
case Jim:
System.out.println ("I.D. 0971790(M) SURNAME Dimech GROUP NO 8");
break;

switch (name) {
case Sam:
System.out.println ("I.D. 0321790(M) SURNAME Muscat GROUP NO 10");
break;

switch (name) {
case Leo:
System.out.println ("I.D. 0104790(M) SURNAME MIfsud GROUP NO 2");
break;

switch (name) {
case Glen:
System.out.println ("I.D. 0274790(M) SURNAME Borg GROUP NO 6");
break;

switch (name) {
case Kyle:
System.out.println ("I.D. 0721790(M) SURNAME Fabri GROUP NO 11");
break;

switch (name) {
case Kurt:
System.out.println ("I.D. 0589790(M) SURNAME Caruana GROUP NO 2");
break;

switch (name) {
case Ian:
System.out.println ("I.D. 0761790(M) SURNAME Grima GROUP NO 4");
break;

default:
System.out.println("Invalid name");
}
} the error is on the last bold bracket

JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#2: Jul 17 '07

re: reached end of file while parsing


There's a whole lot wrong with your program. The syntax of a switch statement
is like this:

Expand|Select|Wrap|Line Numbers
  1. switch (<integer expression>) {
  2.    case <integer constant expression>: <statements>
  3.    ...
  4.    case <integer constant expression>: <statements>
  5.    default: <statements> // but 'default is optional
  6. }
  7.  
But the worst error is: you can't switch on a float type (a name?). You have
to redesign the whole lot. And where do these Jims, Kens, Marys come from?

kind regards,

Jos
blazedaces's Avatar
Needs Regular Fix
 
Join Date: May 2007
Posts: 280
#3: Jul 17 '07

re: reached end of file while parsing


Quote:

Originally Posted by max3

Hi,can somebody help me, I am trying to compile a programm but have an error
it is called reached end of file while parsing?? Anyone mind th have a look for some help

Expand|Select|Wrap|Line Numbers
  1. public class records
  2. {
  3.     public static void main (String args[]){
  4.         System.out.println("Enter name");
  5.             float  name = Keyboard.readInt();
  6.  
  7.         switch (name) {
  8.             case Ryan:
  9.                 System.out.println ("I.D. 0569290(M)  SURNAME Mifsud GROUP NO 1");
  10.                 break;
  11.  
  12.         switch (name) {
  13.             case Robert:
  14.                 System.out.println ("I.D. 086790(M)  SURNAME Vella GROUP NO 3");
  15.                 break;
  16.  
  17.             switch (name) {
  18.                 case Victor:
  19.                     System.out.println ("I.D. 0548790(M)  SURNAME Cassar GROUP NO 5");
  20.                     break;
  21.  
  22.             switch (name) {
  23.                 case Jim:
  24.                     System.out.println ("I.D. 0971790(M)  SURNAME Dimech GROUP NO 8");
  25.                     break;
  26.  
  27.             switch (name) {
  28.                 case Sam:
  29.                     System.out.println ("I.D. 0321790(M)  SURNAME Muscat GROUP NO 10");
  30.                     break;
  31.  
  32.             switch (name) {
  33.                 case Leo:
  34.                     System.out.println ("I.D. 0104790(M)  SURNAME MIfsud GROUP NO 2");
  35.                     break;
  36.  
  37.             switch (name) {
  38.                 case Glen:
  39.                     System.out.println ("I.D. 0274790(M)  SURNAME Borg GROUP NO 6");
  40.                     break;
  41.  
  42.             switch (name) {
  43.                 case Kyle:
  44.                     System.out.println ("I.D. 0721790(M)  SURNAME Fabri GROUP NO 11");
  45.                     break;
  46.  
  47.             switch (name) {
  48.                 case Kurt:
  49.                     System.out.println ("I.D. 0589790(M)  SURNAME Caruana GROUP NO 2");
  50.                     break;
  51.  
  52.             switch (name) {
  53.                 case Ian:
  54.                     System.out.println ("I.D. 0761790(M)  SURNAME Grima GROUP NO 4");
  55.                     break;
  56.  
  57.             default:
  58.                 System.out.println("Invalid name");
  59.         }
  60.     }
the error is on the last bold bracket

Hello, and welcome to TSDN. First of all, from now on if you could please try and put your code in code tags (look on the right when you're posting to the box that says "REPLY GUIDELINES").

Now, I don't know if this is the exact problem, but I know it is one that needs fixing, this line:

Expand|Select|Wrap|Line Numbers
  1. float  name = Keyboard.readInt();
  2.  
That should be readFloat() right ...? Also, when are you instantiating your scanner keyboard... I don't see it. Is this really the only error you're receiving?

OH OH, I found your problem. I'm almost 100% sure it says this when you have not closed your brackets properly. Add another bracket on the bottom there ok... try that. If not, count your brackets again, there should be an exact number of pairs, one close bracket for each open...

Hope that helped,

-blazed
Newbie
 
Join Date: Jul 2007
Posts: 13
#4: Jul 17 '07

re: reached end of file while parsing


hi i'am an absolute beginner in programming. I am trying to create a database program for my school project which I urgenty need. the program is a database which when i input names it gives me information (Surname, I.D. no Group ) about the person.Could you please guide me through the writing of this program.thanks
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#5: Jul 17 '07

re: reached end of file while parsing


Quote:

Originally Posted by max3

hi i'am an absolute beginner in programming. I am trying to create a database program for my school project which I urgenty need. the program is a database which when i input names it gives me information (Surname, I.D. no Group ) about the person.Could you please guide me through the writing of this program.thanks

Try a Properties object first. You can have a little text file that looks like this:
Expand|Select|Wrap|Line Numbers
  1. Ryan= I.D. 0569290(M) SURNAME Mifsud GROUP NO 1
  2. Robert= I.D. 086790(M) SURNAME Vella GROUP NO 3
  3. Victor= I.D. 0548790(M) SURNAME Cassar GROUP NO 5
  4. Jim= I.D. 0971790(M) SURNAME Dimech GROUP NO 8
  5. Sam= I.D. 0321790(M) SURNAME Muscat GROUP NO 10
  6.  
etc. etc. A Properties object can read itself given an InputStream. First check
out the "article index" post in the Java Articles section. At the end of that
article you can find a link where you can download the complete API documentation
for all the Java core classes. Please download the stuff and read all about the
Properties class.

kind regards,

Jos
blazedaces's Avatar
Needs Regular Fix
 
Join Date: May 2007
Posts: 280
#6: Jul 17 '07

re: reached end of file while parsing


Quote:

Originally Posted by max3

hi i'am an absolute beginner in programming. I am trying to create a database program for my school project which I urgenty need. the program is a database which when i input names it gives me information (Surname, I.D. no Group ) about the person.Could you please guide me through the writing of this program.thanks

Hold up there man. Take this one step at a time. Split this into as many tiny parts you have to understand and come up with. What do you know/have done before and what do you not have a clue about? Do you need to make it as complex as you're making it? The old saying comes to mind: "keep it simple stupid". Just keep it simple, step by step, we can get through this.

-So you're going to input names, first get that down pat. Write a program that asks the user for a name, then prints it to the screen.

-Next, go to sun's tutorial website and take some tutorials on using databases (not an easy step, but you need it if you want to tackle databases)

-Then write a program that simply spits out info from the database.

-Then write a program that asks a user for something and prints the info.

It should be even more steps, but you get the picture...

Good luck,

-blazed
Newbie
 
Join Date: Jul 2007
Posts: 13
#7: Jul 17 '07

re: reached end of file while parsing


this programm needs to have ten persons ?? am I using a good method ??
blazedaces's Avatar
Needs Regular Fix
 
Join Date: May 2007
Posts: 280
#8: Jul 17 '07

re: reached end of file while parsing


Quote:

Originally Posted by max3

this programm needs to have ten persons ??

Why are you asking us?
Quote:
am I using a good method ??
Method to do what? Design a program that involves a database and information retrieval? Which method are you talking about?

-blazed
Newbie
 
Join Date: Jul 2007
Posts: 13
#9: Jul 17 '07

re: reached end of file while parsing


What does orphaned default means??
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#10: Jul 17 '07

re: reached end of file while parsing


Quote:

Originally Posted by max3

What does orphaned default means??

Don't think about that for now, you can't use a switch statement for your purposes.

kind regards,

Jos
Newbie
 
Join Date: Jul 2007
Posts: 13
#11: Jul 17 '07

re: reached end of file while parsing


which statement in your opinion should i use??if you are saying switch is not good ??
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#12: Jul 17 '07

re: reached end of file while parsing


Quote:

Originally Posted by max3

which statement in your opinion should i use??if you are saying switch is not good ??

Don't think about that either; as blazedaces suggested: try to read a name from
somewhere and echo it back on the screen. Try to accomplish that first. Better
take a lot of baby steps you *do* understand instead of one big step that baffles
you. You have to learn how to walk before you can run; really.

kind regards,

Jos
blazedaces's Avatar
Needs Regular Fix
 
Join Date: May 2007
Posts: 280
#13: Jul 17 '07

re: reached end of file while parsing


Quote:

Originally Posted by max3

which statement in your opinion should i use??if you are saying switch is not good ??

You technically could use a switch statement, but a switch is always of either an integer, or a character. It can not be of a string or a float.

You technically could make an array of strings, then when you ask the user for a name (Which I'm assuming you want the name to be a string, so you should be doing "String" name = keyboard.read() or something like that...) you could search for it in your array and then use a switch of the index (location in the array) where that string is stored. Then spit out the data.

I'm going to have to say though, this is unnecessarily complex. It doesn't need to be. Re-evaluate.

What EXACTLY do you need to do? It's a school project right? What are the specific requirements (you don't need to tell me, just think about it again). Maybe you don't need a database. Maybe you don't need a switch statement. Think about what you need and think of another solution...

Good luck
-blazed
Moderator
 
Join Date: Mar 2006
Posts: 1,103
#14: Jul 17 '07

re: reached end of file while parsing


1. You want a string name not an integer.
Use String name = Keyboard.readLine();
or readString()
depending on what Keyboard class you are using.

2. You cannot switch on a string. Unfortunately you'd have to use if/else statements. eg.
if (name.equals("Jonathan")) {
// some action
} else if (name.equals("Jimmy")){
// some other action ..
} ...


3. For string comparison you have to use .equals() as opposed to == operator.
Reply