當前位置:首頁 » 招生排名 » 浙江大學java實驗題答案

浙江大學java實驗題答案

發布時間: 2021-02-09 10:40:49

⑴ Java實驗題

public class Complex{
private int x;
private int y;
public Complex(){
this.x = 0;
this.y=0;
}
public int getX(){
return this.x;
}
public int getY(){
return this.y;
}
public Complex(int x,int y){
this.x = x;
this.y = y;
}

public void showComp(){
System.out.println(x+""+y+"i");
}
public Complex addComp(Complex C1,Complex C2){
return new Complex(C1.getX() + C2.getX(), C1.getY() + C2.getY());
}

public Complex subComp(Complex C1,Complex C2){
return new Complex(C1.getX() - C2.getX(), C1.getY() - C2.getY());
}

// 乘和除類似

public static void main(String[] args){
//獲得測試用例的參數x,y
//獲得方法,我不清楚你說的意思,我自定義一個,不是的話自己修改下
int x1=1;
int y1=2;
int x2 =5;
int y2=9;
Complex a1 = new Complex(x1,y1);
Complex a2 = new Complex(x2,y2);

Complex result1 = addComp(a1,a2);
showComp(result1);

Complex result2 = subComp(a1,a2);
showComp(result2);

//乘法除法類似
}
}

⑵ java實驗題

代碼如下:

//一次貼6個還不給分啊,只能幫你到這了
publicclassCourse{
//4個屬性
privateStringname;
privateStringdate;
privateStringteacherName;
privateinttime;

publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicStringgetDate(){
returndate;
}
publicvoidsetDate(Stringdate){
this.date=date;
}
publicStringgetTeacherName(){
returnteacherName;
}
publicvoidsetTeacherName(StringteacherName){
this.teacherName=teacherName;
}
publicintgetTime(){
returntime;
}
publicvoidsetTime(inttime){
this.time=time;
}

//兩個構造方法
publicCourse(){
super();
}
publicCourse(Stringname,Stringdate,StringteacherName,inttime){
super();
this.name=name;
this.date=date;
this.teacherName=teacherName;
this.time=time;
}

publicvoidoutput(){
System.out.println("課程名稱:"+name);
System.out.println("上課時間:"+date);
System.out.println("任課教師:"+teacherName);
System.out.println("實驗次數:"+time);
}

publicvoidedit(Stringdate){
System.out.println("上課時間調為:"+date);
this.date=date;
}
}
publicclassTest{

publicstaticvoidmain(String[]args){
Coursec1=newCourse("語文","8:00-8:45","張三",2);
Coursec2=newCourse("數學","10:00-10:45","李四",5);
c1.output();
c1.edit("9:15-9:50");
System.out.println();
c2.output();
}

}

輸出如下:

⑶ 求一份Java實訓題目的代碼答案!!!急!!!!!

我的空間有一些學生信息管理系統的論文```不知道你用不用得上````無論怎麼樣~~~也許對你有些幫助吧~~~別忘了幫我踩哈空間```

⑷ 求一個java實驗題,急急急

寫一個定時任務,每十抄秒生成一個隨機數,列印,同時插入到資料庫中,同時插入當前時間,每一分鍾從資料庫中按插入時間倒序查詢十條記錄,計算平均值,返回列印。參考代碼如下:
Timer timer = new Timer();
timer.schele(new TimerTask(){
int n = 0;

int[] m = new int[10];
@Override
public void run(){
int i = (int)(15+Math.random()*10);
System.out.println("第"+(n+1)+"次溫度為:"+i);
m[n] = i;
n++;
int sum = 0;
if(n == 10){
n = 0;
for(int k : m){
sum+=k;
}
System.out.println("平均值:"+sum/10);
}
}
},2000,10*1000);
我將溫度存放在數組中,計算平均值,這塊你需要存放到資料庫中,代碼僅供參考

熱點內容
現讀大學生 發布:2025-06-07 06:10:28 瀏覽:408
挪威大學考研 發布:2025-06-07 06:10:26 瀏覽:371
福建師范大學好的專業 發布:2025-06-07 06:10:26 瀏覽:845
中國政法大學研究生導師名師 發布:2025-06-07 06:06:32 瀏覽:642
山西大學研究生院2016錄取名單 發布:2025-06-07 05:58:15 瀏覽:999
長安大學的考研專業 發布:2025-06-07 05:53:25 瀏覽:60
章子怡大學老師叫什麼關系 發布:2025-06-07 05:20:25 瀏覽:439
2016美國大學生數學建模競賽 發布:2025-06-07 05:07:55 瀏覽:786
編程在大學是什麼專業 發布:2025-06-07 05:06:36 瀏覽:103
中南大學地理信息科學考研科目 發布:2025-06-07 05:01:28 瀏覽:472