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.

Page 1 of 2 12 LastLast
Results 1 to 25 of 29

Thread: Help for my codes

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    16
    My Mood
    Confused
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Unhappy Help for my codes

    Hello, im new in java programming can someone help me, to fix this problem im making a program a id searching program , that the user will be ask to input an student id and if the STUDENT ID is found the program will execute the information for that id and if the id is not found the program will display "ID NOT FOUND"

    example of Student id and other information for that id
    Untitled-1.jpg

    id searching(input the Student ID
    i for this example i will ender the student id
    "lol-1:)
    input.JPG

    if id is found display the other information in that id
    output.JPG

    if id is not found this will display
    not.JPG


    *
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package student.information.pkg1;
     
    import javax.swing.JOptionPane;
     
    /**
     *
     * @author +++++
     */
    public class StudentInformation1 {
     
        /**
         * @param args the command line arguments
         */
     
        public static void main(String[] args) {
            // TODO code application logic here
     
            String Input ="";
     
            String Student [][] = {{"lol-0", "meow0", "superman0", "batman0"},
                {"lol-1", "meow1", "superman1", "batman1"},
                {"lol-2", "meow2", "superman2", "batman2"},
                {"lol-3", "meow3", "superman3", "batman3"},
                {"lol-4", "meow4", "superman4", "batman4"},
                {"lol-5", "meow5", "superman5", "batman5"}};
     
     
            boolean Superman = false;
            Input = JOptionPane.showInputDialog(null, "Enter Student ID");
     
     
            for (int x = 0; x < Input.length() ; x++){
                for (int y = 0; y <  Student[x].length; y++){
                    Superman = true;
                    break;
                }
                if (Superman){
                    System.out.println( Input + " found" );   
                }
                else{
                System.out.println(Input +  " not found ");
             }

    hope you understand me , BTW you can edit that code


    #JOptionPane
    #array elements
    #string


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

    Default Re: Help for my codes

    Can you explain what problems you are having?
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    noobie (March 19th, 2013)

  4. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    16
    My Mood
    Confused
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default Re: Help for my codes

    my problem sir for that program, if i type the student id , the program is not find the id and other information for that elements , or it find but it have a error

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help for my codes

    the program is not find the id
    Where is the id located? Where are the statements in the posted code that searches for the id?
    If you don't understand my answer, don't ignore it, ask a question.

  6. The Following User Says Thank You to Norm For This Useful Post:

    noobie (March 19th, 2013)

  7. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    16
    My Mood
    Confused
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Lightbulb Re: Help for my codes

    String Student [][] = {{"lol-0", "meow0", "superman0", "batman0"},
                {"lol-1", "meow1", "superman1", "batman1"},
                {"lol-2", "meow2", "superman2", "batman2"},
                {"lol-3", "meow3", "superman3", "batman3"},
                {"lol-4", "meow4", "superman4", "batman4"},
                {"lol-5", "meow5", "superman5", "batman5"}}

    the id is that "lol-0 to lol-5" and if the id is found the name and other elements for that line will be display

    e.g
    student id input : ol-1


    the student id is found so the program will display the other elements in that id
    name :meow1
    other 1:superman1
    other 2:batman1

  8. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help for my codes

    What problems are you having with writing the code to find the matching id?
    If you don't understand my answer, don't ignore it, ask a question.

  9. The Following User Says Thank You to Norm For This Useful Post:

    noobie (March 19th, 2013)

  10. #7
    Junior Member
    Join Date
    Mar 2013
    Posts
    16
    My Mood
    Confused
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default Re: Help for my codes

    yes sir, i having problem with writing the code to find the matching id,

  11. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help for my codes

    Post the code you are working on and ask questions about the problems you are having.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #9
    Junior Member
    Join Date
    Mar 2013
    Posts
    16
    My Mood
    Confused
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default Re: Help for my codes

    problem : having problem with writing the code to find the matching id and to display the elements on that line
    code
    import javax.swing.JOptionPane;
     
    /**
     *
     * @author +++++
     */
    public class StudentInformation1 {
     
        /**
         * @param args the command line arguments
         */
     
        public static void main(String[] args) {
            // TODO code application logic here
     
            String Input ="";
     
            String Student [][] = {{"lol-0", "meow0", "superman0", "batman0"},
                {"lol-1", "meow1", "superman1", "batman1"},
                {"lol-2", "meow2", "superman2", "batman2"},
                {"lol-3", "meow3", "superman3", "batman3"},
                {"lol-4", "meow4", "superman4", "batman4"},
                {"lol-5", "meow5", "superman5", "batman5"}};
     
     
            boolean Superman = false;
            Input = JOptionPane.showInputDialog(null, "Enter Student ID");
     
     
            for (int x = 0; x < Input.length() ; x++){
                for (int y = 0; y <  Student[x].length; y++){
                    Superman = true;
                    break;
                }
                if (Superman){
                    System.out.println( Input + " found" );   
                }
                else{
                System.out.println(Input +  " not found ");
             }


  13. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help for my codes

    There are no statements in the posted code to do the search. What have you tried so far?

    Can you describe the steps the program must take to do the search?
    If you don't understand my answer, don't ignore it, ask a question.

  14. The Following User Says Thank You to Norm For This Useful Post:

    noobie (March 19th, 2013)

  15. #11
    Junior Member
    Join Date
    Mar 2013
    Posts
    16
    My Mood
    Confused
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default Re: Help for my codes

    sir the program should ask the user to input the student id and search the student id that the user has been input, and for example if i input the lol-1 as a student id the line for that lol-1 should display the , meow0, superman0, batman0 not just a straight line that will post, but it will display like this

    student id : lol-1
    name :meow1
    other 1:superman1
    other 2:batman1


    #sorry

  16. #12
    Member
    Join Date
    Feb 2013
    Posts
    45
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: Help for my codes

    you first learn how to search string from 2d array and then you fetch the other items depends on the searching string
    Searching a 2d Array (Java) for an element - Stack Overflow
    Regards
    Android developer
    Trinay Technology Solutions
    http://www.trinaytech.com
    5705750475

  17. The Following User Says Thank You to Tamilarasi For This Useful Post:

    noobie (March 20th, 2013)

  18. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help for my codes

    search the student id
    How will the program do that step? What are the steps required to do the search?
    If you don't understand my answer, don't ignore it, ask a question.

  19. The Following User Says Thank You to Norm For This Useful Post:

    noobie (March 20th, 2013)

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

    Default Re: Help for my codes

    Do you need to use a 2-D array? Why not use a normal array for each record (read from a file perhaps)?

  21. The Following User Says Thank You to Starstreak For This Useful Post:

    noobie (March 20th, 2013)

  22. #15
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help for my codes

    What is a "normal" array? In the OP's 2 dim array, each row has related data that the OP wants to print depending on a match with the data in the first column.
    If you don't understand my answer, don't ignore it, ask a question.

  23. The Following User Says Thank You to Norm For This Useful Post:

    noobie (March 20th, 2013)

  24. #16
    Junior Member
    Join Date
    Mar 2013
    Posts
    16
    My Mood
    Confused
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default Re: Help for my codes

    Quote Originally Posted by Starstreak View Post
    Do you need to use a 2-D array? Why not use a normal array for each record (read from a file perhaps)?

    i think i need to use a 2-D array , but i don't know how to code it


    (sorry im just a noob)

  25. #17
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help for my codes

    Start with a loop to go through the elements in the array.
    Look at the 2 dim array and see what indexes to use to access the element that you want to compare against.
    If you don't understand my answer, don't ignore it, ask a question.

  26. The Following User Says Thank You to Norm For This Useful Post:

    noobie (March 20th, 2013)

  27. #18
    Junior Member
    Join Date
    Mar 2013
    Posts
    16
    My Mood
    Confused
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Wink Re: Help for my codes

    String  Student [][] = {{"lol-0", "meow0", "superman0", "batman0"},
                {"ID-1", "meow1", "superman1", "batman1"},
                {"ID-2", "meow2", "superman2", "batman2"},
                {"ID-3", "meow3", "superman3", "batman3"},
                {"ID-4", "meow4", "superman4", "batman4"},
                {"ID-5", "meow5", "superman5", "batman5"}};
     
     
            String input = JOptionPane.showInputDialog(null, "Input Here");
            int i;
            int j = 0;
            boolean foundIt = false;
     
        search:
            for (i = 0; i < Student.length; i++) {
                for (j = 0; j < Student[i].length;
                     j++) {
                    if ( Student[i][j] == null ? input == null : Student[i][j].equals(input)) {
                        foundIt = true;
                        break search;
                    }
                }
            }
     
            if (foundIt) {
                JOptionPane.showMessageDialog(null, "Found the"
                        + "id  \n\n" + input);
     
            } else {
                JOptionPane.showMessageDialog(null, input + " ID NOT FOUND");
     
            }

    now , the program is can find the ID in the element, but my problem is how can i display the column that i search using the id?

  28. #19
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: Help for my codes

    The use of labels in Java is generally discouraged if we can help it.

    If the program tries to find ID-4, we get the Student[3][0] {Student[i][j]} where 3 is the row and 0 is the column containing the ID number, then you just need to display the other elements of that particular row. We only have 0,1,2,3 to choose from and 0 is the ID number.

  29. The Following User Says Thank You to Starstreak For This Useful Post:

    noobie (March 21st, 2013)

  30. #20
    Junior Member
    Join Date
    Mar 2013
    Posts
    16
    My Mood
    Confused
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default Re: Help for my codes

    Quote Originally Posted by Starstreak View Post
    The use of labels in Java is generally discouraged if we can help it.

    If the program tries to find ID-4, we get the Student[3][0] {Student[i][j]} where 3 is the row and 0 is the column containing the ID number, then you just need to display the other elements of that particular row. We only have 0,1,2,3 to choose from and 0 is the ID number.
    ok sir can you code/show sample code sir? to display the element in the choosing row.

    advance thank you sir

  31. #21
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help for my codes

    Look at what is in the array. Each row has data for one student. One of the columns in the row has the student id.
    The search loop should look at the student id in each row. That can be done with a single loop.
    Pseudo code:
    begin loop through rows of array
    does this row have desired student id
    if yes, this row has desired data for printing
    move to next row
    end loop
    If you don't understand my answer, don't ignore it, ask a question.

  32. The Following User Says Thank You to Norm For This Useful Post:

    noobie (March 21st, 2013)

  33. #22
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: Help for my codes

    Look where your code writes "found it". That i value will be the row you need.

    The row where you found the correct ID is i. So now you just need to output the j's you want.

  34. The Following User Says Thank You to Starstreak For This Useful Post:

    noobie (March 21st, 2013)

  35. #23
    Junior Member
    Join Date
    Mar 2013
    Posts
    16
    My Mood
    Confused
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default Re: Help for my codes

    Quote Originally Posted by Norm View Post
    Look at what is in the array. Each row has data for one student. One of the columns in the row has the student id.
    The search loop should look at the student id in each row. That can be done with a single loop.
    Pseudo code:
    begin loop through rows of array
    does this row have desired student id
    if yes, this row has desired data for printing
    move to next row
    end loop
    how to write Pseudo code sir in java? and add that into my project?


    Quote Originally Posted by Starstreak View Post
    Look where your code writes "found it". That i value will be the row you need.

    The row where you found the correct ID is i. So now you just need to output the j's you want.

    sir like these?
    if (foundIt) {
                JOptionPane.showMessageDialog(null, "Found the "
                        + " id  \n\n" + input + "\n" + foundIT );
     
            } else {
                JOptionPane.showMessageDialog(null, input + " ID NOT FOUND");
     
            }

  36. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help for my codes

    Post the search code you are working on.

    The pseudo code I posted was a list of the steps the program could take to do the search. The search is done in a simple loop that looks at each row for the desired student id.
    If you don't understand my answer, don't ignore it, ask a question.

  37. #25
    Junior Member
    Join Date
    Mar 2013
    Posts
    16
    My Mood
    Confused
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default Re: Help for my codes

    Quote Originally Posted by Norm View Post
    Post the search code you are working on.

    The pseudo code I posted was a list of the steps the program could take to do the search. The search is done in a simple loop that looks at each row for the desired student id.
    public static void main (String []args)
        {
        String  Student [][] = {{"ID-0", "meow0", "superman0", "batman0"},
                {"ID-1", "meow1", "superman1", "batman1"},
                {"ID-2", "meow2", "superman2", "batman2"},
                {"ID-3", "meow3", "superman3", "batman3"},
                {"ID-4", "meow4", "superman4", "batman4"},
                {"ID-5", "meow5", "superman5", "batman5"}};
     
     
            String input = JOptionPane.showInputDialog(null, "Input Here");
            int i;
            int j = 0;
            boolean foundIt = false;
     
        search:
            for (i = 0; i < Student.length; i++) {
                for (j = 0; j < Student[i].length;
                     j++) {
                    if ( Student[i][j] == null ? input == null : Student[i][j].equals(input)) {
                        foundIt = true;
                        break search;
                    }
                }
            }
     
            if (foundIt) {
                JOptionPane.showMessageDialog(null, "Found the "
                        + " id  \n\n" + input + "\n" );
     
            } else {
                JOptionPane.showMessageDialog(null, input + " ID NOT FOUND");
     
            }
    my problem, how can i display the element in the column, using the ID that i search ?

    for e.g i search
    ID-3 and ID-3 column the other will also display, but in a new line, like these
    meow3
    superman3
    batman3

Page 1 of 2 12 LastLast

Similar Threads

  1. need help with loops and codes..
    By akocnivek in forum Loops & Control Statements
    Replies: 1
    Last Post: October 19th, 2012, 02:02 AM
  2. Help me please with my codes
    By sara92 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 12th, 2012, 11:52 AM
  3. Looking for help on two codes:
    By captianjaax in forum What's Wrong With My Code?
    Replies: 24
    Last Post: September 20th, 2011, 11:49 PM
  4. Please Help What's Wrong with my Codes!
    By bertzki10 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 25th, 2011, 11:03 AM
  5. help us in eclipse basic codes
    By bil_Imma in forum AWT / Java Swing
    Replies: 1
    Last Post: January 24th, 2009, 06:02 PM