@matfah/

Student Record FR 2005

Java

No description

fork
loading
Files
  • Main.java
  • StudentRecord.java

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.921323549772159","path":"Main.java","file":{"path":"Main.java","content":{"asEncoding":{"base64":"aW1wb3J0IGphdmEubGFuZy5yZWZsZWN0Lio7CmltcG9ydCBqYXZhLnV0aWwuQXJyYXlMaXN0OwoKcHVibGljIGNsYXNzIE1haW4gewogIAogIAogIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgIHRlc3RBdmVyYWdlKCk7CiAgICBTeXN0ZW0ub3V0LnByaW50bG4oImF2ZXJhZ2UoKSBtZXRob2Qgd29ya3MhIik7CiAgICB0ZXN0SGFzSW1wcm92ZWQoKTsKICAgIFN5c3RlbS5vdXQucHJpbnRsbigiaGFzSW1wcm92ZWQoKSBtZXRob2Qgd29ya3MhIik7CiAgICB0ZXN0RmluYWxBdmVyYWdlKCk7CiAgICBTeXN0ZW0ub3V0LnByaW50bG4oImZpbmFsQXZlcmFnZSgpIG1ldGhvZCB3b3JrcyEhIik7CiAgICAKICAgIFN5c3RlbS5vdXQucHJpbnRsbigiQWxsIHRlc3RzIHBhc3NlZCEiKTsKICB9CiAgCiAgcHVibGljIHN0YXRpYyB2b2lkIHRlc3RBdmVyYWdlKCkgewogICAgCiAgICBTdHVkZW50UmVjb3JkIHJlYyA9IG5ldyBTdHVkZW50UmVjb3JkKCk7CiAgICAKICAgIEZpZWxkIHNjb3Jlc0ZpZWxkID0gbnVsbDsKICAgIHRyeSB7CiAgICAgIHNjb3Jlc0ZpZWxkID0gU3R1ZGVudFJlY29yZC5jbGFzcy5nZXREZWNsYXJlZEZpZWxkKCJzY29yZXMiKTsKICAgIH0KICAgIGNhdGNoKEV4Y2VwdGlvbiBlKSB7CiAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiRGlkIHlvdSByZW1vdmUgdGhlIHNjb3JlcyBpbnN0YW5jZSB2YXJpYWJsZT8hIik7CiAgICAgIFN5c3RlbS5leGl0KDApOwogICAgfQogICAgc2NvcmVzRmllbGQuc2V0QWNjZXNzaWJsZSh0cnVlKTsKICAgIAogICAgZm9yKGludCBpID0gMTsgaSA8PSAxMDsgaSsrKSB7CiAgICAgIGludFtdIHNjb3JlcyA9IG5ldyBpbnRbaV07CiAgICAgIAogICAgICBmb3IoaW50IGogPSAwOyBqIDwgaTsgaisrKQogICAgICAgIHNjb3Jlc1tqXSA9IChpbnQpKE1hdGgucmFuZG9tKCkqMjApIC0gMTA7CiAgICAgICAgCiAgICAgIGZvcihpbnQgZmlyc3QgPSAwOyBmaXJzdCA8IGk7IGZpcnN0KyspIHsKICAgICAgICBmb3IoaW50IGxhc3QgPSBmaXJzdDsgbGFzdCA8IGk7IGxhc3QrKykgewogICAgICAgICAgCiAgICAgICAgICB0cnkgewogICAgICAgICAgICBzY29yZXNGaWVsZC5zZXQocmVjLCBzY29yZXMuY2xvbmUoKSk7CiAgICAgICAgICB9CiAgICAgICAgICBjYXRjaChFeGNlcHRpb24gZSkgewogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIlRoZSBzY29yZXMgaW5zdGFuY2UgdmFyaWFibGUgaXMgbm90IGFuIGludFtdLi4uPyIpOwogICAgICAgICAgICBTeXN0ZW0uZXhpdCgwKTsKICAgICAgICAgIH0KICAgICAgICAgIAoKICAgICAgICAgIGRvdWJsZSByZXN1bHQgPSAwLjA7CiAgICAgICAgICBkb3VibGUgY29weVJlc3VsdCA9IDAuMDsKICAgICAgCiAgICAgICAgICB0cnkgewogICAgICAgICAgICBjb3B5UmVzdWx0ID0gcmVzdWx0ID0gcmVjLmF2ZXJhZ2UoZmlyc3QsIGxhc3QpOwogICAgICAgICAgfQogICAgICAgICAgY2F0Y2goRXhjZXB0aW9uIGUpIHsKICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJUaGUgYXZlcmFnZSgpIG1ldGhvZCBjcmFzaGVzIHdoZW4gY2FsbGVkISIpOwogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIiBzY29yZXM6ICIgKyBqYXZhLnV0aWwuQXJyYXlzLnRvU3RyaW5nKHNjb3JlcykpOwogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIiBmaXJzdDogIiArIGZpcnN0KTsKICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCIgbGFzdDogIiArIGxhc3QpOwogICAgICAgICAgICBTeXN0ZW0uZXhpdCgwKTsKICAgICAgICAgIH0KICAgIAogICAgICAgICAgcmVzdWx0ICo9IChsYXN0IC0gZmlyc3QgKyAxKTsKICAgICAgICAgIGZvcihpbnQgayA9IGZpcnN0OyBrIDw9IGxhc3Q7IGsrKykKICAgICAgICAgICAgcmVzdWx0LT0gc2NvcmVzW2tdOwogICAgICAgICAgICAKICAgICAgICAgIGlmKE1hdGguYWJzKHJlc3VsdCkgPj0gMC4wMDAxKSB7CiAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiUmVzdWx0IG9mIGF2ZXJhZ2UoKSBpcyBub3QgY29ycmVjdCIpOwogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIiBzY29yZXM6ICIgKyBqYXZhLnV0aWwuQXJyYXlzLnRvU3RyaW5nKHNjb3JlcykpOwogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIiBmaXJzdDogIiArIGZpcnN0KTsKICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCIgbGFzdDogIiArIGxhc3QpOwogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIiByZXN1bHQ6ICIgKyBjb3B5UmVzdWx0KTsKICAgICAgICAgICAgU3lzdGVtLmV4aXQoMCk7CiAgICAgICAgICB9CiAgICAgICAgICAKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIAogIH0KICAKICBwdWJsaWMgc3RhdGljIHZvaWQgdGVzdEhhc0ltcHJvdmVkKCk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gICBzY29yZXNGaWVsZC5zZXRBY2Nlc3NpYmxlKHRydWUpOwogICAgCiAgICBmb3IoaW50IGkgPSAxOyBpIDw9IDEwOyBpKyspIHsKICAgICAgaW50W10gc2NvcmVzID0gbmV3IGludFtpXTsKICAgICAgCiAgICAgIGJvb2xlYW4gaW1wcm92ZWQgPSB0cnVlOwogICAgICBmb3IoaW50IGogPSAwOyBqIDwgaTsgaisrKSB7CiAgICAgICAgc2NvcmVzW2pdID0gKGludCkoTWF0aC5yYW5kb20oKSozKTsKICAgICAgICBpbXByb3ZlZCA9IGltcHJvdmVkICYmIChqID09IDAgfHwgc2NvcmVzW2pdID49IHNjb3Jlc1tqLTFdKTsKICAgICAgfQogICAgICAgIAoKICAgICAgWm9tYmllU3R1ZGVudFJlY29yZCByZWMgPSBuZXcgWm9tYmllU3R1ZGVudFJlY29yZCgpOwogICAgICAKICAgICAgdHJ5IHsKICAgICAgICBzY29yZXNGaWVsZC5zZXQocmVjLCBzY29yZXMuY2xvbmUoKSk7CiAgICAgIH0KICAgICAgY2F0Y2goRXhjZXB0aW9uIGUpIHsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIlRoZSBzY29yZXMgaW5zdGFuY2UgdmFyaWFibGUgaXMgbm90IGFuIGludFtdLi4uPyIpOwogICAgICAgIFN5c3RlbS5leGl0KDApOwogICAgICB9CiAgICAgIAoKICAgICAgZG91YmxlIHJlc3VsdCA9IDAuMDsKICAKICAgICAgdHJ5IHsKICAgICAgICByZXN1bHQgPSByZWMuZmluYWxBdmVyYWdlKCk7CiAgICAgIH0KICAgICAgY2F0Y2goRXhjZXB0aW9uIGUpIHsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIlRoZSBmaW5hbEF2ZXJhZ2UoKSBtZXRob2QgY3Jhc2hlcyB3aGVuIGNhbGxlZCEiKTsKICAgICAgICBTeXN0ZW0uZXhpdCgwKTsKICAgICAgfQoKICAgICAgaWYocmVjLmZpcnN0LnNpemUoKT09MCB8fC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
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
import java.lang.reflect.*;
import java.util.ArrayList;

public class Main {
  
  
  public static void main(String[] args) {
    testAverage();
    System.out.println("average() method works!");
    testHasImproved();
    System.out.println("hasImproved() method works!");
    testFinalAverage();
    System.out.println("finalAverage() method works!!");
    
    System.out.println("All tests passed!");
  }
  
  public static void testAverage() {
    
    StudentRecord rec = new StudentRecord();
    
    Field scoresField = null;
    try {
      scoresField = StudentRecord.class.getDeclaredField("scores");
    }
    catch(Exception e) {
      System.out.println("Did you remove the scores instance variable?!");
      System.exit(0);
    }
    scoresField.setAccessible(true);
    
    for(int i = 1; i <= 10; i++) {
      int[] scores = new int[i];
      
      for(int j = 0; j < i; j++)
        scores[j] = (int)(Math.random()*20) - 10;
        
      for(int first = 0; first < i; first++) {
        for(int last = first; last < i; last++) {
          
          try {
            scoresField.set(rec, scores.clone());
          }
          catch(Exception e) {
            System.out.println("The scores instance variable is not an int[]...?");
            System.exit(0);
          }
          

          double result = 0.0;
          double copyResult = 0.0;
      
          try {
            copyResult = result = rec.average(first, last);
          }
          catch(Exception e) {
            System.out.println("The average() method crashes when called!");
            System.out.println(" scores: " + java.util.Arrays.toString(scores));
            System.out.println(" first: " + first);
            System.out.println(" last: " + last);
            System.exit(0);
          }
    
          result *= (last - first + 1);
          for(int k = first; k <= last; k++)
            result-= scores[k];
            
          if(Math.abs(result) >= 0.0001) {
            System.out.println("Result of average() is not correct");
            System.out.println(" scores: " + java.util.Arrays.toString(scores));
            System.out.println(" first: " + first);
            System.out.println(" last: " + last);
            System.out.println(" result: " + copyResult);
            System.exit(0);
          }
          
        }
      }
    }
    
  }
  
  public static void testHasImproved() {
     StudentRecord rec = new StudentRecord();
    
    Field scoresField = null;
    try {
      scoresField = StudentRecord.class.getDeclaredField("scores");
    }
    catch(Exception e) {
      System.out.println("Did you remove the scores instance variable?!");
      System.exit(0);
    }
    scoresField.setAccessible(true);
    
    for(int i = 1; i <= 10; i++) {
      int[] scores = new int[i];
      
      boolean answer = true;
      for(int j = 0; j < i; j++) {
        scores[j] = (int)(Math.random()*3);
        answer = answer && (j == 0 || scores[j] >= scores[j-1]);
      }
      try {
        scoresField.set(rec, scores.clone());
      }
      catch(Exception e) {
        System.out.println("The scores instance variable is not an int[]...?");
        System.exit(0);
      }
      
      boolean result = false;
      try {
        result = rec.hasImproved();
      }
      catch(Exception e) {
        System.out.println("The hasImproved() method crashes when called!");
        System.out.println(" scores: " + java.util.Arrays.toString(scores));
        System.exit(0);
      }
      
      if(result != answer) {
        System.out.println("Result of hasImproved() is not correct");
        System.out.println(" scores: " + java.util.Arrays.toString(scores));
        System.out.println(" result: " + result);
        System.exit(0);
      }
      
    }
  }
  
  public static void testFinalAverage() {
    
    Field scoresField = null;
    try {
      scoresField = StudentRecord.class.getDeclaredField("scores");
    }
    catch(Exception e) {
      System.out.println("Did you remove the scores instance variable?!");
      System.exit(0);
    }
    scoresField.setAccessible(true);
    
    for(int i = 1; i <= 10; i++) {
      int[] scores = new int[i];
      
      boolean improved = true;
      for(int j = 0; j < i; j++) {
        scores[j] = (int)(Math.random()*3);
        improved = improved && (j == 0 || scores[j] >= scores[j-1]);
      }
        

      ZombieStudentRecord rec = new ZombieStudentRecord();
      
      try {
        scoresField.set(rec, scores.clone());
      }
      catch(Exception e) {
        System.out.println("The scores instance variable is not an int[]...?");
        System.exit(0);
      }
      

      double result = 0.0;
  
      try {
        result = rec.finalAverage();
      }
      catch(Exception e) {
        System.out.println("The finalAverage() method crashes when called!");
        System.exit(0);
      }

      if(rec.first.size()==0 || rec.last.size()==0 || rec.hasImproved == null) {
        System.out.println("Required methods not called in finalAverage()");
        System.exit(0);
      }
      
      int[] params;
      if(improved) {
        params = new int[]{scores.length/2, scores.length-1};
      }
      else {
        params = new int[]{0, scores.length-1};
      }
      
      boolean failed = true;
      for(int m = 0; m < rec.first.size(); m++) {
        if(rec.first.get(m) == params[0] && rec.last.get(m) == params[1]) {
          failed = false;
          break;
        }
      }
      
      if(failed) {
         System.out.println("Inside finalAverage(), call to average() with correct parameters is not made");
         System.exit(0);
      }
      
      double sum = 0.0;
      for(int n = params[0]; n <= params[1]; n++) {
        sum += scores[n];
      }
      sum /= (params[1] - params[0] + 1);
      
      if(Math.abs(sum - result) >= 0.0001) {
        System.out.println("Result of finalAverage() is not correct");
        System.out.println(" scores: " + java.util.Arrays.toString(scores));
        System.out.println(" result: " + result);
        System.exit(0);
      }
          
  
    }
  }
}

class ZombieStudentRecord extends StudentRecord {
  
  ArrayList<Integer> first = new ArrayList<Integer>();
  ArrayList<Integer> last = new ArrayList<Integer>();
  Boolean hasImproved = null;
  
  public double average(int first, int last) {
    this.first.add(first);
    this.last.add(last);
    return super.average(first, last);
  }
  
  public boolean hasImproved() {
    hasImproved = true;
    return super.hasImproved();
  }
}