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 3 of 3

Thread: Accesor and Mutator help

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Accesor and Mutator help

    public class StudentRecord{
        private String name;
        private String address;
        private int age;
        private double mathGrade;
        private double englishGrade;
        private double scienceGrade;
        private double average;
        private static int studentCount;
     
     
        public String getName(){
            studentCount++;
            return name;
     
        }
     
        public void setName( String name ){
           this.name = name;
        }
     
     
        public void setMathGrade( double mathGrade ){
           this.mathGrade= mathGrade;
        }
     
        public void setEnglishGrade( double englishGrade ){
           this.englishGrade= englishGrade;
        }
     
        public void setScienceGrade( double scienceGrade ){
           this.scienceGrade= scienceGrade;
        }
     
        public double getAverage(){
            double result = 0;
            result = ( mathGrade+englishGrade+scienceGrade )/3;
            return result;
        }
     
        public static int getStudentCount(){
            return studentCount;
        }
    }
     
     
    [COLOR="Red"]// Provide the necessary accessor and mutator methods for all the attributes.[/COLOR]

    @red... what does this mean??


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Accesor and Mutator help


  3. #3
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Accesor and Mutator help

    Ok, so Accessor Methods are methods that allow you to access the Class Variables or whatever. And Mutator Methods are methods that allow you to change variables.

    So, in your code above, you have several Class Variables:
    private String name;
        private String address;
        private int age;
        private double mathGrade;
        private double englishGrade;
        private double scienceGrade;
        private double average;
        private static int studentCount;

    And you have several methods made for you.
    These methods are Accessor Methods:
    public String getName(){
            studentCount++;
            return name;
     
        }
     public double getAverage(){
            double result = 0;
            result = ( mathGrade+englishGrade+scienceGrade )/3;
            return result;
        }
     
        public static int getStudentCount(){
            return studentCount;
        }

    And these methods are Mutator Methods:
    public void setName( String name ){
           this.name = name;
        }
     
     
        public void setMathGrade( double mathGrade ){
           this.mathGrade= mathGrade;
        }
     
        public void setEnglishGrade( double englishGrade ){
           this.englishGrade= englishGrade;
        }
     
        public void setScienceGrade( double scienceGrade ){
           this.scienceGrade= scienceGrade;
        }

    Do you understand that?

    So, you still need to create the Accessor and Mutator methods for the variables that do not have either or one. You should have a total of at least 16 methods when you are done (if I understand your assignment). 8 Accessor methods for each variable (or attribute) and 8 Mutator methods for each variable (or attribute).
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Similar Threads

  1. What is the matching mutator method?
    By ssmith in forum Object Oriented Programming
    Replies: 1
    Last Post: November 3rd, 2009, 10:03 PM