java程序设计考试题,求大神发eclipse软件做的全程截图,急急急!!!

 我来答
匿名用户
2015-12-30
展开全部
我可以有偿代做
更多追问追答
追问
多少钱
我要截图,因为我在考试
新叶给力
2015-12-30 · TA获得超过323个赞
知道小有建树答主
回答量:258
采纳率:50%
帮助的人:65.1万
展开全部
//第一问
public class Student3 {
private String num;
private String name;
private int chinese;
private int math;
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getChinese() {
return chinese;
}
public void setChinese(int chinese) {
this.chinese = chinese;
}
public int getMath() {
return math;
}
public void setMath(int math) {
this.math = math;
}
@Override
public String toString() {
return "Student3 [num=" + num + ", name=" + name + ", chinese=" + chinese + ", math=" + math + "]";
}
public Student3(String num, String name, int chinese, int math) {
super();
this.num = num;
this.name = name;
this.chinese = chinese;
this.math = math;
}
public Student3() {
super();
}

}

 所有代码


import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Student3 implements Serializable{
/**
 * 
 */
private static final long serialVersionUID = 1L;
private String num;
private String name;
private int chinese;
private int math;
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getChinese() {
return chinese;
}
public void setChinese(int chinese) {
this.chinese = chinese;
}
public int getMath() {
return math;
}
public void setMath(int math) {
this.math = math;
}
@Override
public String toString() {
return "Student3 [num=" + num + ", name=" + name + ", chinese=" + chinese + ", math=" + math + "]";
}
public Student3(String num, String name, int chinese, int math) {
super();
this.num = num;
this.name = name;
this.chinese = chinese;
this.math = math;
}
public Student3() {
super();
}
public static void writeObjectToFile(List<Student3> obj)
{
    File file =new File("date.txt");
    FileOutputStream out;
    try {
        out = new FileOutputStream(file);
        ObjectOutputStream objOut=new ObjectOutputStream(out);
        objOut.writeObject(obj);
        objOut.flush();
        objOut.close();
        System.out.println("write object success!");
    } catch (IOException e) {
        System.out.println("write object failed");
        e.printStackTrace();
    }
}

public static Object readObjectFromFile()
{
    Object temp=null;
    File file =new File("date.txt");
    FileInputStream in;
    try {
        in = new FileInputStream(file);
        ObjectInputStream objIn=new ObjectInputStream(in);
        temp=objIn.readObject();
        objIn.close();
        System.out.println("read object success!");
    } catch (IOException e) {
        System.out.println("read object failed");
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    return temp;
}
 public static void main(String[] args) {
 List<Student3> list = new ArrayList<Student3>();
  Student3 student3 = new Student3();
  Student3 student1 = new Student3();
  Student3 student2 = new Student3();
student3.setChinese(60);
student3.setMath(100);
student3.setName("张三");
student3.setNum("201102");
student2.setChinese(70);
student2.setMath(90);
student2.setName("李四");
student2.setNum("201103");
student1.setChinese(80);
student1.setMath(90);
student1.setName("王五");
student1.setNum("201105");
list.add(student3);
list.add(student2);
list.add(student1);

 writeObjectToFile(list);

 Student3 student33 = new Student3();
  Student3 student11 = new Student3();
  Student3 student22 = new Student3();
  List<Student3> list2 = new ArrayList<Student3>();
  list2=(List<Student3>)readObjectFromFile();
student11=list2.get(0);
student22=list2.get(1); student33=list2.get(2);

   System.out.println(student11.getName()+"的平均成绩为"+(student11.getChinese()+student11.getMath())/2);
   
   System.out.println(student22.getName()+"的平均成绩为"+(student22.getChinese()+student22.getMath())/2);
   System.out.println(student33.getName()+"的平均成绩为"+(student33.getChinese()+student33.getMath())/2);
}
}

 

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式