Page 1 of 2 12 LastLast
Results 1 to 20 of 27

Thread: I need help

  1. #1
    Join Date
    Jan 2008
    Location
    Singapore
    Posts
    24
    Rep Power
    0

    Unhappy I need help

    Hi All,

    I am new to Java programming have not even started yet i am already stuck at doing pseudo-code. I have this assignment coming up require me to write a pseudo-code:

    Can anyone please give my code a check coz i really clueless now.
    --------------------------------------------------------------------------
    Given a student file, you need to complete the following logical design task by using pseudo code:

    1)Display the details of the students who are from Indonesia and study Multimedia

    2)Show the total number of students of above student

    3)Show the total number of female students in the file

    4)show the average age of all the students
    --------------------------------------------------------------------------
    1. Initialize Total_Std_Count = 0
    2. Initialize Total_Female_Std = 0
    3. Initialize STD_NO = 0

    4. OPEN STUDENT_FILE

    5. READ a Record (NATIONALITY, SUBJECT, AGE, GENDER)

    6. LOOP UNTIL end of file

    7. IF every "NATIONALITY" matches "Indonesia" AND
    8. IF every "SUBJECT" matches "Multimedia" THEN
    Add 1 to Total_Std_Count
    DISPLAY TOTAL_STD_COUNT
    9. ELSE
    DISPLAY "NO_STD_RECORD_FOUND"

    10. ENDIF

    11. IF every Gender = Female THEN
    Add 1 to Total_Female_Std
    DISPLAY Total_Female_Std
    ELSE
    DISPLAY "NO RECORD FOUND"

    I got stuck at the calculate avg age. I do not know whether the above code is correct. Please do enlighten me thanks all.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Clemenza1983 View Post
    I got stuck at the calculate avg age. I do not know whether the above code is correct. Please do enlighten me thanks all.
    Welcome to the Java forum :)

    Seems your code is not bad. In the above case, to calculate average age, you have to find the sum of all students age and number of students. You find that you have to LOOP until end-of-file found, that's correct. So where why are you stuck. Just find those details within the loop.

  3. #3
    Join Date
    Jan 2008
    Location
    Singapore
    Posts
    24
    Rep Power
    0

    Default

    So do you imply that my code is on the right track, coz somehow i just feel that is somewhere out of the way. Am i correct to link all these codes together? Sorry really new to this really need alot of guidance. Thanks appreciated.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Yes, but in implementing you can change the way appropriately. Best thing is start work right now and if you stuck, get back to here.

  5. #5
    Join Date
    Jan 2008
    Location
    Singapore
    Posts
    24
    Rep Power
    0

    Default Still do not get it.

    Hi there all ppl out there can anyone please guide me on this i really need guidance after search and reading thru i still confuse on how to actually do a good pseudocode. Gosh please i need help!!!

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Ok pal, now what is your question. The previous code is correct actually. And at the same time different people can seen it in different views. Now where are you stuck.

  7. #7
    Join Date
    Jan 2008
    Location
    Singapore
    Posts
    24
    Rep Power
    0

    Default

    I am stuck at the average student age, can i put it this manner?

    STD_NO STD_NAME GENDER AGE SUBJECT NATIONALITY
    ---------------------------------------------------------------------------
    1001 Albert Male 20 Programing England
    1002 Boey Male 21 Engineering Indonesia
    1003 Chan Mei Ling Female 21 Graphic Design China
    1004 Dahnia Female 22 Networking India
    1005 Melanie Female 23 Multimedia Philipines
    1006 Yung Hua Male 24 Multimedia Indonesia
    1007 Gerry Male 24 Multimedia Indonesia
    1008 Canny Liew Female 24 Networking Malaysia
    1009 Ben Low Male 26 Programing Singapore
    ================================================== =========================

    1. Initialize Total_Std_Count = 0
    2. Initialize Total_Female_Std = 0
    3. Initialize Age =

    4. OPEN STUDENT_FILE

    5. READ a Record (NATIONALITY, SUBJECT, AGE, GENDER)

    6. LOOP UNTIL end of file

    7. IF every "NATIONALITY" matches "Indonesia" AND
    8. IF every "SUBJECT" matches "Multimedia" THEN
    Add 1 to Total_Std_Count
    DISPLAY TOTAL_STD_COUNT
    9. ELSE
    DISPLAY "NO_STD_RECORD_FOUND"

    10. ENDIF

    11. IF every Gender = Female THEN
    Add 1 to Total_Female_Std
    DISPLAY Total_Female_Std
    ELSE
    DISPLAY "NO RECORD FOUND"

    12. ENDIF

    13. IF STD_NO < 1010 THEN
    Add 1 to Total_Std_Count
    ELSE DISPLAY "ERROR"
    14. How to i add the age? Please help me here thanks.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Ste the following ling, 3. Initialize Total_Age = 0

    Then,

    Java Code:
    If every "AGE" is greater than zero
    Total_age = Total_Age + AGE
    No need of else part actually. If you you can use a 'else' to display an error, like Age can't be valid or something like that. Is it helpful to you?

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Since you have number of students, you can find the average as follows

    Initialize AVG = 0
    AVG = Total_Age / Total_Std_Count

  10. #10
    Join Date
    Jan 2008
    Location
    Singapore
    Posts
    24
    Rep Power
    0

    Default

    Oh yes it is very helpful thank you so much. It the logic that i have to get use 2 but it seems like my brain have lots of things already and my workload is getting too much for me to handle

    IF Study and Work < Time
    DISPLAY "TIRING"

    hehe how i wish i can have someone to discuss these things with.

  11. #11
    Join Date
    Jan 2008
    Location
    Singapore
    Posts
    24
    Rep Power
    0

    Default

    But first i have to add up all the ages that is the part which i do not understand but thanks anyway Eranga for your reply really appreciate it.

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Clemenza1983 View Post
    But first i have to add up all the ages that is the part which i do not understand
    That's what I have done in my 8th post. Is it not clear for you?

  13. #13
    Join Date
    Jan 2008
    Location
    Singapore
    Posts
    24
    Rep Power
    0

    Default

    What i dun understand is
    If every "AGE" is greater than zero
    (Total_age = Total_Age + AGE) --> this is the part i do not understand.

    Can pls explain how you get Total Age may be a silly question but i just do not understand this part.

    Do you have msn messenger? I know it inappropriate for me to ask this.

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Here is much simpler way I can come across with your question.

    Java Code:
    1. Initialize Total_Std_Count = 0
    2. Initialize Total_Female_Std = 0
    3. Initialize Total_Age = 0
    4. Initialize Avg = 0
    
    5. OPEN STUDENT_FILE
    
    6. READ a Record (NATIONALITY, SUBJECT, AGE, GENDER)
    
    7. LOOP UNTIL end of file
    
    8. IF every "NATIONALITY" matches "Indonesia" AND
            every "SUBJECT" matches "Multimedia"
            THEN
                 Add 1 to Total_Std_Count
    
    9. ELSE
          DISPLAY "NO_STD_RECORD_FOUND"
    
    10.IF every Gender = Female
            THEN Add 1 to Total_Female_Std
    
    11.ELSE
          DISPLAY "NO_RECORD_FOUND" 
                 
    
    12.IF every "AGE" is greater than zero
          Then
              Add AGE to Total_Age
    
    13.ELSE 
          DISPLAY "Invalid age"
    
    14.DISPLAY Total_Std_Count
    
    15.DISPLAY Total_Female_Std
    
    16.CALCULATE AVG as
            Total_Age devide by Total_Std_Count
    
    17.DISPLAY AVG

  15. #15
    Join Date
    Jan 2008
    Location
    Singapore
    Posts
    24
    Rep Power
    0

    Default

    I am going for my night class now i will be back later anyway thanks eranga you are the first to reply to my question i really appreciate it hope to hear from you soon as a friend. Out!

  16. #16
    Join Date
    Jan 2008
    Location
    Singapore
    Posts
    24
    Rep Power
    0

    Default

    Thank you i am sure i be able to work these out coz i also do not wish to copy these step i wanna find out the logic out myself or else there is no point in studying java haha you been of great help.

  17. #17
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Clemenza1983 View Post
    What i dun understand is
    If every "AGE" is greater than zero
    (Total_age = Total_Age + AGE) --> this is the part i do not understand.

    Can pls explain how you get Total Age may be a silly question but i just do not understand this part.

    Do you have msn messenger? I know it inappropriate for me to ask this.
    Ok, first I initialized Total_Age to zero. Then you read the file, say line by line. At the reading time you can find the age of each student. I think it is clear.

    Say first student age is 20, then
    Total_Age = 0 + 20 --> Result is 20

    Say second student age is 15, then
    Total_Age = 20 + 15 --> Result is 35

    I have put a condition, age greater than zero. Because no one can have zero age. Is it clear to you.

    BTW, if you can use my Yahoo messenger. You can see it my profile. ;)

  18. #18
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Clemenza1983 View Post
    Thank you i am sure i be able to work these out coz i also do not wish to copy these step i wanna find out the logic out myself or else there is no point in studying java haha you been of great help.
    Yep, learn the basis well first. Mainly the logic of each problem you come across with.

  19. #19
    Join Date
    Jan 2008
    Location
    Singapore
    Posts
    24
    Rep Power
    0

    Default

    Thank You very much Eranga you the man!!!
    Hope to become a good programmer someday hehe

  20. #20
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Yep, try to do it You can do it in right way, be with Java forum. Me and all other users are always ready to help you pal.

    Have you solve the problem? If you, I'm really happy yo hear that pal.:p

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •