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

📄 prescription.java

📁 处方跟踪系统的开发
💻 JAVA
字号:
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
public class Prescription 
{	
	private int prescriptionId;
	private HashMap<String, Medicine> medicinesOffered; 
	private String doctorName;
	private String doctorPhone;
	private String startTime;
	private String endTime;
	private int usedTimes;
	private int ableTimes;
	
	//构造器
	public Prescription()
	{
	  this.setPrescriptionId(0);	  
	  this.setDoctorName("");
	  this.setStartTime("");
	  this.setEndTime("");
	  this.setUsedTimes(0);
	  this.setAbleTimes(5);

	  medicinesOffered=new HashMap<String,Medicine>();		 
	}
	public Prescription(int prescriptionId,String doctorName,String doctorPhone,String startTime,String endTime,int usedTimes,int ableTimes)
	{
	  this.setPrescriptionId(prescriptionId);	 
	  this.setDoctorName(doctorName);
	  this.setDoctorPhone(doctorPhone);
	  this.setStartTime(startTime);
	  this.setEndTime(endTime);
	  this.setUsedTimes(usedTimes);	 
	  this.setAbleTimes(ableTimes);
	  medicinesOffered=new HashMap<String,Medicine>();	
	}
	 //get()和set()方法
    public void setPrescriptionId(int prescriptionId)
	{
	   this.prescriptionId=prescriptionId;
	}
	public int getPrescriptionId()
	{
	   return this.prescriptionId;
	}	
   //doctorName的get()和set()方法
	public void setDoctorName(String doctorName)
	{
	   this.doctorName=doctorName;
	}
	public String getDoctorName()
	{
	   return this.doctorName;	
	}
	//doctorPhone的get()和set()方法
	public void setDoctorPhone(String doctorPhone)
	{
	   this.doctorPhone=doctorPhone;
	}
	public String getDoctorPhone()
	{
	   return this.doctorPhone;	
	}
	//startTime的get()和set()方法
	public void setStartTime(String startTime)
	{
	   this.startTime=startTime;
	}
	public String getStartTime()
	{
	   return this.startTime;	
	}
	//endTime的get()和set()方法
	public void setEndTime(String endTime)
	{
	   this.endTime=endTime;
	}
	public String getEndTime()
	{
	   return this.endTime;	
	}
	//usedTimes的get()和set()方法
	public void setUsedTimes(int usedTimes)
	{
	   this.usedTimes=usedTimes;
	}
	public int getUsedTimes()
	{
	   return this.usedTimes;	
	} 
	//ableTimes的get()和set()方法
	public void setAbleTimes(int ableTimes)
	{
	   this.ableTimes=ableTimes;
	}
	public int getAbleTimes()
	{
	   return this.ableTimes;	
	} 


	public HashMap<String, Medicine> getMedicinesOffered()
	{
        return medicinesOffered;
        }

	public void addMedicinesOffered(Medicine m)
	{ 
		if (!medicinesOffered.containsValue(m))
		{
	          String key=m.getMedicineId();
	           medicinesOffered.put(key,m);
		}		
	}
	public String toString()
	{
	    return this.getPrescriptionId()+"("+this.getDoctorName()+"\t"+
		this.getDoctorPhone()+"\t"+this.getStartTime()+"\t"+this.getEndTime()+"\t"+this.getUsedTimes()+"\t"+this.getAbleTimes()+")";
	}
	public void display()
	{
	  System.out.println("\tprescriptionId : "+this.getPrescriptionId());     
	  System.out.println("\tdoctorName : "+this.getDoctorName());
	  System.out.println("\tdoctorPhone : "+this.getDoctorPhone());
	  System.out.println("\tstartTime : "+this.getStartTime());
	  System.out.println("\tendTime : "+this.getEndTime());
	  System.out.println("\tusedTimes : "+this.getUsedTimes());	
	  System.out.println("\tableTimes :"+this.getAbleTimes());

	  for (Medicine m : medicinesOffered.values())
         {
            m.display();
            System.out.println();
        }
	  System.out.println("ableToUse : "+this.isAbleToUse());	
	}
	public boolean isAbleToUse()
	{
		boolean ableToUse=true;
	    SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); 
        Date today=new Date();
        String todayTime=sdf.format(today);
        
        DateFormat df = DateFormat.getDateTimeInstance();	   
	    try
		{
	      if(df.parse(endTime).before(df.parse(todayTime)));
	      ableToUse=false;
	    }
	    catch(ParseException e)
	    {
	    	System.out.print("[SYS] " + e.getMessage());
	    	ableToUse=true;	    	
	    }
		if(usedTimes>ableTimes)
		{
		  ableToUse=false;
		}
		return ableToUse;	
	}
}

⌨️ 快捷键说明

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