jackyhuichunkit

Parallel Arrays and Records

Feb 10th, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.28 KB | None | 0 0
  1. class parallelarrays {
  2.  
  3.     public static int[] SID = new int[100];
  4.     public static String[] SNAME = new String[100];
  5.     public static int[] MTH = new int[100];
  6.     public static int[] ENG = new int[100];
  7.     public static int[] CHI = new int[100];
  8.     public static int N=-1;
  9.  
  10.     public static void main(String[] args) {
  11.         insertStudent(123, "JACKY");
  12.         insertStudent(231, "JASPER");
  13.         insertStudent(333, "TOMMY");
  14.         insertStudent(787, "ISAAC");
  15.         insertStudent(999, "DENNIS");
  16.         updateMTH(999, 85);
  17.     }
  18.  
  19.     public static void insertStudent(int stuid, String sname) {
  20.         N++;
  21.         if (N<100) {
  22.             SID[N] = stuid;
  23.             SNAME[N] = sname;
  24.             MTH[N] = 0;
  25.             ENG[N] = 0;
  26.             CHI[N] = 0;
  27.         }
  28.     }
  29.  
  30.     public static boolean updateName(int stuid, String sname) {
  31.         int id;
  32.         boolean result;
  33.         id = searchByStuid(stuid);
  34.         if (id != -1) {
  35.             SNAME[id] = sname;
  36.             result = true;
  37.         } else {
  38.             result = false;
  39.         }
  40.         return result;
  41.     }
  42.  
  43.     public static int searchByStuid(int stuid) {
  44.         int id=-1;
  45.         int i = 0;
  46.         while (i<100 && id==-1) {
  47.             if (SID[i] == stuid) {
  48.                 id = i;
  49.             }
  50.             i++;
  51.         }
  52.         return i;
  53.     }
  54.  
  55.     public static boolean updateMTH(int stuid, int mark) {
  56.         int id;
  57.         boolean result;
  58.         id = searchByStuid(stuid);
  59.         if (id != -1) {
  60.             MTH[id] = mark;
  61.             result = true;
  62.         } else {
  63.             result = false;
  64.         }
  65.         return result;
  66.     }
  67.  
  68.     public static boolean updateCHI(int stuid, int mark) {
  69.         int id;
  70.         boolean result;
  71.         id = searchByStuid(stuid);
  72.         if (id != -1) {
  73.             CHI[id] = mark;
  74.             result = true;
  75.         } else {
  76.             result = false;
  77.         }
  78.         return result;
  79.     }
  80.  
  81.     public static boolean updateENG(int stuid, int mark) {
  82.         int id;
  83.         boolean result;
  84.         id = searchByStuid(stuid);
  85.         if (id != -1) {
  86.             ENG[id] = mark;
  87.             result = true;
  88.         } else {
  89.             result = false;
  90.         }
  91.         return result;
  92.     }
  93.  
  94. }
Add Comment
Please, Sign In to add comment