⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mailtest.java

📁 这是一个邮件系统
💻 JAVA
字号:
import java.sql.Date;

class Mail  {
    String title;
    Date   time;
    String sender;
    String content;
    Mail   nextMail;   //单向链表的每个结点
    
    Mail()
    {
        this.title="nihao";
        this.time =new Date(2006-4-5);
        this.sender="li";
        this.content="how are you";
        this.nextMail=null;
    }
    
    Mail(String ti,Date t,String sen,String con)
    {
     this.title=ti;
     this.time =t;
     this.sender=sen;
     this.content=con;
     this.nextMail=null;
    }
    public String toString()
    {
    	return title+" "+time+" "+sender+" "+content+"\n";
    }
}


class MailBox{
 Mail   mails;    //这个是Mail的头
 
void deleteMail1(String title)  //按照题目删除
{

    Mail p, pre;
     pre = null;
     p = mails;
     while (p!= null && !p.title.equals(title))
     {
         pre = p;
         p = p.nextMail;
     }
     if (p == null)
         return;
     else {
         if (pre == null)
          mails = mails.nextMail;
         else 
          pre.nextMail = p.nextMail;
         
 
     }

}

void deleteMail2(String sender) //按照发送人删除
{
     Mail p, pre;
     pre = null;
     p = mails;
     while (p!= null && !p.sender.equals(sender))
     {
         pre = p;
         p = p.nextMail;
     }
     if (p == null)
         return;
     else {
         if (pre == null)
          mails = mails.nextMail;
         else 
          pre.nextMail = p.nextMail;    
     }
}
 
void deleteMail3(Date d)      //按照时间删除
{

	    Mail p, pre;
           pre = null;
           p = mails;
     while (p!= null && !p.time.equals(d))
     {
         pre = p;
         p = p.nextMail;
     }
     if (p == null)
         return;
     else {
         if (pre == null)
          mails = mails.nextMail;
         else 
          pre.nextMail = p.nextMail;
         
 
     }
} 
   
void deleteMail(Mail amail)   //把一个Mail删除
{
	     Mail p, pre;
     pre = null;
     p = mails;
     while (p!= null && !p.title.equals(t))
     {
         pre = p;
         p = p.nextMail;
     }
     if (p == null)
         return;
     else {
         if (pre == null)
          mails = mails.nextMail;
         else 
          pre.nextMail = p.nextMail;
         
 
     }
}

void addMail(Mail amail)    //添加邮件
{ 
 Mail t1;
 t1=mails;
 if (mails == null)
	 mails = amail;
 else {
   while (t1.nextMail!=null)
   {
     t1=t1.nextMail;
   }
   t1.nextMail=amail;
 }
}


void addMailAtHead(Mail amail)
{
   amail.nextMail = mails;
   mails = amail;

}
public String toString()
{
	String returnS ="";
	Mail t1;
	t1=mails;
	 if (mails == null)
		return "";
	 else {
	   while (t1 !=null)
	   {
	     returnS += t1.toString();
	     t1 =t1.nextMail;
	   }
	   return returnS;
	 }
}
}


public class mailtest {

	public static void main(String[] args) {
    
	Mail a=new Mail("hello",new Date(2006,5,1),"wang","hello java");
	Mail a1=new Mail("good",new Date(2006,12,12),"cheng","good evening");
	MailBox m=new MailBox();
	m.addMail(a);
	m.addMail(a1);
	System.out.println(m);
	m.deleteMail1("hello");
	System.out.println();
	System.out.println();
	System.out.println(m);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -