Java Student Performance management system source code

Source: Internet
Author: User
Tags count integer key modify readline return sort tostring
source code import Java.io.BufferedReader;
Import Java.io.BufferedWriter;
Import Java.io.File;
Import java.io.FileNotFoundException;
Import Java.io.FileReader;
Import Java.io.FileWriter;
Import java.io.IOException;
Import Java.io.InputStreamReader;
Import Java.io.PrintWriter;
Import Java.io.StringReader;
Import java.util.ArrayList;
Import java.util.Collection;
Import java.util.Collections;
Import Java.util.HashMap;
Import Java.util.Iterator;
Import Java.util.StringTokenizer;

/*
* Created on 2005-1-11
*/

/**
* @author Let Wei
* @since 1.0
*
* TODO Student Performance Management system
* Find, modify, delete data by learning number
*
*/
public class Littleprogram
{
static Boolean isdelete = true;
static Boolean isfind = true;
public static void Main (String [] args)/Main method, where the program starts running
Throws Ioexception,numbernotfoundexception
{
int choice=-1;
do{
Littleprogram LP = new Littleprogram ();
System.out.println ();
System.out.println ("\t####################################");
System.out.println ();
System.out.println ("\t\t Java Student Performance Management System 1.1");
System.out.println ("\t\t, please find, modify, delete data");
System.out.println ();
System.out.println ("\t####################################\n");
System.out.print ("1. Add data: \ n" +
"2. Find data: \ n" +
"3. Delete data: \ n" +
"4. Clear all data: \ n" +
"5. Print all the data to the screen \ n" +
"6. Sort the score by school number \ n" +
"7. Modify data \ n" +
"8. Statistics of the number of students recorded score \ n" +
"9. About author \ n" +
"0. Quit the program. \ n" +
"Input:");
BufferedReader in =//from end
New BufferedReader (//end-up)
New InputStreamReader (system.in))//Collection
String inputline = In.readline (); Word selection
Choice= integer.valueof (inputline). Intvalue ();
Switch (choice)
{
Case 1: {//1. Add data
String str = Lp.inputdata ();
Lp.adddata (str);
SYSTEM.OUT.PRINTLN ("Increase data success.");
TimeOut (1);
}break;
Case 2: {//2. Find data
Long find = 0;
System.out.print ("Please enter the student number you are looking for:");
BufferedReader inn =
New BufferedReader (
New InputStreamReader (system.in));
String Inputli = Inn.readline ();
Find = integer.valueof (Inputli). Longvalue ();
Lp.finddata (find);

TimeOut (2);
}break;
Case 3: {//3. Delete data
Long deletenumber = 0;
System.out.print ("Please enter the student number you want to delete:");
BufferedReader BF =
New BufferedReader (
New InputStreamReader (system.in));
String inputl = Bf.readline ();
Deletenumber = integer.valueof (inputl). Longvalue ();
Lp.deletedata (Deletenumber);
if (Isdelete)
System.out.println ("Delete data successful!");
TimeOut (1);
}break;
Case 4: {
Lp.cleardata ();//4. Clear All data
TimeOut (1);
}break;
Case 5: {
Print ();//5 the data to the screen.
TimeOut (2);
}break;
Case 6: {
Lp.numsort ()//6. Sort the score by the number of studies
System.out.println ("according to the school number from small to large sort of success!\n" +
"After sort: \ n");
Print ();
TimeOut (2);
}break;
Case 7: {
Lp.rewrite ();//7. Modify Data
TimeOut (2);
}break;
Case 8: {
int count = Lp.count ();
System.out.println ("A total of" +count+ "students have been recorded.");
TimeOut (2);
}break;
Case 9: {
System.out.print ("\t\t let Wei \ n" +
"\t\t Shanghai Electric Power College Communication engineering Department \ n" +
"\t\tqq:254482170\n");
TimeOut (4);
}break;
}while (choice!= 0);
System.out.println ("bye! ^-^");
System.exit (0);
}
public string Inputdata ()//The method of receiving data from the terminal, returning a string
Throws Ioexception,numberformatexception
{
System.out.print ("Please enter: School number name sex score \ n" +
"Separate each data by a space:");
String all = "";
try{
BufferedReader in =//from end
New BufferedReader (//end-up)
New InputStreamReader (system.in)); Collect number
String inputline = In.readline (); According
StringTokenizer str =
New StringTokenizer (Inputline, "");//Receive data separated by spaces, this class is used to extract each string
Long num = integer.valueof (Str.nexttoken ()). Longvalue ();//School Number
String name = (string) str.nexttoken (); Name
String sex = (string) str.nexttoken (); Gender
Double mark = integer.valueof (Str.nexttoken ()). Doublevalue ();//Fractions
all = String.valueof (num) + "," +
Name + "," +
Sex + "," +
String.valueof (Mark)//Put all the data in "," and then connect it into the string all
}catch (IOException e) {}
catch (NumberFormatException e) {}
Return all;//returns the string all
}
public void AddData (String str)//method of increasing data
Throws IOException
{
String S1 = "", s2= "", s3= "";
File File = new file ("Data.txt");
if (file.exists ())//if file Data.txt exists
{
try{
BufferedReader in =
New BufferedReader (
New FileReader ("Data.txt"));
while ((S1=in.readline ())!=null)
s2+=s1+ "\ n";//put each row of data in a file into a string s2
S2+=str+ "\ n"; And then put the S2 in the form of STR and put it into S2.
BufferedReader in2 =//Put character
New BufferedReader (//String S2 Also
New StringReader (S2)); is the original
PrintWriter out =//File +
New PrintWriter (//Parameter str (newly entered row of data)
New BufferedWriter (//re-written in Data.txt
New FileWriter ("Data.txt")); Overwrite the original data
while ((S3=in2.readline ())!= null)
{
Out.println (S3);
}
Out.close ();
System.out.println ("Write Data True.");
}catch (IOException e) {}
}else{
System.err.println ("File \" data\ "missing!");
}
}
public void ClearData ()//method to clear all data for data.txt
Throws IOException
{
File File = new file ("Data.txt");
if (file.exists ())//If the file is
{
try{
PrintWriter out =
New PrintWriter (
New BufferedWriter (
New FileWriter (file));
Out.print ("");//write a null character in the file data.txt, so clear the original content
Out.close (); Close File
SYSTEM.OUT.PRINTLN ("Clear Data true!");
}catch (IOException e) {}
}else{
System.err.println ("File \" data\ "missing!");
}
}
public void DeleteData (long deletenumber)//delete a piece of data
Throws Ioexception,filenotfoundexception
{
Isdelete = true;
try{
Datamap MP = new Datamap ();//Generate a container of your own writing
Long j=0;
String s1= "", s2= "", s3= "";
BufferedReader in =
New BufferedReader (
New FileReader ("Data.txt"));
while ((S1=in.readline ())!=null)
{
J=numbertokenizer (S1);
Mp.put (J,S1);
}
try{
if (Mp.containskey (string.valueof (Deletenumber). toString ()))
{
Mp.remove (Deletenumber);
}else
throw new Numbernotfoundexception ();
Collection C = mp.values ();
Iterator iter = C.iterator ();
while (Iter.hasnext ())
{
S1 = (String) iter.next ();
S3 +=s1+ "\ n";
}
BufferedReader in2 =
New BufferedReader (
New StringReader (S3));
PrintWriter out =
New PrintWriter (
New BufferedWriter (
New FileWriter ("Data.txt"));
System.out.println ("delete No" +deletenumber);
while ((S1 = In2.readline ())!=null)
{
Out.println (S1);
}
Out.close ();
}catch (numbernotfoundexception e)
{
Isdelete = false;
System.out.println (deletenumber+ "no found:(");
}
}catch (IOException e) {}
}
Public long Numbertokenizer (String s)
Throws IOException
{
StringTokenizer st =
New StringTokenizer (S, "");
Return Integer.valueof ((St.nexttoken ())). Longvalue ();
}
public void FindData (long find)/lookup data
Throws Ioexception,numbernotfoundexception
{
Isfind = true;
String s = "", findstring = "";
Long I;
Datamap dm = new Datamap ();
BufferedReader in =
New BufferedReader (
New FileReader ("Data.txt"));
while ((S=in.readline ())!=null)
{
I=numbertokenizer (s);
Dm.put (i,s);
}
In.close ();
try{
if (Dm.containskey (string.valueof (Find). ToString ()))
{
FindString = Dm.get (find);
SYSTEM.OUT.PRINTLN ("Student number" +find+ "Students ' information is:");
System.out.println (findstring);
}else
throw new Numbernotfoundexception ();
}catch (Numbernotfoundexception e) {
System.out.println (find+ "no found:(");
Isfind = false;
}
}
public static void print ()//read a text file to print data to the terminal method
Throws IOException
{
try{
BufferedReader in =
New BufferedReader (
New FileReader ("Data.txt"));
String read = "";
while (read = In.readline ())!=null)
SYSTEM.OUT.PRINTLN (read);
}catch (IOException e) {}
}
public static void TimeOut (double sec)//Pause a short time a method completely can not this function
{
Double seconds = sec;
Long T = System.currenttimemillis () + (int) (seconds*1000);
while ((System.currenttimemillis ()) <t)
;
}
public void Numsort ()//sorted by school Number
Throws IOException
{
Long i = 0;
String s = "";
try{
Dataarraylist dal = new dataarraylist ();
BufferedReader in =
New BufferedReader (
New FileReader ("Data.txt"));
while ((S=in.readline ())!=null)
{
I=numbertokenizer (s);
Dal.add (i);
}
Collections.sort (DAL);
Datamap dm = new Datamap ();
BufferedReader in2 =
New BufferedReader (
New FileReader ("Data.txt"));
while ((S=in2.readline ())!=null)
{
I=numbertokenizer (s);
Dm.put (i,s);
}
PrintWriter out =
New PrintWriter (
New BufferedWriter (
New FileWriter ("Data.txt"));
Iterator it = Dal.iterator ();
Long temp = 0;
String tempstr = "";
while (It.hasnext ())
{
temp = integer.valueof ((String) It.next ()). Longvalue ();
TempStr = Dm.get (temp);
Out.println (TEMPSTR);
}
Out.close ();
}catch (IOException e) {}
}
public void rewrite ()
Throws Ioexception,numbernotfoundexception
{
try{
System.out.print ("Please enter the student number you want to revise:");
BufferedReader in =
New BufferedReader (
New InputStreamReader (system.in));
String inputline = In.readline ();
Long num = integer.valueof (inputline). Longvalue ();
FindData (num);
if (Isfind)
{
DeleteData (num);
System.out.print ("Please re-enter the student's information:");
String str = Inputdata ();
AddData (str);
System.out.println ("rewrite true!");
}
}catch (IOException e) {}
catch (Numbernotfoundexception e) {}
}
public int count ()
Throws IOException
{

Dataarraylist dal = new dataarraylist ();
try{
String s = "";
Long i = 0;
BufferedReader in =
New BufferedReader (
New FileReader ("Data.txt"));
while ((S=in.readline ())!=null)
{
I=numbertokenizer (s);
Dal.add (i);
}
}catch (IOException e) {}
return Dal.size ();
}
}
/*
*
* @author Rangwei
* TODO This is a container we write, inheriting the public class HashMap
* The approximate function is quite an array
*
*/
Class Datamap extends hashmap//a map for storing data
{
public void put (Long i,string str)//Put the school number and data into this map
{//later a school number (key) corresponds to a person's data (value)
Put (string.valueof (i). toString (), str);
}
public void Remove (long i)/receive the number, and then delete the school number (key) and its corresponding data (value)
{
Remove (string.valueof (i). ToString (). ToString ());
}
The public String get (long i) receives a school number, and then returns the value of the key
{
String s = string.valueof (i). toString ();
if (!containskey (s))
{
System.err.println ("Not Found Key:" +s);
}
Return (String) get (s);
}
}
/*
*
* @author Rangwei
*
* TODO This class inherits ArrayList
* Used to sort by number, use it when sorting with a school number
*
*/
Class Dataarraylist extends ArrayList
{
public void Add (Long num)
{
String numtostring = string.valueof (num). toString ();
Add (numtostring);
}
}
/*
*
* @author Rangwei
*
* TODO adds a exception, mostly in the file without looking for
* The school number is thrown
*
*/
Class Numbernotfoundexception extends Exception
{
Public Numbernotfoundexception ()
{}
}





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.