java程序代码设计 java基础程序代码编写( 三 )


Java语言的输入/输出处理机制和方法 , 常用的输入/输出方法,输入/输出处理的应用;
Java语言的图形用户界面设计:AWT界面设计的基本方法,常用的组件类库,图形用户界面的事件处理模型和方法,JFC介绍 , Swing图形界面设计;Java Applet程序设计,Applet程序的特点,运行机制,与浏览器的集成,安全机制的使用;
多线程程序设计,进程和线程的联系和区别,多线程程序设计的一般方法,线程的生命周期,线程状态的控制,多线程的互斥和同步;Java语言的网络编程技术和应用,Socket程序设计,Client/Server程序设计;Java的Servlet和JSP(Java?Server?Page)技术;
JavaBeans和RMI 。
java程序设计,求代码 1.定义学生类,学生类有学号,姓名 , 语文成绩,数学成绩的属性和有参的构造import java.util.Comparator;
public class Student implements ComparableStudent {
private int no;
private String name;
private String sex;
private int roomNo;
private double score;
public Student(int no, String name, String sex, int roomNo, double score) {
this.no = no;
this.name = name;
this.sex = sex;
this.roomNo = roomNo;
this.score = score;
}
public Student(int no, String name, String sex, double score) {
this.no = no;
this.name = name;
this.sex = sex;
this.score = score;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getRoomNo() {
return roomNo;
}
public void setRoomNo(int roomNo) {
this.roomNo = roomNo;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
@Override
public int compareTo(Student o) {
if (this.noo.no) return 1;
else if (this.noo.no) return -1;
else return 0;
}
@Override
public String toString() {
return "Student{" +
"no=" + no +
", name='" + name + '\'' +
", sex='" + sex + '\'' +
", roomNo=" + roomNo +
", score=" + score +
'}';
}
}
//性别比较器类
class SexComparator implements ComparatorStudent {
@Override
public int compare(Student o1, Student o2) {
if (o1.getSex().compareTo(o2.getSex())0) return 1;
else if (o1.getSex().compareTo(o2.getSex())0) return -1;
else return 0;
}
}
//寝室号比较器类
class RoomNoComparator implements ComparatorStudent {
@Override
public int compare(Student o1, Student o2) {
if (o1.getRoomNo()o2.getRoomNo()) return 1;
else if (o1.getRoomNo()o2.getRoomNo()) return -1;
else return 0;
}
}
//入学成绩比较器类
class ScoreComparator implements ComparatorStudent {
@Override
public int compare(Student o1, Student o2) {
if (o1.getScore()o2.getScore()) return 1;
else if (o1.getScore()o2.getScore()) return -1;
else return 0;
}
}
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class TestStudent {
public static void main(String[] args) {
Student s1 = new Student(1, "jack", "boy", 90);
Student s2 = new Student(5, "jack", "boy", 90);
Student s3 = new Student(4, "jack", "boy", 90);
Student s4 = new Student(2, "jack", "boy", 90);
ListStudent studentList=new ArrayList();
studentList.add(s1);

推荐阅读