import?java.util.ArrayList;
公司主營(yíng)業(yè)務(wù):網(wǎng)站設(shè)計(jì)制作、做網(wǎng)站、移動(dòng)網(wǎng)站開(kāi)發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競(jìng)爭(zhēng)能力。創(chuàng)新互聯(lián)公司是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開(kāi)放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對(duì)我們的高要求,感謝他們從不同領(lǐng)域給我們帶來(lái)的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來(lái)驚喜。創(chuàng)新互聯(lián)公司推出魯?shù)槊赓M(fèi)做網(wǎng)站回饋大家。
import?java.util.Collections;
import?java.util.Comparator;
import?java.util.List;
public?class?Sort?{
public?static?void?main(String[]?args)?{
Student?p1?=?new?Student(1001,?"小明",?20);
Student?p2?=?new?Student(1002,?"小紅",?21);
Student?p3?=?new?Student(1003,?"小黑",?19);
ListStudent?list?=?new?ArrayListStudent();
list.add(p1);
list.add(p2);
list.add(p3);
Collections.sort(list,?new?ComparatorStudent()?{
/*
?*?int?compare(Student?o1,?Student?o2)?返回一個(gè)基本類型的整型,?返回負(fù)數(shù)表示:o1?小于o2,
?*?返回0?表示:o1和o2相等,?返回正數(shù)表示:o1大于o2。
?*/
public?int?compare(Student?o1,?Student?o2)?{
//?按照學(xué)生的學(xué)號(hào)進(jìn)行升序排列
if?(o1.getId()??o2.getId())?{
return?1;
}
if?(o1.getId()?==?o2.getId())?{
return?0;
}
return?-1;
}
});
write(list);
System.out.println("---------------------");
Collections.sort(list,?new?ComparatorStudent()?{
/*
?*?int?compare(Student?o1,?Student?o2)?返回一個(gè)基本類型的整型,?返回負(fù)數(shù)表示:o1?小于o2,
?*?返回0?表示:o1和o2相等,?返回正數(shù)表示:o1大于o2。
?*/
public?int?compare(Student?o1,?Student?o2)?{
//?按照學(xué)生的年齡進(jìn)行升序排列
if?(o1.getAge()??o2.getAge())?{
return?1;
}
if?(o1.getAge()?==?o2.getAge())?{
return?0;
}
return?-1;
}
});
write(list);
}
public?static?void?write(ListStudent?list)?{
for?(Student?s?:?list)?{
System.out.println(s.getId()?+?"\t"?+?s.getName()?+?"\t"
+?s.getAge());
}
}
}
public?class?Student?{
private?int?id?;
private?String?name;
private?int?age;
//構(gòu)造方法
public?Student(int?id,String?name,int?age){
this.id?=?id;
this.name?=?name;
this.age?=?age;
}
public?int?getId()?{
return?id;
}
public?void?setId(int?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;
}
}
lListStudent students = new ArrayListStudent();
BufferedReader br = new BufferedReader(new FileReader("D:\student.txt"));
String tmpStr = br.readLine();
while(tmpStr != null){
int firstIndex = tmpStr.indexOf(" ");
int secondIndex = tmpStr.indexOf(" ",firstIndex + 1);
int thirdIndex = tmpStr.indexOf(" ", secondIndex + 1);
int forthIndex = tmpStr.indexOf(" ", thirdIndex + 1);
Integer stuId = Integer.parseInt(tmpStr.substring(0,firstIndex));
String stuName = tmpStr.substring(firstIndex + 1,secondIndex);
Integer stuYW = Integer.parseInt(tmpStr.substring(secondIndex + 1,thirdIndex));
Integer stuSX = Integer.parseInt(tmpStr.substring(thirdIndex + 1,forthIndex));
Integer stuYY = Integer.parseInt(tmpStr.substring(forthIndex + 1));
Student student = new Student();
student.setStuId(stuId);
student.setStuName(stuName);
student.setStuYW(stuYW);
student.setStuSX(stuSX);
student.setStuYY(stuYY);
students.add(student);
tmpStr.readLine();
}
//創(chuàng)建一個(gè)學(xué)生實(shí)體類 封裝stuId stuName stuYW stuSx stuYY 這5個(gè)屬性。。。
//已經(jīng)幫你把數(shù)據(jù)拆分出來(lái) 并以Student 對(duì)象的形式放入集合中了 接下來(lái) 給分吧 哇咔咔
public class Course {
private String name;
private float score;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getScore() {
return score;
}
public void setScore(float score) {
this.score = score;
}
public Course(String name, float score) {
this.name = name;
this.score = score;
}
public String toString() {
return this.name + ":" + this.score;
}
}
public class Student {
private long id;
private String name;
private int age;
private boolean sex;
public String toString() {
String sex = "女";
if (this.sex == true) {
sex = "男";
}
return String.format("姓名:%s,性別:%s,聯(lián)系電話:%s,課程信息:%s,課程信息:%s", this.name, sex, this.phone, this.subject.toString());
}
public long getId() {
return id;
}
public void setId(long 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 boolean isSex() {
return sex;
}
public void setSex(boolean sex) {
this.sex = sex;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public Course[] getSubject() {
return subject;
}
public void setSubject(Course[] subject) {
this.subject = subject;
}
private String phone;
private Course[] subject;
public Student(long i, String n, int a, boolean s, String p) {
this.id = i;
this.name = n;
this.age = a;
this.sex = s;
this.phone = p;
}
}
import java.util.ArrayList;
public class Cmanage {
private ArrayListStudent students;
//插入
public void addStudent(Student student) {
students.add(student);
}
//刪除
public void delStudent(Student student) {
students.remove(student);
}
//查詢
public void queryStudent() {
System.out.printf("一共有%d個(gè)學(xué)生", students.size());
for (Student student : students) {
System.out.println(student.toString());
}
}
//修改
public void updateStudent(long i, String n, int a, boolean s, String p)
{
//以姓名做為唯一標(biāo)識(shí)
for(int j=0;jstudents.size();j++)
{
if (students.get(j).getName().equals(n))
{
students.get(j).setId(i);
students.get(j).setAge(a);
students.get(j).setSex(s);
students.get(j).setPhone(p);
}
}
}
}
以下方法實(shí)現(xiàn)了用戶界面登陸
import java.awt.*;
import java.awt.event.*;
public class DengLuJieMian extends Frame implements ActionListener
{
Label username=new Label("用戶名:");//使用文本創(chuàng)建一個(gè)用戶名標(biāo)簽
TextField t1=new TextField();//創(chuàng)建一個(gè)文本框?qū)ο?/p>
Label password=new Label("密碼:");//創(chuàng)建一個(gè)密碼標(biāo)簽
TextField t2=new TextField();
Button b1=new Button("登陸");//創(chuàng)建登陸按鈕
Button b2=new Button("取消");//創(chuàng)建取消按鈕
public DengLuJieMian()
{
this.setTitle("學(xué)生信息管理系統(tǒng)");//設(shè)置窗口標(biāo)題
this.setLayout(null);//設(shè)置窗口布局管理器
username.setBounds(50,40,60,20);//設(shè)置姓名標(biāo)簽的初始位置
this.add(username);// 將姓名標(biāo)簽組件添加到容器
t1.setBounds(120,40,80,20);// 設(shè)置文本框的初始位置
this.add(t1);// 將文本框組件添加到容器
password.setBounds(50,100,60,20);//密碼標(biāo)簽的初始位置
this.add(password);//將密碼標(biāo)簽組件添加到容器
t2.setBounds(120,100,80,20);//設(shè)置密碼標(biāo)簽的初始位置
this.add(t2);//將密碼標(biāo)簽組件添加到容器
b1.setBounds(50,150,60,20);//設(shè)置登陸按鈕的初始位置
this.add(b1);//將登陸按鈕組件添加到容器
b2.setBounds(120,150,60,20);//設(shè)置取消按鈕的初始位置
this.add(b2);// 將取消按鈕組件添加到容器
b1.addActionListener(this);//給登陸按鈕添加監(jiān)聽(tīng)器
b2.addActionListener(this);// 給取消按鈕添加監(jiān)聽(tīng)器
this.setVisible(true);//設(shè)置窗口的可見(jiàn)性
this.setSize(300,200);//設(shè)置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});//通過(guò)內(nèi)部類重寫關(guān)閉窗體的方法
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)//處理登陸事件
{
String name=t1.getText();
String pass=t2.getText();
if(name!=nullpass.equals("000123"))//判斷語(yǔ)句
{
new StudentJieMian();
}
}
}
public static void main(String args[])//主函數(shù)
{
new DengLuJieMian();
}
}
以下方法實(shí)現(xiàn)了學(xué)生界面設(shè)計(jì)
import java.awt.*;
import java.awt.event.*;
class StudentJieMian extends Frame implements ActionListener
{
MenuBar m=new MenuBar();//創(chuàng)建菜單欄
Menu m1=new Menu("信息");//創(chuàng)建菜單“信息”
MenuItem m11=new MenuItem("插入");//創(chuàng)建“插入”的菜單項(xiàng)
MenuItem m12=new MenuItem("查詢");
Menu m2=new Menu("成績(jī)");//創(chuàng)建菜單“成績(jī)”
MenuItem m21=new MenuItem("查詢");
public StudentJieMian()
{
this.setTitle("學(xué)生界面");//設(shè)置窗口標(biāo)題
this.setLayout(new CardLayout());//設(shè)置窗口布局管理器
this.setMenuBar(m);//將菜單欄組件添加到容器
m.add(m1);//將信息菜單放入菜單欄
m.add(m2);
m1.add(m11);//將“插入”菜單項(xiàng)添加到“信息”菜單
m1.add(m12); //將“查詢”菜單項(xiàng)添加到“信息”菜單
m2.add(m21); //將“查詢”菜單項(xiàng)添加到“成績(jī)”菜單
m11.addActionListener(this); //給“插入”菜單項(xiàng)添加監(jiān)聽(tīng)器
m12.addActionListener(this); //給“查詢”菜單項(xiàng)添加監(jiān)聽(tīng)器
m21.addActionListener(this); //給“查詢”菜單項(xiàng)添加監(jiān)聽(tīng)器
this.setVisible(true); //設(shè)置窗口的可見(jiàn)性
this.setSize(300,200); //設(shè)置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);//關(guān)閉窗口
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==m11) //處理“添加信息”事件
{
new AddStudent();
}
if(e.getSource()==m12) //處理“查詢信息”事件
{
new SelectStudent();
}
if(e.getSource()==m21) //處理“查詢成績(jī)”事件
{
new ChengJiStudent();
}
}
public static void main(String args[])
{ new StudentJieMian(); //創(chuàng)建一個(gè)對(duì)象 }