程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

python spyder jupyter

編輯:Python

python
編輯 What is the difference between the menu and other methods
創建一個學生信息管理系統,學生信息包括:學號,姓名,年齡,性別,出生年月,地址,電話,E-mail

功能:1.系統以菜單方式工作 2.學生信息錄入功能(文件) 3.學生信息浏覽 4.查詢排序功能 1)學號排序 2)姓名排序

public class Student {
//Student information is included(學生學號、姓名、性別、手機號碼
private int id;
private String name;
private String sex;
private String phone;
public Student() {
}
public Student(int id, String name, String sex, String phone) {
this.id = id;
this.name = name;
this.sex = sex;
this.phone = phone;
}
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 String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
@Override
public String toString() {
return "學號:" + id + "\t 姓名:" + name + "\t 性別:" + sex + "\t 電話:" + phone ;
}

}
import java.util.Scanner;

/*
編寫一個學生信息管理系統:Student information is included(學生學號、姓名、性別、手機號碼),The system stores student information in the form of student object array
(初始數組為10個元素,Whenever the array is full,需要進行擴容,The expansion rule can be doubling or fixed growth)
The operation of the system to students includes:新增、查詢、修改、刪除.
大概流程如下:
請選擇操作:退出請輸入bye
1.新增
2.查詢
3.修改
4.刪除
輸入:1
請輸入:學生學號,姓名,性別,手機號碼
輸入:學生學號,姓名,性別,手機號碼
新增完成,請繼續操作!
請選擇操作:退出請輸入bye
1.新增
2.查詢
3.修改
4.刪除
輸入:2
請輸入學生的姓名
錢鐘書
查詢學生:
學生學號,姓名,性別,手機號碼
查詢完畢,請繼續操作!
請選擇操作:退出請輸入bye
1.新增
2.查詢
3.修改
4.刪除
輸入:3
請輸入要修改的學生學號:
10000
學生不存在,請繼續操作!
請選擇操作:退出請輸入bye
1.新增
2.查詢
3.修改
4.刪除
輸入4
請輸入學生學號
刪除成功

  • /
    public class StudentManage {
    // Defines the storage space for an array of objects
    private Student[] students = new Student[4]; public static void main(String[] args) {
     // 創建類對象,Calling non-static methods through class objects StudentManage sm = new StudentManage(); // Initialize some data sm.initStudent(); // 菜單 while (true) { String select = sm.menu(); switch (select) { case "1": sm.addStudent();// 新增 break; case "2": sm.queryStudent();// 查找 break; case "3": sm.modify();// 修改 break; case "4": sm.deleteStudent();// 刪除 break; case "bye": System.out.println("謝謝您的使用");// 退出 return; default: System.out.println("The function is not open"); break; } }
    } // 修改學生信息
    public void modify() {
     Scanner sc = new Scanner(System.in); // Finding a reference value from an array is notnull的空間,存在學號,則修改, 若 學生不存在,請繼續操作! System.out.println("請輸入要修改的學生學號"); int id = sc.nextInt(); boolean b = true; for (int i = 0; i < students.length; i++) { if (students[i] != null && students[i].getId() == id) { System.out.println(students[i]);// 存在學號,First output the student information of the student number,然後修改 b = true; // The student number will not be changed System.out.println("請輸入要修改的學生姓名:"); String name = sc.next(); students[i].setName(name); System.out.println("Please enter the gender of the student to modify:"); String sex = sc.next(); students[i].setSex(sex); System.out.println("Please enter the mobile phone number you want to modify:"); String phone = sc.next(); students[i].setPhone(phone); System.out.println("修改完成"); break; } else { b = false; } } // 學生不存在 if (b == false) { System.out.println("修改失敗!No student information to edit was found!!"); }
    }
    //查找學生 小菜單 1.按照學生姓名查找2.Overview Students3.返回
    public void queryStudent() {
     while(true) { Scanner sc=new Scanner(System.in); System.out.println("1.按照學生姓名查找"); System.out.println("2. Overview Students "); System.out.println("3. 返回 "); System.out.println("Please select the corresponding action:"); int select=sc.nextInt(); //按照姓名查找 if(select==1) { System.out.println("請輸入學生的姓名:"); String name=sc.next(); //返回的下標值,根據下標,Output the information of a certain student you are looking for int index=queryByName(name); if(index!=-1) { System.out.println("The student information was found:"); System.out.println(students[index]); }else{ System.out.println("No student information found for that name"); } //總覽 }else if(select==2) { queryByAll(); }else if(select==3) { //End find method,跳出循環 break; } }
    }
    //查找 Overview of student information
    public void queryByAll() {
     for (int i = 0; i < students.length; i++) { if(students[i]!=null) { System.out.println(students[i]); } }
    }
    //按照姓名查找
    public int queryByName(String name) {
     //The name of the student you are looking for exists,輸出該學生的信息,不存在,Prompt No student information to look for for (int i = 0; i < students.length; i++) { if(students[i]!=null && students[i].getName().equals(name)) { return i;//找到了就返回下標 } } return -1;
    }
    //刪除學生
    public void deleteStudent() {
     Scanner sc=new Scanner(System.in); System.out.println("請輸入要刪除的學生學號:"); int id=sc.nextInt(); //查找到學號,Remove students from the array,沒查找到,The output does not have this student information boolean b=true; for (int i = 0; i < students.length; i++) { //Find from the beginning of the array,A reference value is notnull的空間 if(students[i]!=null && students[i].getId()==id) { System.out.println(students[i]); b=true;//find studentsid students[i]=null; System.out.println("刪除成功!"); break;//To break out of the loop after deletion }else{ b=false; } } //No students were foundid if(b==false) { System.out.println("刪除失敗,沒有找到要刪除的學生信息!");}
    }
    //添加學生
    public void addStudent() {
     Scanner sc=new Scanner(System.in); //Enter the student information you want to add System.out.println("Please enter the student ID to be added:"); int id=sc.nextInt(); //Ensure that the student's student number is unique,如果已存在,cannot be added for (int i = 0; i < students.length; i++) { if(students[i]!=null && students[i].getId()==id) { System.out.println("該學生已存在,不能新增!"); return; } } System.out.println("Please enter the name of the student to be added:"); String name=sc.next(); //guaranteed in the array Students' names are unique //If the array already has the student name to add,則不能添加 int index=queryByName(name); if(index!=-1) { System.out.println("該學生已存在,不能新增!"); return; } System.out.println("Please enter the gender of the student to add:"); String sex=sc.next(); System.out.println("Please enter the student mobile number to be added:"); String phone=sc.next(); //Add the information to the array of student objects //Find from the beginning of the array,until a reference value is found 為null的空間,添加學生信息 boolean isFull=true; for (int i = 0; i
    
    
    } //菜單
    public String menu() {
     System.out.println("請選擇操作:退出請輸入bye"); System.out.println("1.新增學生信息"); System.out.println("2.查詢學生信息"); System.out.println("3.修改學生信息"); System.out.println("4.刪除學生信息"); Scanner sc=new Scanner(System.in); String select=sc.next(); return select;
    }
    //Initialize some data
    public void initStudent() {
     students[0]=new Student(101,"張三","男","15566668888"); students[1]=new Student(102,"李四","男","14455557777"); students[2]=new Student(103,"王二","男","12233336666");
    }
    }

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved