Advertisement
fosterbl

Name.java

Dec 3rd, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. public class Name{// Class Header - Names the class
  2.  
  3.    //Instance Variables - Data associated with each name
  4.    private String name, gender;
  5.    private int frequency;
  6.    
  7.    //Parameterized Constructor - Creates a name with given information
  8.    public Name(String n, String g, int f){
  9.       name = n;
  10.       gender = g;
  11.       frequency = f;
  12.    }
  13.    
  14.    //Accessor Methods - Allows us to see values of private instance variables outside of class
  15.    public String getName(){
  16.       return name;
  17.    }
  18.    
  19.    public String getGender(){
  20.       return gender;
  21.    }
  22.    
  23.    public int getFrequency(){
  24.       return frequency;
  25.    }
  26.    
  27.    //toString Method - Returns a textual representation of each Name object
  28.    public String toString(){
  29.       return name + ", " + gender + ", " + frequency;
  30.    }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement