12-29打印病历单(函数的继承)

Medical.java
public class Medical {

	private String name;
	private boolean eType;
	private boolean nType;
	private double price;
	private int dTime;
	private int num;
	private boolean lOrB;
	
	public Medical(String name,boolean eType,boolean nType,double price,int dTime,int num,boolean lOrB){
		this.name=name;
		this.eType=eType;
		this.nType=nType;
		this.price=price;
		this.dTime=dTime;
		this.num=num;
		this.lOrB=lOrB;
	}
	
	public String getInfo(){
		String eStr="外用";
		String nStr="中药";
		if(eType){
			eStr="内服";
		}
		if(nType){
			nStr="西药";
		}
		return "\n名          称:"+name+
		       "\n服用类型:"+eStr+
		       "\n品种类型:"+nStr+
		       "\n单          价:"+price+
		       "\n服用方案:"+eMethod()+
		       "\n-------------------------------";
	}
	
	public String eMethod(){
		String eMStr="粒";
		if(lOrB){
			eMStr="包";
		}
		return "一日"+dTime+"次,每次"+num+eMStr;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean iseType() {
		return eType;
	}

	public void seteType(boolean eType) {
		this.eType = eType;
	}

	public boolean isnType() {
		return nType;
	}

	public void setnType(boolean nType) {
		this.nType = nType;
	}

	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public int getdTime() {
		return dTime;
	}

	public void setdTime(int dTime) {
		this.dTime = dTime;
	}

	public int getNum() {
		return num;
	}

	public void setNum(int num) {
		this.num = num;
	}

	public boolean islOrB() {
		return lOrB;
	}

	public void setlOrB(boolean lOrB) {
		this.lOrB = lOrB;
	}
	
	
}

 

CHistory.java

import java.util.GregorianCalendar;
public class CHistory {
	
	private String name;
	private int age;
	private boolean sex;
	private String tOffice;
	private GregorianCalendar gc;
	private Medical[] medical;
	
	public CHistory(String name,int age,boolean sex,String tOffice,GregorianCalendar gc,Medical[] medical){
		this.name=name;
		this.age=age;
		this.sex=sex;
		this.tOffice=tOffice;
		this.gc=gc;
		this.medical=medical;
	}
	
	public String getInfo(){
		String str="女";
		if(sex){
			str="男";
		}
		return "姓          名:"+name+
		       "\n年          龄:"+age+
		       "\n性          别:"+str+
		       "\n科          室:"+tOffice+
		       "\n病历建立时间:"+gc.getTime().toLocaleString()+
		       "\n所用药品:"+
		       "\n==============================="+
		       uMedical();
		       
	}
	
	public String uMedical(){
		String uStr="";
		for(int i=0;i<medical.length;i++){
			uStr+=medical[i].getInfo();
		}
		return uStr;
	}
	
	public double uPrice(){
		double uDou=0;
		for(int i=0;i<medical.length;i++){
			uDou+=medical[i].getPrice();
		}
		return uDou;
	}

}


Ophthalmology.java

import java.util.GregorianCalendar;

public class Ophthalmology extends CHistory{
	
	private double oDPrice;

	public Ophthalmology(String name, int age, boolean sex, String tOffice,
			GregorianCalendar gc, Medical[] medical,double oDPrice) {
		super(name, age, sex, tOffice, gc, medical);
		// TODO Auto-generated constructor stub
		this.oDPrice=oDPrice;
	}
	
	public String getInfo(){
		return super.getInfo()+
		             "\n眼科门诊费用:"+oDPrice+
		             "\n眼科治疗费用:"+oPrice()+
	                 "\n*******************************";
	}
	
	public double oPrice(){
		return oDPrice+super.uPrice();
	}

	public double getoDPrice() {
		return oDPrice;
	}

	public void setoDPrice(double oDPrice) {
		this.oDPrice = oDPrice;
	}
	
	

}

 

Surgery.java

import java.util.GregorianCalendar;

public class Surgery extends CHistory{

	private double sDPrice;
	private double oPrice;
	
	public Surgery(String name, int age, boolean sex, String tOffice,
			GregorianCalendar gc, Medical[] medical,double sDPrice,double oPrice) {
		super(name, age, sex, tOffice, gc, medical);
		// TODO Auto-generated constructor stub
		this.sDPrice=sDPrice;
		this.oPrice=oPrice;
	}
	
	public String getInfo(){
		return super.getInfo()+
		             "\n外科门诊费用:"+sDPrice+
		             "\n手术          费用:"+oPrice+
		             "\n外科治疗费用:"+sPrice()+
		             "\n*******************************";
	}
	
	public double sPrice(){
		return super.uPrice()+sDPrice+oPrice;
	}

	public double getsDPrice() {
		return sDPrice;
	}

	public void setsDPrice(double sDPrice) {
		this.sDPrice = sDPrice;
	}

	public double getoPrice() {
		return oPrice;
	}

	public void setoPrice(double oPrice) {
		this.oPrice = oPrice;
	}
	
	

}

 

Test.java

package P1229;

import java.util.GregorianCalendar;

public class Test {

 /**   * @param args   */  public static void main(String[] args) {   // TODO Auto-generated method stub

  Medical[] mc1={new Medical("白加黑",true,true,20.0,3,2,true),new Medical("白加黑",true,true,20.0,3,2,true)};   Ophthalmology op=new Ophthalmology("赵四",22,true,"眼科",new GregorianCalendar(2012,12,28),mc1,500);      Medical[] mc2={new Medical("感康",true,true,20.0,2,1,false),new Medical("感康",true,true,20.0,3,1,false)};   Surgery sg=new Surgery("刘能",22,true,"眼科",new GregorianCalendar(2012,12,28),mc2,500,200);      CHistory[] cs=new CHistory[2];   cs[0]=op;   cs[1]=sg;      for(int i=0;i<cs.length;i++){    System.out.println(cs[i].getInfo());   }     }

}

12-29打印病历单(函数的继承)

 

 

你可能感兴趣的:(等闲识却,打印病历单,函数的继承)