Urgently need help for school program please help

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

    Urgently need help for school program please help

    Hi to all I'am trying to run this program for my school progect but I keep receiving the same answer when I compile ')' expected. on the highlighted line can anyone help me thanks to all.



    /**
    * Write a description of class Records here.
    *
    * @author (Ryan MIfsud)
    * @version (version 1)
    */
    public class Records
    {


    public static void main (String Args []){

    String Student_Name1;
    String Student_surname 1;
    String Student_ID1;
    String Student_group1;
    System.out.prin tln ("Enter name ");
    int name = Keyboard.readIn t();
    char grade;

    grade = '_';

    if ( name > Ryan,Robert,Vic tor,Jim,Sammy,L eo,Glen,Kyle || name < Kurt) System.out.prin tln ("name is not included");
    else

    if (name >= Ryan,Robert,Vic tor,Jim,Sammy,L eo,Glen,Kyle && name <= Kurt )
    grade = 'name included';



    System.out.prin tln ( "Enter student's name" );
    Student_Name1 = Keyboard.readSt ring();

    System.out.prin tln ( "Enter student's surname" );
    Student_surname 1 = Keyboard.readSt ring();

    System.out.prin tln( "Enter student's ID" );
    Student_ID1 = Keyboard.readSt ring();

    System.out.prin tln( "Enter student's group" );
    Student_group1 = Keyboard.readSt ring();

    System.out.prin tln ( Student_Name1 + Student_surname 1 + Student_ID1 + Student_group1 );

    System.out.prin tln ("End by entering -1");
    int counter = -1;


    }

    }
  • blazedaces
    Contributor
    • May 2007
    • 284

    #2
    Hey, from now on please put your code in code tags (look on the right when you post on the box that says "REPLY GUIDELINES". Also, could you post the full error you get when you try to compile. I'm a bit confused as to what exactly it's trying to tell you...

    -blazed

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      if (name >= Ryan,Robert,Vic tor,Jim,Sammy,L eo,Glen,Kyle && name <= Kurt )
      grade = 'name included';


      Those two lines will not compile. What are you trying to do there?
      Also char variable can only hold chars.

      Comment

      • max3
        New Member
        • Jul 2007
        • 13

        #4
        I'am trying to creat a program that when I give name ,surname and Id in the list it will give me the name and when it is not in the list it will say name not included thanks for your interest and sorry to Blazedaces about the the codes but I'm still new in this fourm and did't understand exactly how the codes work thank you

        When I compile this is what I get ')' expected

        Comment

        • blazedaces
          Contributor
          • May 2007
          • 284

          #5
          Originally posted by max3
          I'am trying to creat a program that when I give name ,surname and Id in the list it will give me the name and when it is not in the list it will say name not included thanks for your interest and sorry to Blazedaces about the the codes but I'm still new in this fourm and did't understand exactly how the codes work thank you

          When I compile this is what I get ')' expected
          I don't think you can compare more then one result by separating it by a comma like that. I don't think this is possible: name < firstVariable, secondVariable. I think you need to do name < firstVariable && name < secondVariable.

          The compiler may think the comma indicates some end for the if statement and wants you to close the parenthesis or something. Also, as mentioned by r035198x above, are you comparing characters or is name and those variables simply integers or something?

          Why are you using < to find out if the name is not included in the list?

          -blazed

          Comment

          • max3
            New Member
            • Jul 2007
            • 13

            #6
            Hi I'm only trying to find a selective name out of the list and regarding using this symbol < I think it's the best in my opinion have you any suggestions? thanks what in your opinion should I do to make this program work.

            Comment

            • blazedaces
              Contributor
              • May 2007
              • 284

              #7
              Originally posted by max3
              Hi I'm only trying to find a selective name out of the list and regarding using this symbol < I think it's the best in my opinion have you any suggestions? thanks what in your opinion should I do to make this program work.
              The "<" symbol compares two numbers and if the first is "less than" the other, it returns true, otherwise it returns false... How does this have anything to do with finding a selective name out of the list?

              If you asked a random person "is Jake less then Ronald" they would ask you what you're talking about, which is exactly what the JVM will do.

              What I think you should do is go through the entire list one at a time and ask "is Jake the same name as ronald?" no, repeat throughout the entire list. Use the String1.equals( String2) method...

              Good luck,
              -blazed

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by max3
                Hi I'm only trying to find a selective name out of the list and regarding using this symbol < I think it's the best in my opinion have you any suggestions? thanks what in your opinion should I do to make this program work.
                Have you read a tutorial about how that symbol is used?

                Comment

                • max3
                  New Member
                  • Jul 2007
                  • 13

                  #9
                  R035198 the < symbol means less than and I think it is one of the problems I have I try to change as blazedaces said and tell you what happend later .thanks

                  Comment

                  • JosAH
                    Recognized Expert MVP
                    • Mar 2007
                    • 11453

                    #10
                    Originally posted by max3
                    if ( name > Ryan,Robert,Vic tor,Jim,Sammy,L eo,Glen,Kyle || name < Kurt)
                    Don't just guess what Java's syntax is supposed to be according to what you
                    wish it to be. Compare it to this: suppose I have my own private understanding
                    of what a 'fronobulax' is supposed to be. Nobody else would understand me if
                    I'd ask anyone where to buy fresh fronobulaxes. If you want to program in Java
                    you have to speak the Java language. When in Rome, do as the Romans do.

                    kind regards,

                    Jos

                    Comment

                    • ramadeviirrigireddy
                      New Member
                      • Jul 2007
                      • 54

                      #11
                      Hi,


                      I don't know whether this statement which u used is valid or not(if ( name > Ryan,Robert,Vic tor,Jim,Sammy,L eo,Glen,Kyle || name < Kurt) ). But what i suggest is write like this [if (( name > Ryan,Robert,Vic tor,Jim,Sammy,L eo,Glen,Kyle) || (name < Kurt) )] when ever u use this || or && operators.

                      Hi all let me know if i'm wrong.

                      Comment

                      • JosAH
                        Recognized Expert MVP
                        • Mar 2007
                        • 11453

                        #12
                        Originally posted by ramadeviirrigir eddy
                        Hi,


                        I don't know whether this statement which u used is valid or not(if ( name > Ryan,Robert,Vic tor,Jim,Sammy,L eo,Glen,Kyle || name < Kurt) ). But what i suggest is write like this [if (( name > Ryan,Robert,Vic tor,Jim,Sammy,L eo,Glen,Kyle) || (name < Kurt) )] when ever u use this || or && operators.

                        Hi all let me know if i'm wrong.
                        You're wrong ;-)

                        If those names are comparable using the '<' or '>' operators they need to be
                        identifiers of primitive numerical type. If they are of type String, those operators
                        can't be used. The comma operator isn't defined in Java. That 'statement' (mind
                        the quotes) is completely wrong.

                        kind regards,

                        Jos

                        Comment

                        • emekadavid
                          New Member
                          • Mar 2007
                          • 46

                          #13
                          I think from the discussion i gathered this information:
                          the names you're comparing against are the “accepted” names for this course, group etc therefore the user is limited to just those and has a “closed” outlook to any other, hence the need for an if statement that compares twice against just that list.
                          The problem: implement this closet in a list such that when a name is to be in this close group, there is a list to compare against. Instead of doing:
                          if (name > X1, X2 || name < X3 etc) //this is a list, maybe two lists the comparison on greater than and on less than?
                          Rather do:
                          If ( list1.contains( name) || list2.contains( name)) then...”name included”.
                          else ....”name not included” //somewhat simpler and less code.

                          i wonder what your keyboard class is? Can't find any Keyboard class in the jdk 6 documentation though i believe it refers to user input. Why do you have to readInt this input and then compare against String? No compiler would accept that. Rather read on string and verify on string input since this is name and name should be string, if black is black and never shades of it.

                          Comment

                          • ramadeviirrigireddy
                            New Member
                            • Jul 2007
                            • 54

                            #14
                            thanks Jos for correcting me

                            Comment

                            • padmavathik
                              New Member
                              • Jul 2007
                              • 2

                              #15
                              Originally posted by ramadeviirrigir eddy
                              thanks Jos for correcting me

                              hi,
                              you have taken name as integer and names are in string,
                              they r incompatable types.
                              compare name with the length of strings and also take all the atrings into an array.
                              I think taht oparator will not compare more than one so better to take all strings into array.
                              String [] arr = new String[Ryan,Robert,Vic tor,Jim,Sammy,L eo,Glen,Kyle] ;

                              for(int i=0;i<arr.size( );i++)
                              {
                              if(name>(arr.ge t(i)).length()| |name<kurt.leng th())
                              System.out.prin tln("not included);
                              else
                              if (name >=(arr.get(i)). length()&& name <= Kurt.length() )
                              grade = 'name included'

                              }
                              once try this iam not sure

                              Comment

                              Working...