Results 1 to 20 of 27
Thread: I need help
- 01-25-2008, 08:42 AM #1
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.
- 01-25-2008, 08:55 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 25
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.
- 01-25-2008, 09:03 AM #3
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.
- 01-25-2008, 09:09 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 25
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.
- 01-25-2008, 10:28 AM #5
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!!!
- 01-25-2008, 10:48 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 25
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.
- 01-25-2008, 10:50 AM #7
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.
- 01-25-2008, 10:57 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 25
Ste the following ling, 3. Initialize Total_Age = 0
Then,
Java Code:If every "AGE" is greater than zero Total_age = Total_Age + AGE
- 01-25-2008, 10:59 AM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 25
Since you have number of students, you can find the average as follows
Initialize AVG = 0
AVG = Total_Age / Total_Std_Count
- 01-25-2008, 11:01 AM #10
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.
- 01-25-2008, 11:02 AM #11
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.
- 01-25-2008, 11:06 AM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 25
- 01-25-2008, 11:11 AM #13
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.
- 01-25-2008, 11:16 AM #14
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 25
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
- 01-25-2008, 11:17 AM #15
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!
- 01-25-2008, 11:18 AM #16
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.
- 01-25-2008, 11:21 AM #17
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 25
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. ;)
- 01-25-2008, 11:23 AM #18
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 25
- 01-25-2008, 05:49 PM #19
Thank You very much Eranga you the man!!!
Hope to become a good programmer someday hehe
- 01-26-2008, 06:23 AM #20
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 25
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
Bookmarks