Keeping track of duplicate entries within a java class?

Status
Not open for further replies.

Druid

Fully Optimized
Messages
3,065
Resolved - needed "static"


How do I keep track of duplicate entries within this class?
Okay, so I am supposed to increment the dot number in email addresses (ex: miller.5021@osu.edu), but how can I do that without a hashmap in the main? I need to do it from this class. Help?
______________________________________…
import java.util.HashMap;

class EmailAccount {
private HashMap<String, Long> database = new HashMap<String, Long>();
private String name;
private String email;

public EmailAccount(String first, String last) {
this.name = first.concat(" " + last); // forms full name
long dotnumber = 1;

// finds the current amount with the same last name and increments
if (this.database.containsKey(last)) {
dotnumber = this.database.get(last);
dotnumber++;
System.out.println(dotnumber);
this.database.remove(last);
}
this.email = last.toLowerCase().concat("." + dotnumber + "@osu.edu"); // forms
// email
this.database.put(last, dotnumber); // puts last name back in database
System.out.println(this.database.get…
}

public String getName() {
return this.name;
}

public String getEmailAddress() {
return this.email;
}
}
 
Status
Not open for further replies.
Back
Top Bottom