基本JAVA实验题及代码(3)

2019-02-16 00:43

}

}

this.stuScore = stuScore;

public int hashCode() { }

return Integer.parseInt(this.stuNo);

public boolean equals(Object obj) { }

@Override

public String toString() { }

protected Object clone() throws CloneNotSupportedException { }

Student stu=(Student)(super.clone()); stu.stuScore=this.stuScore; return stu;

String strTemp = this.stuNo+\+this.stuName+\+this.stuSex+\;

for(int i=0;i

return strTemp;

strTemp+=this.stuScore[i].getCourseScore()+\;

if(this.stuNo== (String) obj ) { }

return true;

return false;

测试类:

package com.stu.info;

public class Test {

/**

* @param args

11

*/

public static void main(String[] args) throws CloneNotSupportedException {

// TODO Auto-generated method stub Score sc=new Score(\,\英语1\,80); Score sc1=new Score(\,\英语1\,87); Score sc2=new Score(\,\英语1\,90); Score sc3=new Score(\,\英语1\,81);

Score[] score=new Score[4]; score[0]=sc; score[1]=sc1; score[2]=sc2; score[3]=sc3;

Student stu=new Student(\,\张三\,\男\,score);

stu.setStuScore(score);

System.out.println(\该对象的学号是:\+stu.hashCode());

if(stu.equals(\)) { } else { }

Student stu1=(Student)stu.clone();

System.out.println(\克隆对象后的学号是:\+stu1.hashCode());

Score sco=new Score(\,\英语1\,90); Score sco1=new Score(\,\英语1\,97); Score sco2=new Score(\,\英语1\,100); Score sco3=new Score(\,\英语1\,91);

Score[] score1=new Score[4]; score1[0]=sco; score1[1]=sco1; score1[2]=sco2; score1[3]=sco3;

stu1.setStuScore(score1);

System.out.println(\与 对象学号: \+stu.getStuNo()+\不同啦\); System.out.println(\与 对象学号:\+stu.getStuNo()+\相同啦\);

12

}

}

System.out.println(stu.toString()); System.out.println(stu1.toString()); System.out.println(stu.toString());

程序结果:

八、掌握Java如何实现多线程程序的设计,Java中实现多线程的方法

参考书本多线程的代码,设计具有以下功能的程序 ? 总共有1000张火车票

? 有四个售票点来销售(用四个线程来模拟实现)

? 当线程销售出去一张票时,显示线程销售的提示信息

(一)public class DuoThreah implements Runnable {

@Override

public void run() {

// TODO Auto-generated method stub int nonSharedValue = 100; nonSharedValue += 100;

System.out.println(\+ nonSharedValue); } /**

* @param args */

public static void main(String[] args) { }

// TODO Auto-generated method stub DuoThreah ts = new DuoThreah(); Thread t1 = new Thread(ts); Thread t2 = new Thread(ts); t1.start(); t2.start();

13

}

(二)、

public class DuoThreah implements Runnable { }

/**

* @param args */

public static void main(String[] args) { }

// TODO Auto-generated method stub DuoThreah ts = new DuoThreah(); Thread t1 = new Thread(ts); Thread t2 = new Thread(ts); t1.start(); t2.start(); int SharedValue=100; @Override

public void run() {

// TODO Auto-generated method stub

SharedValue += 100;

System.out.println(\+ SharedValue); }

(三)、

public class DuoThreah implements Runnable {

int SharedValue=0; @Override

public void run() {

// TODO Auto-generated method stub SharedValue += 1;

14

}

System.out.println(\卖出票数为:\+ SharedValue+\张\); } /**

* @param args */

public static void main(String[] args) { }

// TODO Auto-generated method stub DuoThreah ts = new DuoThreah(); Thread t1 = new Thread(ts); Thread t2 = new Thread(ts); Thread t3 = new Thread(ts); Thread t4 = new Thread(ts); t1.start(); t2.start(); t3.start(); t4.start();

(四)、

public class DuoThreah implements Runnable {

int SharedValue=0; int SurplusValue=1000; @Override

public void run() { {

SharedValue +=1; SurplusValue -= 1;

System.out.println(\卖出票数为:\+ SharedValue+\张\+\+\剩余票数为:\+ } }

// TODO Auto-generated method stub

while(SurplusValue!=0)

SurplusValue+\张\+\);

15


基本JAVA实验题及代码(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:事故隐患排查治理体系实施指南

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: