Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class parallelarrays {
- public static int[] SID = new int[100];
- public static String[] SNAME = new String[100];
- public static int[] MTH = new int[100];
- public static int[] ENG = new int[100];
- public static int[] CHI = new int[100];
- public static int N=-1;
- public static void main(String[] args) {
- insertStudent(123, "JACKY");
- insertStudent(231, "JASPER");
- insertStudent(333, "TOMMY");
- insertStudent(787, "ISAAC");
- insertStudent(999, "DENNIS");
- updateMTH(999, 85);
- }
- public static void insertStudent(int stuid, String sname) {
- N++;
- if (N<100) {
- SID[N] = stuid;
- SNAME[N] = sname;
- MTH[N] = 0;
- ENG[N] = 0;
- CHI[N] = 0;
- }
- }
- public static boolean updateName(int stuid, String sname) {
- int id;
- boolean result;
- id = searchByStuid(stuid);
- if (id != -1) {
- SNAME[id] = sname;
- result = true;
- } else {
- result = false;
- }
- return result;
- }
- public static int searchByStuid(int stuid) {
- int id=-1;
- int i = 0;
- while (i<100 && id==-1) {
- if (SID[i] == stuid) {
- id = i;
- }
- i++;
- }
- return i;
- }
- public static boolean updateMTH(int stuid, int mark) {
- int id;
- boolean result;
- id = searchByStuid(stuid);
- if (id != -1) {
- MTH[id] = mark;
- result = true;
- } else {
- result = false;
- }
- return result;
- }
- public static boolean updateCHI(int stuid, int mark) {
- int id;
- boolean result;
- id = searchByStuid(stuid);
- if (id != -1) {
- CHI[id] = mark;
- result = true;
- } else {
- result = false;
- }
- return result;
- }
- public static boolean updateENG(int stuid, int mark) {
- int id;
- boolean result;
- id = searchByStuid(stuid);
- if (id != -1) {
- ENG[id] = mark;
- result = true;
- } else {
- result = false;
- }
- return result;
- }
- }
Add Comment
Please, Sign In to add comment