重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
全部代码已发送你的邮箱。
10年积累的网站设计制作、成都网站设计经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站制作后付款的网站建设流程,更有东洲免费网站建设让你可以放心的选择与我们合作。
以下是部分代码。
package zhidao;
import java.util.Scanner;
public class Main {
//从控制台读入信息
private Scanner scanner = new Scanner(System.in);
private StudentService ss = new StudentService();
public static void main(String[] args) {
Main main = new Main();
main.startService();
}
public void startService(){
System.out.println("欢迎使用宿舍管理系统");
//加载之前的舍友信息
ss.getFromFile();
while(true){
System.out.println("1,添加室友信息\t2,显示所有室友信息\t3,按姓名查找室友\t4,保存室友信息到文件\t5,调入舍友\t6,调离舍友\t7,退出");
System.out.print("请选择:");
int choose = Integer.parseInt(scanner.nextLine());
switch (choose) {
case 1:
this.addRoomMates();
break;
case 2:
ss.printRoomMates();
break;
case 3:
this.findRoomMatesByName();
break;
case 4:
ss.saveToFile();
break;
case 5:
this.addRoomMates();
break;
case 6:
this.removeRoomMatesBySno();
break;
case 7:
System.out.println("info -- 感谢使用,再见!");
System.exit(0);
break;
default:
System.out.println("info -- 无此项,请重新选择!");
break;
}
}
}
/**
* 调离舍友
*/
private void removeRoomMatesBySno() {
while(true){
System.out.println("1,调离舍友\t2,退到上一层");
System.out.print("请选择:");
int choose = Integer.parseInt(scanner.nextLine());
switch (choose) {
case 1:
remove();
break;
case 2:
return;
default:
System.out.println("info -- 无此项,请重新选择!");
}
}
}
/**
* 调离
*/
private void remove() {
System.out.print("请输入学号:");
String sno = scanner.nextLine();
ss.removeRoomMatesBySno(sno);
}
/**
* 按姓名查找
*/
private void findRoomMatesByName() {
while(true){
System.out.println("1,查找\t2,退到上一层");
System.out.print("请选择:");
int choose = Integer.parseInt(scanner.nextLine());
switch (choose) {
case 1:
check();
break;
case 2:
return;
default:
System.out.println("info -- 无此项,请重新选择!");
}
}
}
/**
* 查找
*/
private void check() {
System.out.print("请输入姓名:");
String name = scanner.nextLine();
ss.findRoomMateByName(name);
}
/**
* 添加室友
*/
private void addRoomMates() {
while(true){
System.out.println("1,添加\t2,退到上一层");
System.out.print("请选择:");
int choose = Integer.parseInt(scanner.nextLine());
switch (choose) {
case 1:
add();
break;
case 2:
return;
default:
System.out.println("info -- 无此项,请重新选择!");
}
}
}
/**
* 添加
*/
private void add() {
System.out.print("请输入学号:");
String sno = scanner.nextLine();
System.out.print("请输入姓名:");
String name = scanner.nextLine();
System.out.print("请输入性别:");
String sex = scanner.nextLine();
System.out.print("请输入年龄:");
int age = Integer.parseInt(scanner.nextLine());
ss.addRoomMates(new Student(sno,name,sex,age));
}
}
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.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()));
}
}
class Student{
private String name;
private int num;
private String course1;
private String course2;
private String course3;
private String course4;
private String course5;
private String course6;
private String course7;
private String course8;
private String course9;
private String course10;
public String toString() {
return "OrderStatus [name=" + name + ", num=" + num + ", course1="
+ course1 + ", course2=" + course2 + ", course3=" + course3
+ ", course4=" + course4 + ", course5=" + course5
+ ", course6=" + course6 + ", course7=" + course7
+ ", course8=" + course8 + ", course9=" + course9
+ ", course10=" + course10 + "]";
}
}
public class Main{
public static void main(String[] args){}
Student student = new Student();
system.out.println(student.toString);