Java programing, just learning

Discussion in 'OT Technology' started by purebad, Sep 8, 2006.

  1. purebad

    purebad I don't need your approval, right?

    Joined:
    Aug 25, 2006
    Messages:
    4,376
    Likes Received:
    0
    Location:
    Smyrna, GA
    Well, for my database class I need to write a progam that preforms something a database does quite easily. I need to cross reference two files of data, one has a roll of students and thier ID numbers, the other file has a list of all courses taken by each ID number, I need to return a list of student names alphebetically who took class X.

    This is truely my first time programming in java, figures they teach c++ for the first 3 years then expect you to know java all the sudden. Since I am not familiar with java or any nifty functions it might have, I wanted some opinions on if the way I'm thinking about this is the hard way. I was just going to read the roll file putting each student into the java equivalent of an array of structs(holding the student info, and a flag field for having taken class X) I will also just do alphabetizing then. Next I will check the class list and each time I find a line with class X, I will mark the flag in the array element with the matching student ID. Once I'm done, just print all elements of the array with the flag set. Any comments?
     
  2. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
    a) structs don't exist in java, they are all objects (or in C++ terms, instances of a class)
    b) nice thing about arrays is there is a built in sort method which is an enhanced version of quick sort.
    c) I don't think your array idea will work because 1 student can take multiple classes. Seems better to make objects for each class, then have the students reference the objects they take....but it's late and I'm just now learning Java also so what do I know. :)
     
  3. YodaHart

    YodaHart New Member

    Joined:
    Jul 7, 2006
    Messages:
    605
    Likes Received:
    0
    Your solution seems good. In case you haven't been there already, use the API on the sun site: http://java.sun.com/j2se/1.4.2/docs/api/
    I use it as my "guide book" to the Java language. It has the API for all the built in Java objects.

    To help with sorting, you can use the Comparable interface. Here is a code example from the program I used to sort my DVD list.

     
  4. purebad

    purebad I don't need your approval, right?

    Joined:
    Aug 25, 2006
    Messages:
    4,376
    Likes Received:
    0
    Location:
    Smyrna, GA
    in java, is there a way yo break up a string by the positioning, similar to a an aray of chars in C, where I could extrapolate the characters in position 0-3 put it in one string, then 4-5 and put them in another, etc. ?

    or another solution would be to simply read 3 chars in from the input, then read the next 2, etc.

    any comments on either methods in java?
     
  5. GOGZILLA

    GOGZILLA Double-Uranium Member

    Joined:
    Jan 16, 2003
    Messages:
    10,760
    Likes Received:
    3
    Location:
    Plantation, FL
    make a student class that has a vector of classes they have taken in it. then in your main program make a vector of students. That student class should have a class search function in it to search through their vector of classes.
     
  6. YodaHart

    YodaHart New Member

    Joined:
    Jul 7, 2006
    Messages:
    605
    Likes Received:
    0
    You could use substring. If the elements are seperated by spaces, you could easily do it with a StringTokenizer.
     
  7. YodaHart

    YodaHart New Member

    Joined:
    Jul 7, 2006
    Messages:
    605
    Likes Received:
    0
    ahhh...a true answer from a C++ programmer, no doubt :bigthumb:
     
  8. GOGZILLA

    GOGZILLA Double-Uranium Member

    Joined:
    Jan 16, 2003
    Messages:
    10,760
    Likes Received:
    3
    Location:
    Plantation, FL
    yes sir :h5:
     
  9. tyrionlannister

    tyrionlannister New Member

    Joined:
    Jun 13, 2006
    Messages:
    710
    Likes Received:
    0
    Location:
    New York

Share This Page