first commit

This commit is contained in:
Jose Caban
2025-06-07 01:59:34 -04:00
commit 388ac241f0
3558 changed files with 9116289 additions and 0 deletions

191
CS1322/p3/MailBox.java Normal file
View File

@@ -0,0 +1,191 @@
/**
* <PRE>
* MailBox.java
*
* Revisions: 1.0 Oct. 01, 2002
* Created the MailBox class
* 1.1 Oct. 05, 2002
* Compiled, Finished, Commented
*
* </PRE>
*
* Collaboration Statement:
* I worked on the homework assignment alone, using only
* course materials.
*
* Created with JCreatorLE, some indents are off when viewed through notepad
* or EMACS
*
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
* @version Version 1.1, Oct. 05, 2002
*/
import java.util.Vector;
import java.util.Enumeration;
public class MailBox implements P3Type{
public static final boolean bDebug = false; //there's nothing to debug
//that bDebug can handle
private String strLName;
private String strFName;
private Vector vMail;
////////////////
//Constructors//
////////////////
/**
*Constructor for MailBox
*@param last the value for strLName
*@param first the value for strFName
*/
public MailBox(String last, String first){
strLName = last;
strFName = first;
vMail = new Vector();
}
///////////////////////
//Accessors/Modifiers//
///////////////////////
/**
*Modifier for strLName
*@param strLName the value to set this.strLName
*/
public void setStrLName(String strLName){
this.strLName = strLName;
}
/**
*Accessor for strLName
*@return the value of strLName
*/
public String getStrLName(){
return strLName;
}
/**
*Modifier for strFName
*@param strFName the value to set this.strFName
*/
public void setStrFName(String strFName){
this.strFName = strFName;
}
/**
*Accessor for strFName
*@return the value of strFName
*/
public String getStrFName(){
return strFName;
}
///////////
//Methods//
///////////
/**
*Adds mail to the persons box
*@param mail, the mail to be added
*/
public void addMail(Mail mail){
vMail.add(mail);
}
/**
*clear vector and return enumeration of all mail
*@return an enumeration of the mail a person has
*/
public Enumeration getMail(){
Vector vTemp = (Vector)vMail.clone();
Enumeration enum = vTemp.elements();
vMail.clear();
return enum;
}
/**
*toString() override
*@return the amount of mail the person has as a string
*/
public String toString(){
return (getStrFName() + " " + getStrLName() + " has " + vMail.size() +
" piece" + (vMail.size()==1?"":"s") +
/*I used ==1 because when its 0 it should be pieces not piece*/
" of mail.");
}
/**
*@return true if both Mailboxes are owned by the same person
*/
public boolean equals(Object obj){
if(!(obj instanceof MailBox)){
return false;
}
MailBox temp = (MailBox)obj;
if(!(this.getStrFName().equals(temp.getStrFName()))){
return false;
}
if(!(this.getStrLName().equals(temp.getStrLName()))){
return false;
}
return true;
}
/*******************************************************/
/**
* Debugging main for class MailBox.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args) {
MailBox box1 = new MailBox("Romero" , "John");
MailBox box2 = new MailBox("Carmack" , "John");
MailBox box3 = new MailBox("Sweeney" , "Tim" );
//just for reference
//Mail(String strMessage, String strFrom, String strTo)
//
Mail mail1 = new Mail("Don't Screw up Doom3","Gamers","John Carmack");
Mail mail2 = new Mail("Man you screwed up Daikatana","The World","Romero");
Mail spammail;
spammail=new Mail("Buy out product!!!!!","Crappy Company","MailBox owner");
box1.addMail(mail2);
box2.addMail(mail1);
box3.addMail(spammail);
System.out.println(box1);
box1 = new MailBox("Carmack","John");
System.out.println(box1.equals(box2));
box2.addMail(spammail);
box2.addMail(new Mail("This sucks","Me","you"));
System.out.println(box2);
Enumeration e = box2.getMail();
System.out.println("\nStart Elements\n");
while(e.hasMoreElements()){
System.out.println(e.nextElement());
}
System.out.println();
System.out.println(box2.equals(box3));
}// end of main(String[] args)
}// end of class MailBox