Omar_Natour

Natour, O. 11/4/16 Csc-220 BabyNameObject

Nov 5th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. /*
  2.  * Omar Natour
  3.  * 11/4/2016
  4.  * Csc-220 Data Structures
  5.  * Hw 6 Baby names
  6.  * Create a program that orders and combines the amount of baby names from a database
  7.  * Ojnatour0001@studnet.stcc.edu
  8.  */
  9.  
  10. public class BabyName implements Comparable<BabyName> {
  11.  
  12.     private String name;
  13.     private char gender;
  14.     private int tally;
  15.  
  16.     public BabyName(String name, char gender, int tally) {
  17.         this.name = name;
  18.         this.gender = gender;
  19.         this.tally = tally;
  20.     }
  21.  
  22.     public String getName() {
  23.         return this.name;
  24.     }
  25.  
  26.     public int getTally() {
  27.         return this.tally;
  28.     }
  29.  
  30.     public BabyName combine(BabyName c) {
  31.         this.tally += c.tally;
  32.         return this;
  33.  
  34.     }
  35.  
  36.     public boolean equals(BabyName o) {
  37.         if (this.name == o.getName())
  38.             return true;
  39.         else if ((this.name).equals(o.getName()))
  40.             return true;
  41.         return false;
  42.     }
  43.  
  44.     @Override
  45.     public int compareTo(BabyName o) {
  46.  
  47.         return o.tally - this.tally;
  48.  
  49.     }
  50.  
  51.     public String toString() {
  52.         return (this.name + ", " + tally);
  53.     }
  54.  
  55. }
Add Comment
Please, Sign In to add comment