Java – how can I use my program to solve these problems? (many problems were explained internally)
This question is not suitable for timid people and takes time
I'm learning Java. I want to know if someone can tell me what I did wrong and how to solve it through my program so that I can learn
My entire program (if needed): http://pastie.org/private/xpbgpypetvfmivcs88gbcq
Allocation:
Edit:
Oh! Hi Sorry, I still know how to do all this: (well, here are
The program is not compiled, and I'm sure it depends on my logic (and some syntactic things)
The problems I encountered are: 1) how to pass all parameters to each different method, as shown here What I want to do is let me return all the values, such as answerkey, studentanswers, numericgrade, average, etc., so that I can use them and print them out But I don't know what to do
int[] numericGrade = computeNumericGrade(answerKey,studentAnswers); int[] letterGrade = computeLetterGrade(numericGrade); double average = average(numericGrade); int gradeTally = gradeTally(letterGrade); int studentCount = studentCount(numericGrade);
2) I can't figure out how to check each t or F value individually and check whether it corresponds to t or F in the answer key, as shown below
What I want to do is check each letter of a specific element. If the value is "correct" or = = to answerkey, add the total number to the numericgrade of the element
public static int[] computeNumericGrade(int[] answerKey,int[] studentAnswers) { int[] numericGrade = new int[50]; int total = 0; for(int i = 0; i < 50;i++) { for(int a = 0;a == 10;a++) { total = studentAnswers[i].charAt(a); if(total == answerKey[i]) numericGrade[i]++; } } return numericGrade; }
3) I don't know how to return all these different values because I need all of them above! I want this set of code to check the letter level of each element. If this element is found, then the corresponding variable, so I know how many letter levels are called
public static int gradeTally(String[] letterGrade) { int a,b,c,d,f = 0; for(int i = 0;i < letterGrade.length;i++) { if(letterGrade[i] == 'A') a++; else if (letterGrade[i] == 'B') b++; else if (letterGrade[i] == 'C') c++; else if (letterGrade[i] == 'D') d++; else if (letterGrade[i] == 'F') f++; } return a + b + c + d + f; }
4) I can't figure it out... I think I'm close Here, I'm trying to read the file, tag it, and then add it to array 1 for each tag However, I don't think this is correct, but I can't check because I can't compile
public static String[] getData() throws IOException { int[] studentID = new int[50]; String[] studentAnswers = new String[50]; int total = 0; String line = reader.readLine(); strTkn = new StringTokenizer(line); String answerKey = strTkn.nextToken(); while(line != null) { studentID[total] = Integer.parseInt(strTkn.nextToken()); studentAnswers[total] = strTkn.nextToken(); totaL++; } return studentAnswers; }
I'm editing my post now I hope this is enough:)
Solution
I guess you realize from the comments that it's a little difficult to help
I'm not sure how helpful it will be, but I'd like to provide some general tips on how to deal with this problem
First, I might throw away what you have and start over I never regret discarding code - in the long run, it can always help your code, and you'll learn a lot the second time
Second, start small Do something useful - even if it just reads in values and proves that they are read in correctly, then expand it Test frequently Whenever you add code, add a line to the test to ensure that the new code works the same as all previous code
That way, if there's any damage, you'll know exactly what broke it - the last thing you edit
To do this quick test, you should learn to use JUnit for unit testing, or use the main test for testing, so that you can click a button and get the answer immediately JUnit is really not difficult. It's built into eclipse. Oh, yes, next hint
Use eclipse or NetBeans!
These are things experienced programmers automatically know and do Spending a little time and energy from the beginning can save a lot of pain