| | |
Program compiles but has runtime problems
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2006
Posts: 3
Reputation:
Solved Threads: 0
I would not be posting right now if it weren't for the fact that I've exausted my resources and have no where else to turn for a solution.
First of all, let me give you guys a .class file, that when compiled, does exactly what my program is -supposed- to do.
finished program
Now that you know what my program is supposed to do, here is the program I have:
If you throw that into your compiler, it will compile, but gives several runtime errors resulting in a crash.. What happens is that when I get to the "Entering scores for test", the test numbers do not show up correctly. It prints out the student report inproperly and does not print out the test report at all, it just crashes.
First of all, let me give you guys a .class file, that when compiled, does exactly what my program is -supposed- to do.
finished program
Now that you know what my program is supposed to do, here is the program I have:
Java Syntax (Toggle Plain Text)
import static java.lang.System.out; import java.util.Scanner; public class StuTest { private static Scanner keyboard = new Scanner(System.in); public static void main(String[] args) { int[][] testScores; // [students][tests] String[] stuNames; testScores = createArray(); if(testScores != null) { stuNames = new String[testScores.length]; populateNames(stuNames); populateTestScores(stuNames,testScores); printStudentReport(stuNames,testScores); printTestReport(stuNames,testScores); out.println("\n\nGoodbye!\n\n"); } else { out.println("Array not successfully created - exiting"); } } // Code your 5 methods below.. // Ask user to enter the number of students, and then asks user to enter the number of tests. private static int numberOfStudents; private static int numberOfTests; public static int[][] createArray() { System.out.print("Enter the number of students: "); numberOfStudents = keyboard.nextInt(); System.out.print("Enter the number of tests: "); numberOfTests = keyboard.nextInt(); System.out.println(); System.out.println(); int[][] stuArray = new int[numberOfStudents][numberOfTests]; return stuArray; } // Ask for the name of each student for each number of students public static String[] populateNames(String[] stuNames) { for(int x = 0; x < stuNames.length; x++) { System.out.print("Enter the name for student " + (x + 1) + ": "); keyboard = new Scanner(System.in); stuNames[x] = keyboard.nextLine(); } return stuNames; } // Display "Entering Scores for (Student Name)" then input the score for each test. public static int[][] populateTestScores(String[] stuNames, int[][] testScores) { for(int y = 0; y < stuNames.length; y++) { for(int u = 0; u < stuNames.length; u++) { System.out.println("Entering scores for " + stuNames[y]); System.out.print(" Enter score for Test " + testScores + ": "); testScores[y][u] = keyboard.nextInt(); } } return testScores; } // Print Student Report public static void printStudentReport(String[] stuNames, int[][] testScores) { // Print the name of each student and the scores for each of the student's tests System.out.println("STUDENT REPORT"); for(int z = 1; z <= stuNames.length; z++) { System.out.println("Report for " + stuNames[z]); for(int a = 1; a <= numberOfTests; a++) { System.out.println(" Test " + a + ": " + testScores[a][z]); } // Print the average of the student's tests int p = 0; for(int o = 1; o <= testScores.length; o++) { p += testScores[o][z]; } p /= testScores.length; System.out.println(" " + stuNames[z] + "'s average is " + p); } // Print Test Report } public static void printTestReport(String[] stuNames, int[][] testScores) { System.out.println("TEST REPORT"); // Print the results for each individual test, and the average for each test for(int b = 1; b <= testScores.length; b++) { System.out.println("Report for Test" + b); for(int c = 1; c <= numberOfStudents; c++) { System.out.println(" Test " + c + ": " + testScores[c][b]); } int p = 0; for(int o = 1; o <= testScores.length; o++) { p += testScores[o][b]; } p /= testScores.length; System.out.println(" Test" + b + " average is " + p); } } }
If you throw that into your compiler, it will compile, but gives several runtime errors resulting in a crash.. What happens is that when I get to the "Entering scores for test", the test numbers do not show up correctly. It prints out the student report inproperly and does not print out the test report at all, it just crashes.
•
•
Join Date: Feb 2006
Posts: 3
Reputation:
Solved Threads: 0
Well it might take awhile to explain, the best and easiest thing for you and me would be to take a look at the .class file I have and then compile the code I have and compare the two. But I will try to explain... What it does is ask for the number of students, and then the number of tests. Then it should ask for the names of each student. Then it asks for the test scores for each student. After that, it gives a student report which has the scores and average for each individual, and then a test report that has the scores and average for each test.
no, the best way is for you to think about your problems yourself.
If you're too lazy to even try to explain what is going wrong why should anyone go to the effort (especially unpaid) to analyse your problems for you?
If you're too lazy to even try to explain what is going wrong why should anyone go to the effort (especially unpaid) to analyse your problems for you?
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
•
•
Join Date: Feb 2006
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by jwenting
no, the best way is for you to think about your problems yourself.
If you're too lazy to even try to explain what is going wrong why should anyone go to the effort (especially unpaid) to analyse your problems for you?
•
•
•
•
Originally Posted by yuribokovich221
If you throw that into your compiler, it will compile, but gives several runtime errors resulting in a crash.. What happens is that when I get to the "Entering scores for test", the test numbers do not show up correctly. It prints out the student report inproperly and does not print out the test report at all, it just crashes.
![]() |
Similar Threads
- g++ allegro linking (C++)
- Program Compiles fine, but error upon Running (Java)
- Visual C++ program compiles, but won't run (C++)
- problem with my program!! (C++)
Other Threads in the Java Forum
- Previous Thread: Stack- need help
- Next Thread: need some help
| Thread Tools | Search this Thread |
Tag cloud for Java
-xlint 2dgraphics android api apple applet application applications arguments array arrays automation bank binary bluetooth chat class classes client code collision component database db development draw eclipse eclipsedevelopment error event exception file fractal game givemetehcodez graphics gui helpwithhomework homework html ide image input integer integration j2me jarfile java javadesktopapplications javafx javaprojects jmf jni jpanel julia learningresources linux list loop map method methods mobile netbeans newbie number object oracle print problem program programming project projectideas recursion researchinmotion scanner screen server service set size sms socket sort sorting sql sqlserver state string swing swt tcp test text-file threads time tree web windows






