Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: help creating a virtual Object

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default help creating a virtual Object

    I'm stuck on how to get started on this part of my assignment. These are my instructions.
    The next class that you need to create will be what I call a Virtual Object. It is an object that we are creating so that we can store data in a concise and thoughtful manner. The only thing we want to do here is store data for easy access and referencing from other classes.

    Class Name: Student
    Default Constructor Should do nothing
    Overridden Constructor Should create a student with a name and all 10 grades

    Global Variables:
    strStudentName
    dblAssignmentOne
    dblAssignmentTwo
    dblAssignmentThree
    dblAssignmentFour
    dblAssignmentFive
    dblAssignmentSix
    dblAssignmentSeven
    dblAssignmentEight
    dblAssignmentNine
    dblAssignmentTen

    Methods: Each global variable should have an accessor (getter) and a mutator (setter).
    I posted a sample peice. Is this what it is asking for? or am I way off?
    public class student{
     
    public String getStudentName(String strStudentName){
    return strStudentName;
    }
    pubic String setStudentName(String strStudentName){
    this.strStudentName = strStudentName;
    }
    public String getdblAssignmentOne(double dblAssignmentOne){
    return dblAssignmentOne;
    }
    pubic String setdblAssignmentOne(double dblAssignmentOne){
    this.dblAssignmentOne = dblAssignmentOne;
    }


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: help creating a virtual Object

    you're not way off, but slightly.

    A getter is meant to "get" data. It doesn't require any input parameters, and should return the value in question.

    An example getter:

    public class A
    {
        private String foo;
     
        public String getFoo()
        {
            return foo;
        }
    }

    By the same token, a setter "sets" data fields. It takes in input parameter(s) and modifies internal fields appropriately. A typical setter modifies one field exclusively. Almost always these methods do not return any values.

    An example setter:

    public class A
    {
        private String foo;
     
        public void setFoo(String value)
        {
            foo = value;
        }
    }
    Last edited by helloworld922; March 12th, 2012 at 12:40 AM.

Similar Threads

  1. Creating object everytime object is called
    By aandcmedia in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 12th, 2012, 04:18 PM
  2. Creating and implementing class for creating a calendar object
    By kumalh in forum Object Oriented Programming
    Replies: 3
    Last Post: July 29th, 2011, 08:40 AM
  3. Using a string when creating an object.
    By ZeroLRS in forum Object Oriented Programming
    Replies: 10
    Last Post: July 13th, 2011, 09:22 PM
  4. Creating an object...
    By RodePope4546 in forum Object Oriented Programming
    Replies: 6
    Last Post: June 27th, 2011, 06:44 AM
  5. Creating Servlet object
    By tcstcs in forum Java Servlet
    Replies: 3
    Last Post: May 9th, 2011, 02:13 AM