Function call instance: the student management system (the optimized version above). A window is displayed .,

Source: Internet
Author: User

Function call instance: the student management system (the optimized version above). A window is displayed .,

1 package classwork308; 2/* 3 * student management system 4 */5 import javax. swing. JOptionPane; 6 7 public class Method_StudentManage {8 9/****** management account *****/10 public static String [] manager = {"", "B"}; 11/***** manage password *****/12 public static int [] password = {1, 2 }; 13/***** Student name array *****/14 public static String [] name = new String [30]; 15/***** student ID array *****/16 public static int [] code = new int [30]; 17/***** Student Score array *****/18 Public static int [] grade = new int [30]; 19/***** record the number of students *****/20 public static int number = 0; 21 22 public static void main (String [] args) {23 register (); 24} 25 26 // Administrator Logon 27 public static void register () {28 JOptionPane. showMessageDialog (null, "Welcome! "); 29 int a =-1, B = 0; 30 while (true) {31 String str = JOptionPane. showInputDialog (null, "Enter the user name"); 32 String str1 = JOptionPane. showInputDialog (null, "Enter Password"); 33 int temp = Integer. parseInt (str1); 34 for (int I = 0; I <manager. length; I ++) {35 if (str. equals (manager [I]) & temp = password [I]) {// 36 OS (); 37 a = 1; 38} 39} 40 if (a =-1) {41 if (B = 3) {42 JOptionPane. showMessageDialog (null, "invalid user"); 43 System. exit (0); 44} 45 JOptionPane. showMessageDialog (null, "incorrect user name or password"); 46 B ++; 47} 48} 49} 50 // Select page 51 public static void OS () {52 while (true) {53 String s = JOptionPane. showInputDialog (null, "1. Add \ n2, display \ n3, delete \ n4, QUERY \ n5, modify \ n6, sort \ n7, and exit \ n "); 54 int temp = Integer. parseInt (s); 55 switch (temp) {56 case 1: 57 add (); 58 break; 59 case 2: 60 show (); 61 break; 62 case 3: 63 delete (); 64 break; 65 case 4: 66 demand (); 67 break; 68 case 5: 69 modification (); 70 break; 71 case 6: 72 sort (); 73 break; 74 case 7: 75 System. exit (0); 76 break; 77 78 default: 79 JOptionPane. showMessageDialog (null, "Enter the number between 1 and 7"); 80 break; 81} 82} 83} 84 // add 85 public static void add () {86 String str1 = JOptionPane. showInputDialog (null, "Enter your student ID"); 87 String str2 = JOptionPane. showInputDialog (null, "Enter name"); 88 String str3 = JOptionPane. showInputDialog (null, "Enter the score"); 89 int temp1 = Integer. parseInt (str1); 90 int temp3 = Integer. parseInt (str3); 91 code [number] = temp1; 92 name [number] = str2; 93 grade [number] = temp3; 94 number ++; 95} 96 // delete 97 public static void delete () {98 String str = JOptionPane. showInputDialog (null, "Enter name"); 99 int a =-1; 100 for (int I = 0; I <number; I ++) {101 if (str. equals (name [I]) {102 for (int j = I; j <number-1; j ++) {103 name [j] = name [j + 1]; 104 code [j] = code [j + 1]; 105 grade [j] = grade [j + 1]; 106 107} 108 a = 1; 109 number --; 110 show (); 111 break; 112} 113} 114 if (a =-1) {115 JOptionPane. showMessageDialog (null, "student not found"); 116} 117} 118 // modify 119 public static void modification () {120 String str = JOptionPane. showInputDialog (null, "Enter name"); 121 int a =-1; 122 for (int I = 0; I <number; I ++) {123 if (str. equals (name [I]) {124 a = I; 125 String str1 = JOptionPane. showInputDialog (null, "Enter your student ID"); 126 String str2 = JOptionPane. showInputDialog (null, "Enter the score"); 127 int temp1 = Integer. parseInt (str1); 128 int temp2 = Integer. parseInt (str2); 129 name [I] = JOptionPane. showInputDialog (null, "Enter name"); 130 code [I] = temp1; 131 grade [I] = temp2; 132 show (); 133} 134} 135 if (a =-1) {136 JOptionPane. showMessageDialog (null, "student not found"); 137} 138 139} 140 // query 141 public static void demand () {142 String str = JOptionPane. showInputDialog (null, "Enter name"); 143 int a =-1; 144 for (int I = 0; I <number; I ++) {145 if (str. equals (name [I]) {146 a = I; 147 String s = "student ID name Score \ n "; 148 s = s + code [I] + "" + name [I] + "" + grade [I]; 149 JOptionPane. showMessageDialog (null, s); 150} 151} 152 if (a =-1) {153 JOptionPane. showMessageDialog (null, "student not found"); 154} 155} 156 // sort by score in descending order 157 public static void sort () {158 int temp, temp1; 159 String temp3; 160 for (int I = 0; I <number-1; I ++) {161 for (int j = I + 1; j <number; j ++) {162 if (grade [I] <grade [j]) {163 temp = grade [I]; 164 grade [I] = grade [j]; 165 grade [j] = temp; 166 temp1 = code [I]; 167 code [I] = code [j]; 168 code [j] = temp1; 169 temp3 = name [I]; 170 name [I] = name [j]; 171 name [j] = temp3; 172} 173} 174 show (); 176} 177 // display all student information 178 public static void show () {179 String s = "student ID name Score \ n"; 180 for (int I = 0; I <number; I ++) {181 s = s + code [I] + "" + name [I] + "+ grade [I] +" \ n "; 182} 183 JOptionPane. showMessageDialog (null, s); 184} 185}

 

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.