Simple Student Achievement Management System (implemented in Java)

Source: Internet
Author: User

/** Copyright (c) Guan chengwen at Xiamen University
** 2005-12-25
** Student ID: 03231004, philosophy department
** Email: mydream2007@hotmail.com QQ: 233204600
** Homepage: http://blog.csdn.net/aprin/
**
** File: Main. Java
** Package: aprin. stu_sys
*/

Package aprin. stu_sys;
Import java. Lang .*;
Import java. Io .*;
Import aprin. stu_sys .*;

Public class main
{
Public static void main (string [] ARGs)
{
While (true)
{
Menu. Paint ();
Int ctrltag = console. readint ();
Switch (ctrltag)
{
Case 1:
{
Menu. Action1 ();
Break;
}

Case 2:
{
Menu. Action2 ();
Break;
}

Case 3:
{
Menu. action3 ();
Break;
}

Case 4:
{
Menu. Action4 ();
Break;
}

Case 5:
{
Menu. Action5 ();
Break;
}

Case 6:
{
Menu. Action6 ();
Break;
}

Case 0:
{
System. Exit (0 );
Break;
}
}
}
}
}

Class student
{
Private int number;
Private string name;
Private int English;
Private int math;
Private int computer;
Private int average;
Private int total;

Public student ()
{
}

Public student (INT number, string name, int English, int math, int computer)
{
This. Number = number;
This. Name = Name;
This. English = English;
This. Math = math;
This. Computer = computer;
Total = English + math + computer;
Average = total/3;
}

Public int getnumber ()
{
Return number;
}

Public String getname ()
{
Return name;
}

Public int getenglish ()
{
Return English;
}

Public int getmath ()
{
Return math;
}

Public int getcomputer ()
{
Return computer;
}

Public int getaverage ()
{
Return average;
}

Public int gettotal ()
{
Return total;
}
}

Class studentset
{
Private Static final int maxlename = 1000;
Private Static int Len = 0;
Private Static student [] DATA = new student [maxlen];

Public static int getmaxlen ()
{
Return maxlen;
}

Public static int getlen ()
{
Return Len;
}

Public static student getdata (INT index)
{
Return data [Index];
}

Public static int adddata (student newdata)
{
If (LEN <maxlen)
{
Data [Len] = newdata;
Len ++;
Return 0;
} Else
{
Return-1;
}
}

Public static void sortdata ()
{
For (INT I = 0; I <len-1; I ++)
{
Int minindex = I;
For (Int J = I + 1; j <Len; j ++)
{
If (data [minindex]. getaverage ()> data [J]. getaverage ())
{
Minindex = J;
}
}
If (minindex! = I)
{
Student temp = data [I];
Data [I] = data [minindex];
Data [minindex] = temp;
}
}
}

Public static int search (INT number)
{
For (INT I = 0; I <Len; I ++)
{
If (data [I]. getnumber () = number)
{
Return I;
}
}
Return-1;
}

Public static int Delete (INT number)
{
For (INT I = 0; I <Len; I ++)
{
If (data [I]. getnumber () = number)
{
For (Int J = I + 1; j <Len; j ++)
{
Data [J-1] = data [J];
}
Len --;
Return 0;
}
}
Return-1;
}

Public static int Stat (INT min, int max)
{
Int sum = 0;

For (INT I = 0; I <Len; I ++)
{
If (data [I]. getaverage ()> = min) & (data [I]. getaverage () <= max ))
{
Sum ++;
}
}
Return sum;
}
}

Class Console
{
Public static int readint ()
{
Int result = 0;
Try {
String temp = new bufferedreader (New inputstreamreader (system. In). Readline ();
Result = integer. parseint (temp );
} Catch (exception E)
{
System. Out. println ("error:" + E );
}
Return result;
}

Public static string readsting ()
{
String result = NULL;
Try {
Result = new bufferedreader (New inputstreamreader (system. In). Readline ();
} Catch (exception E)
{
System. Out. println ("error:" + E );
}
Return result;
}
}

Class Menu
{
Public static void paint ()
{
Clrscr ();
For (INT I = 0; I <80; I ++)
{
System. Out. Print ('= ');
}
System. Out. println ();

System. Out. println ("Student Achievement Management System ");
System. Out. println ();
System. Out. println ("1 input record 2 output all records ");
System. Out. println ("3 sort by average score and output 4 search records ");
System. Out. println ("5 counting the number of people in each score segment 6 deleting records ");
System. Out. println ("0 quit ");

For (INT I = 0; I <80; I ++)
{
System. Out. Print ('= ');
}
System. Out. println ("Copyright (c) 2005 文 ");
System. Out. println ();
System. Out. Print ("Enter the command :");
}

Public static int Action1 ()
{
While (true)
{
Clrscr ();
System. Out. Print ("student ID to be entered (enter"-1 "to exit ):");

Int number = console. readint ();
If (number! =-1)
{
System. Out. Print ("* Name :");
String name = console. readsting ();
System. Out. Print ("* English :");
Int English = console. readint ();
System. Out. Print ("* mathematics :");
Int math = console. readint ();
System. Out. Print ("* computer :");
Int computer = console. readint ();
Student newdata = new student (number, name, English, math, computer );
If (studentset. adddata (newdata) =-1)
{
System. Out. println ("Data overflow! ");
Return-2;
}
} Else
{
Return-1;
}
}
}

Public static void Action2 ()
{
Clrscr ();
If (studentset. getlen () = 0)
{
System. Out. println ("no record! ");
} Else
{
System. Out. println ("Mathematics | English | computer | average | Total ");
For (INT I = 0; I <studentset. getlen (); I ++)
{
System. Out. println ("student ID:" + studentset. getdata (I). getnumber () + "name:" + studentset. getdata (I). getname ());
System. Out. println ("" + studentset. getdata (I). getmath () + "" + studentset. getdata (I). getenglish () +
"" + Studentset. getdata (I ). getcomputer () + "" + studentset. getdata (I ). getaverage () + "" + studentset. getdata (I ). gettotal ());
}
}
}

Public static void action3 ()
{
Studentset. sortdata ();
Action2 ();
}

Public static void Action4 ()
{
Clrscr ();
System. Out. Print ("Enter the student ID for record search :");
Int number = console. readint ();
Int I;
If (I = studentset. Search (number ))! =-1)
{
Clrscr ();
System. Out. println ("Mathematics | English | computer | average | Total ");
System. Out. println ("student ID:" + studentset. getdata (I). getnumber () + "name:" + studentset. getdata (I). getname ());
System. Out. println ("" + studentset. getdata (I). getmath () + "" + studentset. getdata (I). getenglish () +
"" + Studentset. getdata (I ). getcomputer () + "" + studentset. getdata (I ). getaverage () + "" + studentset. getdata (I ). gettotal ());
} Else
{
System. Out. println ("no corresponding record found! ");
}
}
Public static void Action5 ()
{
Clrscr ();
System. Out. println ("90-100:" + studentset. Stat (90,100) + "persons ");
System. Out. println ("80-89:" + studentset. Stat (80, 89) + "persons ");
System. Out. println ("70-79:" + studentset. Stat (70, 79) + "persons ");
System. Out. println ("60-69:" + studentset. Stat (60, 69) + "persons ");
System. Out. println ("0-59:" + studentset. Stat (0, 59) + "persons ");
}

Public static void Action6 ()
{
While (true)
{
Clrscr ();
System. Out. Print ("Enter the student ID of the record to be deleted (enter"-1 "to exit ):");
Int number = console. readint ();
If (number! =-1)
{
If (studentset. Delete (number) =-1)
{
System. Out. println ("no corresponding record found! ");
Return;
} Else
{
System. Out. println ("the record is deleted successfully! ");
}
} Else
{
Return;
}
}
}

Public static void clrscr ()
{// Temp Function
System. Out. println ();
System. Out. println ();
}
}

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.