# I need help

Show 40 post(s) from this thread on one page
Page 1 of 2 12 Last
• 01-25-2008, 08:42 AM
Clemenza1983
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
DISPLAY TOTAL_STD_COUNT
9. ELSE
DISPLAY "NO_STD_RECORD_FOUND"

10. ENDIF

11. IF every Gender = Female THEN
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
Eranga
Quote:

Originally Posted by Clemenza1983
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.
• 01-25-2008, 09:03 AM
Clemenza1983
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
Eranga
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
Clemenza1983
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
Eranga
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
Clemenza1983
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
DISPLAY TOTAL_STD_COUNT
9. ELSE
DISPLAY "NO_STD_RECORD_FOUND"

10. ENDIF

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

12. ENDIF

13. IF STD_NO < 1010 THEN
ELSE DISPLAY "ERROR"
• 01-25-2008, 10:57 AM
Eranga
Ste the following ling, 3. Initialize Total_Age = 0

Then,

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?
• 01-25-2008, 10:59 AM
Eranga
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
Clemenza1983
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
Clemenza1983
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
Eranga
Quote:

Originally Posted by Clemenza1983
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?
• 01-25-2008, 11:11 AM
Clemenza1983
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
Eranga
Here is much simpler way I can come across with your question.

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
Clemenza1983
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
Clemenza1983
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
Eranga
Quote:

Originally Posted by Clemenza1983
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. ;)
• 01-25-2008, 11:23 AM
Eranga
Quote:

Originally Posted by Clemenza1983
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.
• 01-25-2008, 05:49 PM
Clemenza1983
Thank You very much Eranga you the man!!!
Hope to become a good programmer someday hehe
• 01-26-2008, 06:23 AM
Eranga
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
Show 40 post(s) from this thread on one page
Page 1 of 2 12 Last