Forums Register Login

Array? Arraylist?

+Pie Number of slices to send: Send
I have an annoying problem. We have been given some pseudocode to work with to create a contact detail list, made up of four arrays (one holding first name, one holding last name, one holding phone number and one holding an enrolment number). Separate arrays are used due to us being beginners at Java.
Here is the code we have been given:

Contact detail manager

BEGIN
Input valid user option
WHILE user option not exit
DO
CASE user option OF
1: Initialise contact detail list
2: Display contact details list
3: Insert new entry into contact detail list
4: Delete entry from contact detail list
5: Search contact detail list
END-CASE
Input valid user option
END-WHILE
END

Input valid user option

BEGIN
Display menu;
Input user option
WHILE user option invalid
Display �User option invalid� message
Display menu
Input user option
END-WHILE
END

Initialise contact detail list

BEGIN
Initialise active entry counter to zero
//No need to initialise/reset individual entries
END

Display contact details list

BEGIN
IF contact detail list contains entries
THEN
Display �Contact detail list heading�
FOR each stored contact
DO
Display one/current contact detail
END-FOR
ELSE
Display �Contact detail list empty� message
END-IF
END

Insert new entry into contact detail list

BEGIN
IF contact detail list is not full
THEN
Input enrolment number
Search contact detail list to determine if enrolment number exists
IF enrolment number does not exist
THEN
Input first name
Input last name
Input telephone number
Insert new contact details into contact detail list
Increment active entry count
ELSE
Display �Enrolment number already exists� message
END-IF
ELSE
Display �Contact detail list full� message
END-IF
END

Delete entry from contact detail list

BEGIN
To be designed by student and submitted with final submission
END

Search contact detail list

BEGIN
IF contact detail list contains entries
THEN
Input enrolment number
Search contact detail list to determine if enrolment number exists
IF enrolment number exists
THEN
Display �Contact detail� message
ELSE
Display �Enrolment number unknown� message
END-IF

ELSE
Display �Contact detail list empty� message
END-IF

END

Insert new contact details into contact detail list

BEGIN
IF contact detail list is empty
THEN
Set insertion point of new entry to first entry
ELSE
IF Enrolment number is greater than enrolment number in last entryTHEN
Set insertion point of new entry to entry after current last entry
ELSE
Locate insertion point of new contact detail
Move subsequent existing contact detail entries one position
END-IF
END-IF
Insert new contact detail at insertion point over-writing any previous contact
detail entry
END

Locate insertion point of new contact detail

BEGIN
Set insertion point identifier to first position
WHILE enrolment number to insert is greater than enrolment number stored at
position identified by insertion point identifier
DO
Increment insertion point identifier
END-WHILE
END

I'm having trouble understanding whether I should use an arraylist, like i've been told or an array.
I don't expect other people to do the work for me but i've included the pseudocode just to make things clearer.

Thanks
+Pie Number of slices to send: Send
Just to clarify, the main part i'm stuck on is where I need to be able to add new contact details into the contact detail list and where I need to be able to locate the insertion point of a new contact detail.
I feel like giving up at the moment because i've looked in the notes from uni and other websites and books but i'm still no clearer!
+Pie Number of slices to send: Send
Actually, the decision is up to you. If you require any limit size for the contact details then nothing wrong using array. But if you want flexibility and easiness operation such as insertion and deletion of the elements, then ArrayList is the best choice.
+Pie Number of slices to send: Send
Hi there,

I'll use the 'standard' array in that case. Where it says 'set insertion point of new entry to first entry' is that just saying 'i = 0;'? That's all I can guess at!
+Pie Number of slices to send: Send
I don't see why you want to use the standard language arrays. They work fine, but if you want to insert a new value in the middle, you have to shuffle all the other values up, check for overflow, etc.

You might want to consider using a linked list, it handles adding stuff in the middle, and removing stuff from the middle automagically for you
+Pie Number of slices to send: Send
 


Originally posted by Gary Jennings:
I don't expect other people to do the work for me but i've included the pseudocode just to make things clearer.



Point to be well appreciated!

As Pat Farrell suggested, you can go for LinkedList if it is NOT way too far for you in the beginner's level. But looking at the pseudo code you have typed, the linked list will make your job easy.

Still, if you just want to get your hands dirty, you can go for the other alternatives!

Good luck
Hoo hoo hoo! Looks like we got a live one! Here, wave this tiny ad at it:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1299 times.
Similar Threads
Need help with assignment - Mini telephone book program please
Method Hash
linked list help!
cannot resolve symbol error
Address Book Java Issues
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:35:49.