求一个JAVA程序,用eclipse编写,全分送上

要求如下,求牛逼大大们帮帮忙,可以的全部分送上,多谢多谢,在线等CreateaJavaprogramthathastheseclasses:1.Name,whichhas... 要求如下,求牛逼大大们帮帮忙,可以的全部分送上,多谢多谢,在线等
Create a Java program that has these classes:

1. Name, which has fields:
- String lastname
- String firstname
2. Address, which has fields:
- int stnum
- String street
- String city
- String postalCode
3. PatientRecord, which has fields:
- int patientID
- Name patName
- Address patAddr
4. Patients, which has fields:
- int numPatients
- PatientRecord[] patRecords
5. Hospital, which has fields:
- String hospitalName
- Address hospitalAddr
- Patients patientRecs

The main routine, in class MainClass, MUST look like this:
public static void main(String[] args){
Hospital hosp = new Hospital();
hosp.readIn();
System.out.printf("hosp=%s",hosp.toString());
}//main

which creates an instance of class Hospital,
then calls the readIn() function of that Hospital object which will:
1. read in the hospitalName, by calling hospitalName.readIn()
2. read in the hospitalAddr, by calling hospitalAddr.readIn()
3. read in the patRecords, by calling patientRecs.readIn() which
reads in the number of PatientRecord objects and
creates the array of PatientRecord objects.
Then, PatientRecs.readIn() calls readIn() on each
Patient record in array PatientRecords, which will
in turn read in the PatientID,
and call PatientName.readIn(), and PatientAddr.readIn()
After calling hosp.readIn(), main will print out all of
the contents of the hospital object pointed to by printing
hosp.toString().
展开
 我来答
kejiaweiren
2011-02-06 · TA获得超过6740个赞
知道大有可为答主
回答量:1774
采纳率:0%
帮助的人:3353万
展开全部
这里主要用到了重写toString,和构造函数方便初始化。
下面是所有代码
class Name {
String lastname;
String firstname;
public Name(String lastname, String firstname) {
this.lastname = lastname;
this.firstname = firstname;
}
public Name() {
}
public String toString() {
return "Name: lastname:\t"+lastname+"\tfirstname:"+firstname+"\n";
}
}

class Address {
int stnum;
String street;
String city;
String postalCode;
public Address(int stnum, String street, String city, String postalCode) {
this.stnum = stnum;
this.street = street;
this.city = city;
this.postalCode = postalCode;
}
public Address() {
}
public String toString() {
return "Address: stnum:\t"+stnum+"\tstreet:"+street+"\tcity:"+city+"\tpostalCode:"+postalCode+"\n";
}
}

class PatientRecord {
int patientID;
Name patName;
Address patAddr;
public PatientRecord(int patientID, Name patName, Address patAddr) {
this.patientID = patientID;
this.patName = patName;
this.patAddr = patAddr;
}
public PatientRecord() {
}
public String toString() {
return "PatientRecord: patientID:\t"+patientID+"\tpatName:"+patName+"\tpatAddr:"+patAddr+"\n";
}
}

class Patients {
int numPatients;
PatientRecord[] patRecords;
public Patients(int numPatients, PatientRecord[] patRecords) {
this.numPatients = numPatients;
this.patRecords = patRecords;
}
public Patients() {
}
public String toString() {
String arr="";
for (int i = 0; i < patRecords.length; i++) {
arr+="patRecords["+(i+1)+"]"+patRecords[i];
}
return "Patients:\nnumPatients:"+numPatients+"\npatRecords:\n"+arr+"\n";
}
}

class Hospital {
String hospitalName;
Address hospitalAddr;
Patients patientRecs;
void readIn(){
System.out.println("hospitalName:"+hospitalName+"\nhospitalAddr:"+ hospitalAddr+patientRecs);
}
public Hospital(String hospitalName, Address hospitalAddr,
Patients patientRecs) {
this.hospitalName = hospitalName;
this.hospitalAddr = hospitalAddr;
this.patientRecs = patientRecs;
}
public Hospital() {
}
}

public class Test {
public static void main(String[] args) {
Hospital hosp = new Hospital(
"hospital1",new Address(100,"streethos","sh","200000"),
new Patients(20,
new PatientRecord[]{
new PatientRecord(1,new Name("zhang","san"),new Address(10,"street1","sh","200001")),
new PatientRecord(1,new Name("li","si"),new Address(20,"street2","bj","200002"))
}
)
);
hosp.readIn();
// System.out.printf("hosp=%s", hosp.toString());
}// main
}
qfyh05
2011-02-06 · TA获得超过507个赞
知道小有建树答主
回答量:325
采纳率:50%
帮助的人:365万
展开全部
已经写好了,留学联系方式吧。我帮你写的是一个java项目,多个类文件。需要你就发个邮件给我吧。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式