Results 1 to 16 of 16

Thread: Field type

  1. #1
    code_worm is offline Member
    Join Date
    Oct 2009
    Posts
    7
    Rep Power
    0

    Default Field type

    Hi guys please excuse my little knowledge of the java enviroment but i would like to know what is the best type to use if i was wanting to store a date of birth. I tried date, but i think it may also be a class

    Thanks in advance for your help and even viewing my thread

    CW :D

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    java.util.Date you mean?

  3. #3
    literallyjer is offline Member
    Join Date
    Oct 2009
    Posts
    25
    Rep Power
    0

    Default

    The Date object is perfect for storing a birthday! How has it been troubling you?

  4. #4
    hunterbdb is offline Member
    Join Date
    Oct 2008
    Posts
    48
    Rep Power
    0

    Default

    I usually use java.util.Long to store as a number. But then again, I do bottom - level stuff.

    java.util.Date is your best bet for an easy deal.

    Care to tell us more about what you're trying to do?

  5. #5
    code_worm is offline Member
    Join Date
    Oct 2009
    Posts
    7
    Rep Power
    0

    Default

    Hi thanks for the swift replies, well iam currently at universirty and this is the brief i was given. its just practice exercises so i can grasp the concepts of the java enviroment. I have managed to do everything but the date, i kept that out but realistically speakin family members can have the same address but less likely to have the same date of birth unless they are twins haha

    1. Download the person class which contains properties relating to a person.
    2. Add an additional property, or 2, to the Person class (so that a person is unique)
    3. Do you need to add a getter and setter method? Think carefully about whether you want to change this unique property!
    4. Make any appropriate changes to the toString method
    5. In the main method in Main, create an array of 4 Person(s) – and test that you can print them out.

    The main problem i am having is the array, i think i have implemented it correctly but iam not to sure how i would display it through the overridden tostring method as i am only used to displaying single propertys

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    You could just loop through all the contents of the array calling/printing toString on each element in there.

    Also have a look at the Arrays.toString method.

  7. #7
    code_worm is offline Member
    Join Date
    Oct 2009
    Posts
    7
    Rep Power
    0

    Default

    Right, i had a look at the arrays.tostring method and its sayin cannot find symbol arrays?

    I'm using netbeans latest release

  8. #8
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    1.) It's Arrays, java is case sensitive.
    2.) It's in the java.util package so you will need to import it.

  9. #9
    code_worm is offline Member
    Join Date
    Oct 2009
    Posts
    7
    Rep Power
    0

    Default

    oh right, thanks ur helpin alot
    i never imported the method
    you see how there is an arguement after the import statement what would that be
    imports java.util.Arrays.toString(arg0)

  10. #10
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Ah, that one is easy. That would be the array containing the objects that you want to print out.

    P.S You should try writing the loop and printing out manually first. Reserve the Arrays.toString trick for when you want to show off your Java skills.

  11. #11
    code_worm is offline Member
    Join Date
    Oct 2009
    Posts
    7
    Rep Power
    0

    Default

    Yeah i thought that was the needed parameter

    I have started doin another practice program, this one is about reading in mobile phones. I think the declaration of my import statement is in tghe wrong posistion would you mind having a look? What iam trying to do is fill the array and display it via the Arrays.toString method

    public class Main {



    public static void main(String[] args) {

    import java.util.Arrays.toString(p);

    PAYGMobilePhone [] p = new PAYGMobilePhone [3];
    p[0] = new PAYGMobilePhone("Nokia", "NGage", 155);
    p[1] = new PAYGMobilePhone("Samsung", "Leap", 165);
    p[2] = new PAYGMobilePhone("Nokia", "Enforcer", 245);
    p[3] = new PAYGMobilePhone("Nokia", "Pinky", 355);
    System.out.println(Arrays.toString(p));]

    I have 3 bugs
    1. illegal start of expression
    2. cannot find variable p
    3. cannot find variable Arrays

  12. #12
    steelshark is offline Member
    Join Date
    Aug 2009
    Posts
    25
    Rep Power
    0

    Default

    you're import method should not be in your constructor.
    import methods go here--
    public class Main {


    public static void main(String[] args) {

  13. #13
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    It's all a bit of a mess to be honest. I'd strongly recommend giving one of those tutorials a shot. Here are some of the things that are wrong.

    1.) You didn't use code tags when posting the code.
    2.) import statements must appear before class declarations.
    3.) If you want to import the Arrays class you would do

    Java Code:
    import java.util.Arrays;
    . You tried to import and use it at the same time. To do that, the correct syntax would be
    Java Code:
    java.util.Arrays.toString(p);
    .
    4.) You create an array of 3 elements but you try to add 4 elements. If you do get that code to compile it will not run because it's going to realize that it has nowhere to put your fourth element.

  14. #14
    code_worm is offline Member
    Join Date
    Oct 2009
    Posts
    7
    Rep Power
    0

    Default

    Yeah i know its a mess
    This is more or less one of the first programs i have written in java, i'm so aggrevated at the moment with the passover from college to university and getting thrown into a class with a higher degree of understanding i have just jumped straight into coding.
    Would you recomend a tutorial?
    Thanks btw

  15. #15
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    The Java™ Tutorials

    Download the whole thing to your computer.

  16. #16
    code_worm is offline Member
    Join Date
    Oct 2009
    Posts
    7
    Rep Power
    0

Similar Threads

  1. using instanceof to get Object type and parent type?
    By xcallmejudasx in forum New To Java
    Replies: 2
    Last Post: 11-06-2008, 07:24 PM
  2. [SOLVED] Cast string type to int type
    By GilaMonster in forum New To Java
    Replies: 9
    Last Post: 09-17-2008, 11:43 AM
  3. Regarding Text Field
    By adeeb in forum AWT / Swing
    Replies: 1
    Last Post: 06-06-2008, 12:01 AM
  4. Replies: 2
    Last Post: 04-28-2008, 11:26 AM
  5. FInal field cannot be assigned
    By ravian in forum New To Java
    Replies: 3
    Last Post: 12-13-2007, 03:26 PM

Posting Permissions

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