Page 1 of 2 12 LastLast
Results 1 to 20 of 22
  1. #1
    pringle is offline Member
    Join Date
    Jan 2008
    Posts
    12
    Rep Power
    0

    Default 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!!

  2. #2
    gibsonrocker800's Avatar
    gibsonrocker800 is offline Senior Member
    Join Date
    Nov 2007
    Location
    New York
    Posts
    143
    Rep Power
    0

    Default

    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.

  3. #3
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Default

    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:
    Java Code:
    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
        [B]Move subsequent existing contact detail entries one position[/B]
    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.
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

  4. #4
    gibsonrocker800's Avatar
    gibsonrocker800 is offline Senior Member
    Join Date
    Nov 2007
    Location
    New York
    Posts
    143
    Rep Power
    0

    Default

    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).

  5. #5
    pringle is offline Member
    Join Date
    Jan 2008
    Posts
    12
    Rep Power
    0

    Default

    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 :o

  6. #6
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Default

    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. :D Look in the java.util package.
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

  7. #7
    gibsonrocker800's Avatar
    gibsonrocker800 is offline Senior Member
    Join Date
    Nov 2007
    Location
    New York
    Posts
    143
    Rep Power
    0

    Default

    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 =]

  8. #8
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Wink

    Quote Originally Posted by pringle View Post
    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 :o
    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.
    Java Code:
    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.
    Last edited by tim; 01-03-2008 at 12:00 AM.
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

  9. #9
    pringle is offline Member
    Join Date
    Jan 2008
    Posts
    12
    Rep Power
    0

    Default

    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.

  10. #10
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Default

    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:

    Java Code:
    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?
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

  11. #11
    gibsonrocker800's Avatar
    gibsonrocker800 is offline Senior Member
    Join Date
    Nov 2007
    Location
    New York
    Posts
    143
    Rep Power
    0

    Default

    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.

  12. #12
    pringle is offline Member
    Join Date
    Jan 2008
    Posts
    12
    Rep Power
    0

    Default

    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!

  13. #13
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Default

    Hello, pringle.

    You should be able to do options one and two. Do you need any more help?
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

  14. #14
    pringle is offline Member
    Join Date
    Jan 2008
    Posts
    12
    Rep Power
    0

    Default

    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

  15. #15
    pringle is offline Member
    Join Date
    Jan 2008
    Posts
    12
    Rep Power
    0

    Default

    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.

  16. #16
    gibsonrocker800's Avatar
    gibsonrocker800 is offline Senior Member
    Join Date
    Nov 2007
    Location
    New York
    Posts
    143
    Rep Power
    0

    Default

    Quote Originally Posted by pringle View Post
    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.
    Last edited by gibsonrocker800; 01-07-2008 at 01:42 AM.

  17. #17
    pringle is offline Member
    Join Date
    Jan 2008
    Posts
    12
    Rep Power
    0

    Default

    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:
    Attached Files Attached Files

  18. #18
    pringle is offline Member
    Join Date
    Jan 2008
    Posts
    12
    Rep Power
    0

    Default

    It's not looking good is it?

  19. #19
    gibsonrocker800's Avatar
    gibsonrocker800 is offline Senior Member
    Join Date
    Nov 2007
    Location
    New York
    Posts
    143
    Rep Power
    0

    Default

    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.)

  20. #20
    pringle is offline Member
    Join Date
    Jan 2008
    Posts
    12
    Rep Power
    0

    Default

    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!

Page 1 of 2 12 LastLast

Similar Threads

  1. Stuck on Two Questions, Please Help
    By sylo18 in forum New To Java
    Replies: 5
    Last Post: 03-11-2008, 02:03 AM
  2. 2 simple java questions
    By jimJohnson in forum New To Java
    Replies: 2
    Last Post: 02-02-2008, 10:35 AM
  3. questions
    By Gilgamesh in forum New To Java
    Replies: 3
    Last Post: 11-28-2007, 12:18 AM
  4. 3 Questions
    By hiranya in forum AWT / Swing
    Replies: 4
    Last Post: 11-14-2007, 05:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •