Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the IO Student Management system by Java

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how Java implements the IO version of the student management system. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

The details are as follows

Illustration:

Cade:

Student.java

/ * * this is my student class * / public class Student {/ / Student ID private String id; / / name private String name; / / Age private String age; / / residence private String address; public Student () {} public Student (String id, String name, String age, String address) {this.id = id; this.name = name This.age = age; this.address = address;} 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 String getAge () {return age } public void setAge (String age) {this.age = age;} public String getAddress () {return address;} public void setAddress (String address) {this.address = address;}}

Studentmangager class

Import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.util.ArrayList;import java.util.Scanner / * * this is the main class of my student management system * * the steps are as follows: * A: define the student class * B: code writing of the main interface of the student management system * C: view of the student management system all student code writing * D: student management system add student code writing * E: student management system delete student code writing * F: modification of student management system student code writing * / public class StudentManagerTest {public static void main (String [] args) throws IOException {/ / definition file path String fileName = "students.txt" / / in order for the program to come back here, we use cyclic while (true) {/ / this is the main interface of the student management system System.out.println ("- Welcome to the student management system -"); System.out.println ("1 View all students") System.out.println ("2 add students"); System.out.println ("3 delete students"); System.out.println ("4 modify students"); System.out.println ("5 quit"); System.out.println ("Please enter your choice:") / / create keyboard entry object Scanner sc = new Scanner (System.in); String choiceString = sc.nextLine (); / / use switch statement to select switch (choiceString) {case "1": / / View all students findAllStudent (fileName); break Case "2": / / add student addStudent (fileName); break; case "3": / / delete student deleteStudent (fileName); break Case "4": / / modify student updateStudent (fileName); break; case "5": default: System.out.println ("Thank you for using"); System.exit (0); / / JVM quit break Read data from file to collection public static void readData (String fileName,ArrayList array) throws IOException {/ / create input buffered stream object BufferedReader br = new BufferedReader (new FileReader (fileName)); String line; while ((line=br.readLine ())! = null) {String [] datas = line.split (",") Student s = new Student (); s.setId (datas [0]); s.setName (datas [1]); s.setAge (datas [2]); s.setAddress (datas [3]); array.add (s);} br.close () } / / write the data in the collection to the file public static void writeData (String fileName,ArrayList array) throws IOException {/ / create the output buffered stream object BufferedWriter bw = new BufferedWriter (new FileWriter (fileName)); for (int xstream 0; x

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report