Omar_Natour

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

Nov 5th, 2016
114
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.  */
  8.  
  9. public class BabyName implements Comparable<BabyName> {
  10.  
  11.     private String name;
  12.     private char gender;
  13.     private int tally;
  14.  
  15.     public BabyName(String name, char gender, int tally) {
  16.         this.name = name;
  17.         this.gender = gender;
  18.         this.tally = tally;
  19.     }
  20.  
  21.     public String getName() {
  22.         return this.name;
  23.     }
  24.  
  25.     public int getTally() {
  26.         return this.tally;
  27.     }
  28.  
  29.     public BabyName combine(BabyName c) {
  30.         this.tally += c.tally;
  31.         return this;
  32.  
  33.     }
  34.  
  35.     public boolean equals(BabyName o) {
  36.         if (this.name == o.getName())
  37.             return true;
  38.         else if ((this.name).equals(o.getName()))
  39.             return true;
  40.         return false;
  41.     }
  42.  
  43.     @Override
  44.     public int compareTo(BabyName o) {
  45.  
  46.         return o.tally - this.tally;
  47.  
  48.     }
  49.  
  50.     public String toString() {
  51.         return (this.name + ", " + tally);
  52.     }
  53.  
  54. }
Add Comment
Please, Sign In to add comment