|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

01-02-2008, 06:21 PM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 12
|
|
|
Just a Few Questions
I'd just like to find out the answers to my questions that so far I haven't been able to find.
For example:
1)I'm creating a menu based program. The users need to press '1' to initialise the 'contact detail list' i'm creating. As the program is made up of four separate arrays, would that mean setting the active entry counter to zero separately for all the arrays? E.g.
String [] Peter = new String [firstName];
int active entries = 0;
2)Also, I have code that goes as follows:
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 ("Another message");
What I don't understand about this is that my program is called 'StudentContactManager' (which is what I was told to call it). Also, due to the fact that the program is made up of four arrays each with different names, how does the above code work i.e. if contact detail list contains entries.
3) Due to the fact that i'm using arrays with a fixed size, is it possible to 'insert new contact details into contact detail list' as i'm told to do?
4)The biggest problem i've had is to do with insertion points. I assume that where it says 'set insertion point of new entry to first entry' it means i = 0;. But i'm totally lost when it comes to the stage where it says:
IF Enrolment number is greater than enrolment number in last entry THEN
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 know it probably looks like I want someone else to do my work for me, but i've been on numerous forums asking for explanations, i've got books that don't cover what I need, i've asked friends who are like me and don't have a clue and so this is my last chance for some pointers - either that or a fail!!
|
|

01-02-2008, 10:52 PM
|
 |
Senior Member
|
|
Join Date: Nov 2007
Location: New York
Posts: 143
|
|
|
i wasn't exactly sure what you were asking for some of the questions, but for number 3, reguarding array size, i've run into this issue before, so what i did was, i first created an ArrayList<Integer> in order to first get all of the nums, and then once you have all the numbers in that ArrayList, you can just make a new int array whose size is the size of the arraylist (arraylistname.size()).
Hope that helps a bit.
|
|

01-02-2008, 11:07 PM
|
 |
Senior Member
|
|
Join Date: Dec 2007
Location: South Africa
Posts: 334
|
|
Hello
I think your instructor wants you to us arrays instead of more advanced data structures, like the one gibsonrocker800 mentioned, since your pseudo code said:
IF Enrolment number is greater than enrolment number in last entry THEN
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
Insert new contact detail at insertion point over-writing any previous contact
detail entry
END
I would use integer variables used for counting purposes and a few for loops.
__________________
If your ship has not come in yet then build a lighthouse.
|
|

01-02-2008, 11:27 PM
|
 |
Senior Member
|
|
Join Date: Nov 2007
Location: New York
Posts: 143
|
|
|
hm, well tim i think maybe he HAS to use arrays (maybe the teacher wants to teach the students the use of arrays). if so, do you know how else could he update the size of the array without using an ArrayList like i mentioned? (i would like to know for my own programs).
|
|

01-02-2008, 11:32 PM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 12
|
|
Yes we were told to use basic arrays due to us being beginners at Java.
The first question I asked about active entries - basically if the user looks at the menu and presses '1', the Contact Detail List will be initialised. Now as the program is made up of four separate arrays,does this mean that I have to write out the four arrays and write 'int active entries = 0; beneath all of the four arrays or only write it once underneath the last array written?
The second question is about my confusion arising from the provided pseudocode. We are to call our program 'StudentContactManager'. In the following piece of pseudocode, it keeps mentioning 'contact detail list':
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
As i've said, the program is made up of four arrays, with each array holding separate information on ten students. As I name my arrays differently, i.e. firstName, lastName - why does it say for example 'display contact detail list'
Hopefully that helps 
|
|

01-02-2008, 11:33 PM
|
 |
Senior Member
|
|
Join Date: Dec 2007
Location: South Africa
Posts: 334
|
|
Well, gibsonrocker800, I like to use Vector objects. They are very easy to handle, especially if you use generics. Vectors update their size automatically, and they really have great functionality. Vector objects can make pringle's or any other programmer's task fairly straightforward.  Look in the java.util package.
__________________
If your ship has not come in yet then build a lighthouse.
|
|

01-02-2008, 11:45 PM
|
 |
Senior Member
|
|
Join Date: Nov 2007
Location: New York
Posts: 143
|
|
|
ah, i'll be sure to check out Vectors (i'm learning alot today =]).
pringle: first of all, if you're having trouble with the menu of the program, you could use a switch statement for the choices. so:
Scanner in = new Scanner(System.in);
System.out.print("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");
int choice = in.nextInt();
switch(choice)
{
case 1: {code for option 1 and the line: break;}
case 2: {code for option 2 and the line: break;}
etc.
}
___________________________________________
You may have already known how to do this. But there it is, either way.
So now, the arrays should be written in the beginning of the programming so that it is within the scope of each case in the switch statement. (AKA, within the range).
As for your second question, it has that option so that the user can see all of the contact details. So, within case 1, you will have it print out all of the details using a for each loop. (or you could use a for loop, but for each is more efficient when dealing with all of the elements in an array). so:
-----------------------------
for(String str: arrayName)
{
System.out.println(str);
}
--------------------------
In this code, i am assuming that the arrays are arrays of Strings (because you said these arrays hold the information on the person).
So yeah, i hope this helps you out. If anything is unclear, just ask, i'll be here =]
|
|

01-02-2008, 11:47 PM
|
 |
Senior Member
|
|
Join Date: Dec 2007
Location: South Africa
Posts: 334
|
|
Originally Posted by pringle
Yes we were told to use basic arrays due to us being beginners at Java.
The first question I asked about active entries - basically if the user looks at the menu and presses '1', the Contact Detail List will be initialised. Now as the program is made up of four separate arrays,does this mean that I have to write out the four arrays and write 'int active entries = 0; beneath all of the four arrays or only write it once underneath the last array written?
The second question is about my confusion arising from the provided pseudocode. We are to call our program 'StudentContactManager'. In the following piece of pseudocode, it keeps mentioning 'contact detail list':
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
As i've said, the program is made up of four arrays, with each array holding separate information on ten students. As I name my arrays differently, i.e. firstName, lastName - why does it say for example 'display contact detail list'
Hopefully that helps 
Okay, I'll try and help you.
I did a similar thing at varsity. It appears to me that you must create a method that does the correct action depending on what the user enters, so you will need five methods. I would have another method that displays the menu.
Menu option 1:
Initialize the arrays by using the new keyword and choose an integer limit on the size of your data structure. Now, set the active entry counter to zero once, after you created the arrays.
firstName = new String[100];
lastName = new String[100];
entryCounter = 0;
Menu option 2:
gibsonrocker800 explained this part.
Menu options 3 to 5: These are algorithms and they should be on the internet.
__________________
If your ship has not come in yet then build a lighthouse.
Last edited by tim : 01-03-2008 at 12:00 AM.
|
|

01-03-2008, 12:08 AM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 12
|
|
|
We're not using a graphical user interface, we're using Oracle's JDeveloper . As for the arrays, four pieces of info are to be held on each student:
First name
Last name
Telephone Number
Enrolment Number
As for the menu, I have written:
Switch (userOption)
{
Case initialise: int activeEntries = 0;
Break;
etc. etc.
|
|

01-03-2008, 12:19 AM
|
 |
Senior Member
|
|
Join Date: Dec 2007
Location: South Africa
Posts: 334
|
|
Okay.
Lets say activeEntries is the number of entries in your list.
To display those entries, (and not the whole array as gibsonrocker800 explained) you must use a for loop:
public static void displayAll(){
for (int i = 0; i < activeEntries; i++){
System.out.println("First name: " + firstName[i]);
System.out.println("Last name: " + lastName[i]);
System.out.println("Telephone Number: " + telephoneNumber[i]);
System.out.println("Enrolment Number: " + enrolmentNumber[i]);
}
}
Do you follow?
__________________
If your ship has not come in yet then build a lighthouse.
|
|

01-03-2008, 12:22 AM
|
 |
Senior Member
|
|
Join Date: Nov 2007
Location: New York
Posts: 143
|
|
|
well pringle, there's a few things:
tim meant that, do you want your program to be a graphical user interface, meaning that should it have a window that pops up where you choose things by clicking on buttons and stuff like that, or do you want it to be completely text-driven (seen through the console, using Scanner and System.out.println in order to input and ouput). I personally think that you should just make it non-graphical, because making it graphical is a whole different topic, which is alot more advanced (you gotta learn about events, buttons, etc.). So, for now, lets get this working by using the console, and then, we'll try to make it graphical (you're teacher will be impressed =]).
also, keep in mind that switch statements can not run on Strings, as you did in your previous post:
"Case initialise:"
it would have to be : case 1 ... or case 2
switch statements can only rely on primitive types (i'm not completely positive if it can run on longs, shorts, doubles, and floats, but i know for a fact that it can work with ints, bytes, and chars).
What this all means is that, you could never have the following example:
---------------------------------------------
Scanner in = new Scanner(System.in);
System.out.print("Please enter your name");
String name = in.nextLine();
switch(name)
{
case Nick:
System.out.println("Hey Nick!");
break;
case John;
System.out.println("Hey John!");
break;
}
------------------------------------------------
This would yield a compile-time error.
|
|

01-03-2008, 12:38 AM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 12
|
|
|
Yes, no GUI involved just simple keyboard input.
Thanks for that reply Tim, I understand now.
Looks like I was trying to be clever for my own good when coding the switch statement!
|
|

01-03-2008, 10:57 AM
|
 |
Senior Member
|
|
Join Date: Dec 2007
Location: South Africa
Posts: 334
|
|
|
Hello, pringle.
You should be able to do options one and two. Do you need any more help?
__________________
If your ship has not come in yet then build a lighthouse.
|
|

01-05-2008, 12:56 AM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 12
|
|
|
I'm gunna look over it tommorow (Saturday) as i've been away these past two days, and so if I have any additional queries i'll ask them on here
Thanks again
|
|

01-06-2008, 04:41 PM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 12
|
|
|
Well i've attempted about three quarters of the pseudocode and wondered if somebody could check whether what i've done is correct. I'm willing to pay for your troubles.
|
|

01-07-2008, 01:40 AM
|
 |
Senior Member
|
|
Join Date: Nov 2007
Location: New York
Posts: 143
|
|
Originally Posted by pringle
Well i've attempted about three quarters of the pseudocode and wondered if somebody could check whether what i've done is correct. I'm willing to pay for your troubles.
Could you please post your code, i would like to check your code. And, i don't think anyone on this site would even consider taking money from anyone for checking their code; we do it out of pure love of the subject.
__________________
//Haha javac, can't see me now, can ya?
Last edited by gibsonrocker800 : 01-07-2008 at 01:42 AM.
|
|

01-07-2008, 04:12 PM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 12
|
|
|
Here is both the pseudocode and partial code for it. As I say, it probably isn't 100% correct but it's better to try rather than ignore it!
Pseudocode:
|
|

01-08-2008, 07:58 PM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 12
|
|
|
It's not looking good is it?
|
|

01-09-2008, 02:55 AM
|
 |
Senior Member
|
|
Join Date: Nov 2007
Location: New York
Posts: 143
|
|
|
Hey, i was going to respond in my AP Comp Science class, and i typed up a response and i accidentally hit "Go Advanced" instead of Post Quick Reply, and so my entire reply was gone lol. So, here is my reply:
Your syntax is a bit off. I can't remember exactly what you did, but i remember you had like if (x > 5 && x < 1) ... Now this would never evaluate to be true, because there's no way x could be greater than 5 AND less than 1. Use || (OR) instead.
Also, you've gotta remember that java keywords are supposed to be lowercase (like for, switch, if, etc.)
__________________
//Haha javac, can't see me now, can ya?
|
|

01-09-2008, 12:43 PM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 12
|
|
|
Hi,
It's because i've written the code in Microsoft Word so they automatically think that i'd like a capital at the start of every line! Well, I know that the array initialisations are wrong, my brackets are all over the place amongst other things so i'll alter them today to make the code a little more respectable!
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
| |