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

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

这里主要用到了重写toString,和构造函数方便初始化。

下面是所有代码

class Name {

String lastname;

String firstname;

public Name(String lastname, String firstname) {

thislastname = lastname;

thisfirstname = 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) {

thisstnum = stnum;

thisstreet = street;

thiscity = city;

thispostalCode = 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) {

thispatientID = patientID;

thispatName = patName;

thispatAddr = 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) {

thisnumPatients = numPatients;

thispatRecords = patRecords;

}

public Patients() {

}

public String toString() {

String arr="";

for (int i = 0; i < patRecordslength; 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(){

Systemoutprintln("hospitalName:"+hospitalName+"\nhospitalAddr:"+ hospitalAddr+patientRecs);

}

public Hospital(String hospitalName, Address hospitalAddr,

Patients patientRecs) {

thishospitalName = hospitalName;

thishospitalAddr = hospitalAddr;

thispatientRecs = 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"))

}

)

);

hospreadIn();

// Systemoutprintf("hosp=%s", hosptoString());

}// main

}

抛砖引玉一下

我觉得该题描述了3个事物

1 小球 Ball

2 放小球的容器 BallPanel

3 小球的控制器 BallControler

public class Ball{

double R = 0d; //球的半径

int cx;//当前小球中心X坐标

int cy;//当前小球中心Y坐标

double angle;//小球运动弧度 ,与cx,cy结合起来用来算出 小球移动到当前时的前一个坐标,及移动到下一个点的坐标

int speed;//小球运动速度,毫秒数

}

public class BallPanel{

double width;//放小球的容器宽

double height;//放小球的容器的高

BallControler []BallControlers;//放了多少个小球

}

public class BallControler extends Thread{

Ball tBall;//该控制器控制的小球

BallControler(Ball tBall){

thistBall = tBall;

}

private int [] getNextPosition(){

/

返回下一点的x,y坐标

/

}

private int [] getPreviousPosition(){

/

返回前一点的x,y坐标

/

}

private void moveBall(int x,int y){

//移动小球到指定的x,y坐标。

//有必要的话,可以记录小球的运动轨迹到堆栈中

}

public void run(){

Threadsleep(tBallspeed);//按照小球规定的速度移动

//下面的代码,计算并且移动小球到下一个点,计算是否碰壁(当前小球中心坐标+半径是否超过BallPanel的长,或者高等),并且移动小球

}

}

以上就是关于求一个JAVA程序,用eclipse编写,全分送上全部的内容,包括:求一个JAVA程序,用eclipse编写,全分送上、用Eclipse写Java程序、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zz/9588500.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-29
下一篇2023-04-29

发表评论

登录后才能评论

评论列表(0条)

    保存