Primary knowledge Java-score Entry system

Source: Internet
Author: User

Package classtest;

Import java.util.Scanner;

public class Scorearrangement {
/**
* Select Interface (main)
*/
public static void main (string[] Args) {
Scanner sc = new Scanner (system.in);
string[] name = new string[2];
string[] Password = new string[2];
int i = 0;//main function and register function, array subscript
While (true) {
System.out.println ("select menu");
System.out.print ("A, Registration B, Landing C, exit");
String choice = Sc.next ();
Switch (choice) {
Case "a":
Case "A":
if (name[1] = = Null) {
System.out.println (name[0] + "" + password[0]);
System.out.println (name[1] + "" + password[1]);
i = Register (name, password, i);
Break
} else {
System.out.println ("registered full! ");
Break
}
Case "b":
Case "B":
Denglu (name, password);
Break
Case "c":
Case "C":
System.out.println ("exit success");
System.exit (-1);
Break
Default
System.out.println ("invalid input, re-select! ");
Break
}
}
}

/**
* Registration
*/
public static int Register (string[] a, string[] b, int X) {
Scanner sc = new Scanner (system.in);
System.out.print ("please Enter User name:");
a[x] = Sc.next ();
System.out.println ("please Enter password:");
b[x] = Sc.next ();
System.out.println ("registered successfully, User name:" + a[x] + "password:" + b[x]);
X + +;
Return x;
}

/**
* Login
*/
public static void Denglu (string[] a, string[] b) {

Scanner sc = new Scanner (system.in);
int times = 0;
System.out.println (a[0] + "" + b[0]);
System.out.println (a[1] + "" + b[1]);
While (times < 3) {
System.out.print ("please Enter User name:");
String name = Sc.next ();
System.out.println ("please Enter password:");
String Password = sc.next ();
For (int x = 0; x < 2; × x + +) {
If (name.equals (a[x]) && password.equals (b[x])) {
Fenshuguanli ();
Times = 3;
Break
} else {
SYSTEM.OUT.PRINTLN ("user name or password is incorrect, Re-enter.") ");
times++;
if (times = = 3) {
System.out.println ("3 times Input error, exit! ");
System.exit (-1); If you need to stop running, add this line of Code.
}
Break
}
}
}
}

/**
* Score Management
*/
public static void Fenshuguanli () {
string[] name = new string[100];
double[] score = new double[100];
Scanner sc = new Scanner (system.in);
int index = 1;
int number = 0;//student name array subscript
While (index = = 1) {
System.out.println ("input selection:");
SYSTEM.OUT.PRINTLN ("1, Input Student Results. ");
System.out.println ("2, revise the student Achievement. ");
System.out.println ("3, Delete Student Results. ");
System.out.println ("4, Query Individual student Results. ");
System.out.println ("5), Check all student Grades. ");
System.out.println ("6, Average Score. ");
System.out.println ("7, return to parent Menu.) ");
int choice = Sc.nextint ();
Switch (choice) {
Case 1:
If (number==99) {
System.out.println ("the data is full and cannot continue to be entered. ");
Break
}
Number = Lurufenshu (name, score, number);
Break
Case 2:
Xiugaifenshu (name, score, number);
Break
Case 3:
Shanchufenshu (name,score,number);
Break
Case 4:
Chaxunfenshu (name, score);
Break
Case 5:
Chaxunall (name,score,number);
Break
Case 6:
Average (name,score,number);
Break
Case 7:
index = 0;
Break
Default
System.out.println ("invalid selection, Re-enter.") ");
Break
}
}
}

/**
* Input Score
*/
public static int Lurufenshu (string[] name, double[] score, int Number) {
If (number > 99) {
SYSTEM.OUT.PRINTLN ("insufficient Storage space, cannot Input!") Returns to the parent menu. ");
Return number;
}
System.out.println ("Welcome lurufenshu!");
Scanner sc = new Scanner (system.in);
int index = 0;
While (index = = 0) {
System.out.println ("please Enter Student's name:");
String userName = Sc.next ();
name[number] = userName;
System.out.println ("please Enter student score:");
Double Userscore = sc.nextdouble ();
score[number] = userscore;
System.out.println ("input Information success, whether continue to Enter?") y/n ");
int index1 = 0;
While (index1 = = 0) {
String choice = Sc.next ();
Switch (choice) {
Case "y":
Case "Y":
number++;
Index1 = 1;
Break
Case "n":
Case "N":
number++;
Return number;
Default
System.out.println ("invalid instruction, Please re-enter:");
Break
}
}
}
Return number;
}

/**
* Modify Score
*/
public static void Xiugaifenshu (string[] name, double[] score, int Number) {
System.out.println ("please Enter Student's name:");
Scanner sc = new Scanner (system.in);
If (name[0]! = Null) {
String userName = Sc.next ();
int i = 0;
For (i = 0; I < number; i++) {
If (name[i].equals (userName)) {
System.out.println ("please Enter the modified score:");
score[i] = sc.nextdouble ();
System.out.println ("modified successfully! "+ name[i] +" "+ score[i] +" min ");
Break
}
}
if (i = = Number) {
System.out.println ("no information for this Student!") ");
}
} else {
System.out.println ("the Database is empty, Please enter the data First!") ");
}
}

 /**
  * Delete scores
  */
 public static int Shanchufenshu (string[]name,double[]score,int Number) {
  scanner sc=new Scanner (system.in);
  system.out.println ("please Enter the Student's name to delete the score:");
  string Username=sc.next ();
  for (int i=0;i<=number;i++) {
   if (name[i].equals (userName) &&i==99) {
    system.out.println ("delete succeeded! ");
    name[i]=null;
    score[i]=0;
   }else if (name[i].equals (userName)) {
    system.out.println ("delete succeeded! ");
    name[i]=name[i+1];
    name[i+1]=null;
    score[i]=score[i+1];
    score[i]=0;
    number--;
   }
  }
  return number;
 }

 /**
  * Query single score
  */
 public static void Chaxunfenshu (string[] name, double[] score) { Br>  system.out.println ("please Enter Student's name:");
  scanner sc = new Scanner (system.in);
  string userName = Sc.next ();
  if (name[0]! = Null) {
   int i = 0;
   for (i = 0; i < name.length-1; i++) {
    if (name[i].equals (userName)) {
     system.out.println ("the Student's score is:" + score[i] + "points. ");
     break;
    }
   }
   if (i = = Name.length-1) {
    system.out.println ("no student Information!") ");
   }
  } Else {
   system.out.println ("the database is empty, Please enter the score First!") ");
  }
 }

/**
* Check ALL Scores
*/
public static void Chaxunall (string[]name,double[]score,int Number) {
If (name[0]! = Null) {
For (int I=0;i<number;i++) {
System.out.println (name[i]+ "," +score[i]+ ");
}
} else {
System.out.println ("the Database is empty, Please enter the results First!") ");
}
}

/**
* Calculate the average score
*/
public static void Average (string[]name,double[]score,int Number) {
Double averagescore=0;
Double sum=0;
For (int I=0;i<name.length-1;i++) {
sum+=score[i];
}
System.out.println ("average divided into:" +sum/(number+1));
}
}

Primary knowledge Java-score Entry system

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.