reached end of file while parsing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • max3
    New Member
    • Jul 2007
    • 13

    reached end of file while parsing

    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.prin tln("Enter name");
    float name = Keyboard.readIn t();

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

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

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

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

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

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

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

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

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

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

    default:
    System.out.prin tln("Invalid name");
    }
    } the error is on the last bold bracket
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

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

    [code=java]
    switch (<integer expression>) {
    case <integer constant expression>: <statements>
    ...
    case <integer constant expression>: <statements>
    default: <statements> // but 'default is optional
    }
    [/code]

    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

    Comment

    • blazedaces
      Contributor
      • May 2007
      • 284

      #3
      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

      Code:
      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");
              }
         [B] }[/B]
      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:

      Code:
      float  name = Keyboard.readInt();
      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

      Comment

      • max3
        New Member
        • Jul 2007
        • 13

        #4
        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

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          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:
          Code:
          Ryan= I.D. 0569290(M) SURNAME Mifsud GROUP NO 1
          Robert= I.D. 086790(M) SURNAME Vella GROUP NO 3
          Victor= I.D. 0548790(M) SURNAME Cassar GROUP NO 5
          Jim= I.D. 0971790(M) SURNAME Dimech GROUP NO 8
          Sam= I.D. 0321790(M) SURNAME Muscat GROUP NO 10
          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

          Comment

          • blazedaces
            Contributor
            • May 2007
            • 284

            #6
            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

            Comment

            • max3
              New Member
              • Jul 2007
              • 13

              #7
              this programm needs to have ten persons ?? am I using a good method ??

              Comment

              • blazedaces
                Contributor
                • May 2007
                • 284

                #8
                Originally posted by max3
                this programm needs to have ten persons ??
                Why are you asking us?
                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

                Comment

                • max3
                  New Member
                  • Jul 2007
                  • 13

                  #9
                  What does orphaned default means??

                  Comment

                  • JosAH
                    Recognized Expert MVP
                    • Mar 2007
                    • 11453

                    #10
                    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

                    Comment

                    • max3
                      New Member
                      • Jul 2007
                      • 13

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

                      Comment

                      • JosAH
                        Recognized Expert MVP
                        • Mar 2007
                        • 11453

                        #12
                        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

                        Comment

                        • blazedaces
                          Contributor
                          • May 2007
                          • 284

                          #13
                          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

                          Comment

                          • jkmyoung
                            Recognized Expert Top Contributor
                            • Mar 2006
                            • 2057

                            #14
                            1. You want a string name not an integer.
                            Use String name = Keyboard.readLi ne();
                            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("J onathan")) {
                            // some action
                            } else if (name.equals("J immy")){
                            // some other action ..
                            } ...


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

                            Comment

                            Working...