Results 1 to 6 of 6
  1. #1
    Emfy is offline Member
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

    Default Help needed, urgently!

    Please help me!

    I'm totally stuck on this lab:

    Lab 8
    This lab is slightly different to the previous ones you have
    completed, as no starter code will be provided. This will give you
    practice in creating a program from scratch (remember, you are free
    to use earlier lab code to help).
    Lab Aims
    In this lab you will practice creating a class, a test executable class,
    creating instances of the class (objects) and using static methods.
    Make use of the lecture slides on the course drive and use the code
    included in them as examples if necessary.
    Ex 1.
    For your first task, you must create a Person class that will be used
    to generate objects corresponding to real people (i.e. An object for
    every person you wish to represent in your program).
    Your Person class should hold the following information:
    First (given) Name
    Family Name
    Age
    Height (in metres)
    Each piece of information must be stored as a private variable
    (chose the best fitting primitive type for each one) in your class. As
    they are set to private, you must also provide the appropriate get
    and set methods for each variable.
    If you are feeling confident, add checks to the set methods to
    ensure that the age and height values are within an acceptable
    range.
    Ex 2.
    Now that you have created your class, you must next add a static
    variable and method. The (private) static variable will be called
    objectCount and should store the number of objects that have been
    created in the program at any time.
    As static variables and methods are associated with the class and
    not the objects that are created, there will only ever be one copy of
    our static variable objectCount. The static method you have to
    create should be called incObjectCount(). This method should
    increment the objectCount variable by 1 every time it is called.
    Once you have created this, add a constructor to your class. This
    constructor should call the incObjectCount() method. By calling
    this method in the constructor, the objectCount variable will be
    incremented each time a new object is created in your program.
    Ex 3.
    For the final part of this lab, you are now going to test the counter
    you added in the last exercise. Firstly, in order to view the value of
    objectCount you must add a second static method to your Person
    class called getObjectCount(). This method should simply return
    the value of objectCount to the calling method.
    Now to test that your class and its static methods work correctly,
    create a test class called personTest. This class should include a
    main method to allow execution of the project.
    Your main method should create several instances (objects) of your
    Person class and then display the value of objectCount with the
    line:
    System.out.println(“Number of objects created:
    “+Person.getObjectCount());


    This is my attempt at it:

    public class Person{



    private String firstName;

    private String familyName;

    private int age;

    private double height;


    public Person(){

    }


    public Person(String firstName, String familyName, int age, double height){

    this.firstName = firstName;
    this.familyName = familyName;
    this.age = age;
    this.height = height;

    }


    public String getFirstName(){
    return firstName;

    }


    public String getFamilyName(){
    return familyName;


    }


    public int getAge(){
    return age;


    }

    public double getHeight(){
    return height;

    }


    public void setFirstName(String firstName){

    this.firstName = firstName;
    }



    However, I'm terrible at java so would really appreciate some help!!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Again, as in your previous post (and please try not to create more than one thread per question) what is your specific question here? What part don't you understand? Again, the better your question, usually the better the help you'll receive. Again, good luck.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Also, when posting your code, please use code tags so that your code will retain its formatting and be readable. To do this, you will need to paste already formatted code into the forum, highlight this code, and then press the "code" button at the top of the forum Message editor prior to posting the message. You may want to click on the Preview tab to make sure that your code is formatted correctly. Another way is to place the tag [code] at the top of your block of code and the tag [/code] at the bottom, like so:

    Java Code:
    [code]
      // your code block goes here.
      // note the differences between the tag at the top vs the bottom.
    [/code]
    You'll find that if you do this, more folks will be willing to read your code, and that is precisely what you want: the more people who read your code, the better your chances that at least one of them will give you the help you need. Again, good luck.

  4. #4
    Emfy is offline Member
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

    Default

    hey, thanks.

    your gonna think i'm really stupid but i dont understand any of it. not one thing! hence why i need help lol

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Based on the homework instructions, I recommend that you try first on your own to create the static objectCount variable and static incObjectCount and getObjectCount methods, then post these attempts here.

    Let us know if your attempt compiles, or if not, what errors are thrown. Based on what you post here, we'll be better able to figure out exactly where you may need help. Who knows, you may even get it right on first try. The key is, don't give up!

    Again, good luck.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Emfy View Post
    hey, thanks.
    your gonna think i'm really stupid but i dont understand any of it. not one thing! hence why i need help lol
    You're not stupid, but it sounds like you're way behind in your studies. If that's the case, then I'm sorry to say, but I'm afraid that you are beyond the abilities of a mere forum to help you. You have really only one option here, and it doesn't involve the forum. You should get together with your teacher (or a local tutor) and arrange some face to face private tutorial sessions ASAP as this gives you your best hopes for learning the basics as quickly as possible. Without this foundation of basic programming knowledge you'll never progress in this course, so again, please don't delay.

    Again, good luck.
    Last edited by Fubarable; 12-27-2008 at 04:14 PM.

Similar Threads

  1. help needed!!! :S
    By mark-mlt in forum Networking
    Replies: 1
    Last Post: 04-14-2008, 10:27 AM
  2. Replies: 0
    Last Post: 03-12-2008, 03:23 PM
  3. please help urgently
    By ananas7777 in forum New To Java
    Replies: 1
    Last Post: 12-22-2007, 03:48 AM
  4. help needed.
    By dirtycash in forum New To Java
    Replies: 3
    Last Post: 12-03-2007, 10:17 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
  •