• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array? Arraylist?  RSS feed

 
Gary Jennings
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Gary Jennings
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Hendy Setyo Mulyo
Ranch Hand
Posts: 219
Firefox Browser Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gary Jennings
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Pat Farrell
Rancher
Posts: 4686
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!