扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
import java.util.Comparator;
我们提供的服务有:网站设计、网站制作、微信公众号开发、网站优化、网站认证、兴安盟ssl等。为近千家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的兴安盟网站制作公司
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.no o.no) return 1;
else if (this.no o.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);
studentList.add(s2);
studentList.add(s3);
studentList.add(s4);
Collections.sort(studentList);
System.out.println(Arrays.toString(studentList.toArray()));
}
}
public class Student {
private String id;
private String name;
private int age;
private String sex;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
public class StudentToDo {
/**
* 吃饭方法
*/
public void eat(Student student){
System.out.println("id"+student.getId()+"年龄为"+student.getAge()+"性别是"+student.getSex()+"姓名叫"+student.getName()+"的学生在吃饭");
}
/**
* 打豆豆方法
*/
public void play(Student student){
System.out.println("id"+student.getId()+"年龄为"+student.getAge()+"性别是"+student.getSex()+"姓名叫"+student.getName()+"的学生在打豆豆");
}
}
public class Test {
public static void main(String[] args) {
StudentToDo studentToDo = new StudentToDo();
Student student = new Student();
student.setId("1");
student.setAge(15);
student.setName("张三");
student.setSex("男");
studentToDo.eat(student);
studentToDo.play(student);
}
}
1:
package wo;
-
public class StudentText{
public static void main(String[] args) {
Student s1=new Student(01,"张三");
Student s2=new Student(02,"李四");
boolean b=s1.equals(s2);
System.out.println(b);
}
}
class Student {
private int num;
private String nema;
public Student(int num, String nema) {
super();
this.num = num;
this.nema = nema;
}
public Student() {
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getNema() {
return nema;
}
public void setNema(String nema) {
this.nema = nema;
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
if (num != this.num)
return false;
return true;
}
}
2
package wo;
public class polyTest {
public static void main(String[] args) {
penson p=new penson("张三",25);
System.out.println(p);
loyee l=new loyee(01,3000);
System.out.println(l);
Manager m=new Manager("老师");
System.out.println(m);
}
}
class penson{
private String name;
private int age;
public penson() {
super();
}
public penson(String name,int age) {
super();
this.name=name;
this.age=age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String toString() {
return "penson [姓名:" + name + ",年龄:" + age + "]";
}
}
class loyee{
private int id;
private double salary;
public loyee() {
super();
}
public loyee(int id,double salary) {
super();
}
public int getID() {
return id;
}
public void setID(int iD) {
id = iD;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public String toString() {
return "loyee [工号" + id + ", 工资:" + salary + "]";
}
}
class Manager{
private String type;
public Manager() {
super();
}
public Manager(String type) {
super();
this.type=type;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String toString() {
return "Manager [职务名称:" + type + "]";}
}
import java.util.concurrent.atomic.AtomicInteger;
public class CStudent {
/**
* 姓名
*/
private String name;
/**
* 性别
*/
private String gender;
/**
* 年龄
*/
private Integer age;
/**
* 学号
*/
private String studentNo;
/**
* 学生数量
*/
private static AtomicInteger studentNum = new AtomicInteger(0);
public CStudent() {
studentNum.incrementAndGet();
}
/**
* 获取学生数量
* @return
*/
public static int getStudentNum() {
return studentNum.intValue();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getStudentNo() {
return studentNo;
}
public void setStudentNo(String studentNo) {
this.studentNo = studentNo;
}
@Override
public String toString() {
return "CStudent [name=" + name + ", gender=" + gender + ", age=" + age + ", studentNo=" + studentNo + "]";
}
}
其他的相对简单,就不写了
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流