i dont know whats the problem with this linee
public static void displayfailedStudents (String[] name, double[] caMark, double[] ctMark, double[] asgMark, double[] finalMark)
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
i dont know whats the problem with this linee
public static void displayfailedStudents (String[] name, double[] caMark, double[] ctMark, double[] asgMark, double[] finalMark)
...The reason why the compiler is off on the line number is because the compiler ignores white spaces (except when counting line numbers!). So as the compiler moves along your code, it encounters that extra closing curly brace, moves to the next line, and BAM, now it is confused. Well it didn't realize confusion til it was on the next line where your next method name starts, so that is the line number it reports back to you where a problem was found. Well in this case (and quite frequently) the preceeding line could have been valid, depending on what the next line is.
Nw i got 1 error in line 115
/*================================================================================== * FSP 2012 Assignment * Student ID : S10122534C * Student Name : Leonard Laura Rachel M * Module Group : FI05 * * ==================================================================================*/ import java.util.Scanner; public class S10122534c_Assignment { public static void main(String[] args) { final int MAXSIZE = 50; // maximum number of students String[] name = new String[MAXSIZE]; // array to store the names of the students double[] caMark = new double[MAXSIZE]; // array to store the Continuous Assessment marks double[] ctMark = new double[MAXSIZE]; // array to store the Common Test marks double[] asgMark = new double[MAXSIZE]; // array to store the Assignment marks double[] finalMark = new double [MAXSIZE]; // array to store the Final marks int count = 0; Scanner input = new Scanner(System.in); // initialize the array with students count = initialization(name, caMark, ctMark, asgMark,finalMark); int choice; finalMark = calculatefinalMark( count, caMark, ctMark, asgMark ); do { choice = input.nextInt(); switch (choice) { case 1: displayStudentResults( name, caMark, ctMark, asgMark, finalMark, count);break; case 2: diplayFailedStudents( name, caMark, ctMark, asgMark, finalMark, count);break; case 3: addNewStudent(count);break; case 4: updateMarks( asgMark, count);break; case 5: exit();break; default:System.out.print("Thank you."); } }while (choice != 0); } // method to initialize the arrays with students public static int initialization(String[] name, double[] caMark, double[] ctMark, double[] asgMark, double[] finalMark) { name [0] = "Agnes Tan"; caMark [0] = 75; ctMark [0] = 68; asgMark [0] = 82; name [1] = "Benny Ong"; caMark [1] = 66; ctMark [1] = 30; asgMark [1] = 35; name [2] = "Denise Ng"; caMark[2] = 55; ctMark [2] = 42; asgMark [2] = 50; name [3] = "Jimmy Tay"; caMark [3] = 80; ctMark [3] = 76; asgMark[3] = 82; name [4] = "Evelyn Low"; caMark [4] = 70; ctMark [4] = 60; asgMark [4] = 65; return 5; } public static void displayMenu() { String[] nameArr; double[] caMarkArr; double[] ctMarkArr; double[] asgMarkArr; double[] finalMarkArr; { System.out.println ("MENU"); System.out.println ("========================================"); System.out.println (" [1]. Display the results of all students"); System.out.println (" [2]. Display the students who have failed"); System.out.println (" [3]. Add a new student"); System.out.println (" [4]. Update assignment mark of a student"); System.out.println (" [0]. Exit"); System.out.println ("Enter your option: _____ "); System.out.println ("========================================="); } } public static void displayStudentResults(String[] nameArr, double[] caMarkArr, double[] ctMarkArr, double[] asgMarkArr, double[] finalMarkArr) { int [] numArr = new int[50]; System.out.println("Student Name" + "CA" + "CT" + "ASG" + "FINAL" + "GRADE"); for (int i=0; i<numArr.length; i++) { System.out.println(nameArr[i] + caMarkArr[i] + ctMarkArr[i] + asgMarkArr[i] + finalMarkArr[i]); numArr[i]=i+1; } } //Calculate Final marks to compute whether the student has passed & to know the grades public static double calculatefinalMark(int count, double[] caMark, double[] ctMark, double[] asgMark) { int a = count; finalMark = (0.4 * caMark[a]) + (0.3 * ctMark[a]) + (0.3 * asgMark[a]); System.out.print(finalMark); count++; return finalMark; } public static void displayfailedStudents (String[] name, double[] caMark, double[] ctMark, double[] asgMark, double[] finalMark) { System.out.println("No" + "Student Name" + "CA" + "CT" + "ASG" + "FINAL" + "GRADE"); for (int l=0; l<count; l++) { if (finalMark < 50) System.out.print(name[l], caMark[l], ctMark[l], asgMark[l], finalMark[l]); } public static void addNewStudent(int count) { System.out.println("Option 3: Add New Student"); System.out.println("Enter Student Name: "); String name = input.next(); System.out.println("Enter CA Marks: "); double caMark = input.nextDouble(); System.out.println("Enter CT Marks: "); double ctMark = input.nextDouble(); System.out.println("Enter ASG Marks: "); double asgMark = input.nextDouble(); System.out.println("One Student Added."); count++; } public static void updateMarks(int count, double asgMark) { int i = count; System.out.println("Option 4: Update Assignment Mark of a Student: "); System.out.println("Enter the serial number of the student to update : "); i = input.nextInt(); System.out.println("Enter new assignment mark : "); double asgMark = input.nextDouble(); System.out.println("The assignment mark is updated. "); asgMark[count-1] = asgMark; } public static char gradeMark( double finalMark) { char gradeMark = 0; if (finalMark >=80) System.out.println("Grade A"); if ((finalMark >=70) && (finalMark < 80)) System.out.println("Grade B"); if ((finalMark >=60) && (finalMark < 70)) System.out.println("Grade C"); if ((finalMark >= 50) && (finalMark < 60)) System.out.println("Grade D"); if (finalMark < 50) System.out.println("Grade F"); return gradeMark; } }
S10122534c_Assignment.java:115: illegal start of expression
public static void addNewStudent(int count)
^
1 error
What this error message is trying to tell you is:
Before you finished the definition of your method named displayfailedStudents, you started an illegal expression. In this case you started to define another method. In short that extra curly brace you had earlier, actually belongs at this point! There is a curly brace missing that closes off the previous method block. Another example of how the compiler is not real sure which line is in error. You can just count the given line number as a pointer to where the compiler was working when the compiler realized things are not in place, and not an indication of the exact location of the problem.
/*================================================================================== * FSP 2012 Assignment * Student ID : S10122534C * Student Name : Leonard Laura Rachel M * Module Group : FI05 * * ==================================================================================*/ import java.util.Scanner; public class S10122534c_Assignment { public static void main(String[] args) { final int MAXSIZE = 50; // maximum number of students String[] name = new String[MAXSIZE]; // array to store the names of the students double[] caMark = new double[MAXSIZE]; // array to store the Continuous Assessment marks double[] ctMark = new double[MAXSIZE]; // array to store the Common Test marks double[] asgMark = new double[MAXSIZE]; // array to store the Assignment marks double[] finalMark = new double [MAXSIZE]; // array to store the Final marks int count = 0; Scanner input = new Scanner(System.in); // initialize the array with students count = initialization(name, caMark, ctMark, asgMark,finalMark); int choice; finalMark = calculatefinalMark( count, caMark, ctMark, asgMark ); do { choice = input.nextInt(); switch (choice) { case 1: displayStudentResults( name, caMark, ctMark, asgMark, finalMark, count);break; case 2: diplayFailedStudents( name, caMark, ctMark, asgMark, finalMark, count);break; case 3: addNewStudent(count);break; case 4: updateMarks( asgMark, count);break; case 5: exit();break; default:System.out.print("Thank you."); } }while (choice != 0); } // method to initialize the arrays with students public static int initialization(String[] name, double[] caMark, double[] ctMark, double[] asgMark, double[] finalMark) { name [0] = "Agnes Tan"; caMark [0] = 75; ctMark [0] = 68; asgMark [0] = 82; name [1] = "Benny Ong"; caMark [1] = 66; ctMark [1] = 30; asgMark [1] = 35; name [2] = "Denise Ng"; caMark[2] = 55; ctMark [2] = 42; asgMark [2] = 50; name [3] = "Jimmy Tay"; caMark [3] = 80; ctMark [3] = 76; asgMark[3] = 82; name [4] = "Evelyn Low"; caMark [4] = 70; ctMark [4] = 60; asgMark [4] = 65; return 5; } public static void displayMenu() { String[] nameArr; double[] caMarkArr; double[] ctMarkArr; double[] asgMarkArr; double[] finalMarkArr; { System.out.println ("MENU"); System.out.println ("========================================"); System.out.println (" [1]. Display the results of all students"); System.out.println (" [2]. Display the students who have failed"); System.out.println (" [3]. Add a new student"); System.out.println (" [4]. Update assignment mark of a student"); System.out.println (" [0]. Exit"); System.out.println ("Enter your option: _____ "); System.out.println ("========================================="); } } public static void displayStudentResults(String[] nameArr, double[] caMarkArr, double[] ctMarkArr, double[] asgMarkArr, double[] finalMarkArr) { int [] numArr = new int[50]; System.out.println("Student Name" + "CA" + "CT" + "ASG" + "FINAL" + "GRADE"); for (int i=0; i<numArr.length; i++) { System.out.println(nameArr[i] + caMarkArr[i] + ctMarkArr[i] + asgMarkArr[i] + finalMarkArr[i]); numArr[i]=i+1; } } //Calculate Final marks to compute whether the student has passed & to know the grades public static double calculatefinalMark(int count, double[] caMark, double[] ctMark, double[] asgMark) { int a = count; finalMark = (0.4 * caMark[a]) + (0.3 * ctMark[a]) + (0.3 * asgMark[a]); System.out.print(finalMark); count++; return finalMark; } public static void displayfailedStudents (String[] name, double[] caMark, double[] ctMark, double[] asgMark, double[] finalMark) { System.out.println("No" + "Student Name" + "CA" + "CT" + "ASG" + "FINAL" + "GRADE"); for (int l=0; l<count; l++) if (finalMark < 50) System.out.print(name[l], caMark[l], ctMark[l], asgMark[l], finalMark[l]); } public static void addNewStudent(int count) { System.out.println("Option 3: Add New Student"); System.out.println("Enter Student Name: "); String name = input.next(); System.out.println("Enter CA Marks: "); double caMark = input.nextDouble(); System.out.println("Enter CT Marks: "); double ctMark = input.nextDouble(); System.out.println("Enter ASG Marks: "); double asgMark = input.nextDouble(); System.out.println("One Student Added."); count++; } public static void updateMarks(int count, double asgMark) { int i = count; System.out.println("Option 4: Update Assignment Mark of a Student: "); System.out.println("Enter the serial number of the student to update : "); i = input.nextInt(); System.out.println("Enter new assignment mark : "); double asgMark = input.nextDouble(); System.out.println("The assignment mark is updated. "); asgMark[count-1] = asgMark; } public static char gradeMark( double finalMark) { char gradeMark = 0; if (finalMark >=80) System.out.println("Grade A"); if ((finalMark >=70) && (finalMark < 80)) System.out.println("Grade B"); if ((finalMark >=60) && (finalMark < 70)) System.out.println("Grade C"); if ((finalMark >= 50) && (finalMark < 60)) System.out.println("Grade D"); if (finalMark < 50) System.out.println("Grade F"); return gradeMark; } }
back to line 26 wit te error dude?
I dunno whats happening???
S10122534c_Assignment.java:26: cannot find symbol
symbol : variable calculatefinalMark
location: class S10122534c_Assignment
calculatefinalMark = calculatefinalMark( count, caMark, ctMark, asgMark );
^
S10122534c_Assignment.java:31: displayStudentResults(java.lang.String[],double[],double[],double[],double[]) in S10122534c_Assignment cannot be applied to (java.lang.String[],double[],double[],double[],double[],int)
{ case 1: displayStudentResults( name, caMark, ctMark, asgMark, finalMark, count);break;
^
S10122534c_Assignment.java:32: cannot find symbol
symbol : method diplayFailedStudents(java.lang.String[],double[],double[],double[],double[],int)
location: class S10122534c_Assignment
case 2: diplayFailedStudents( name, caMark, ctMark, asgMark, finalMark, count);break;
^
S10122534c_Assignment.java:34: updateMarks(int,double) in S10122534c_Assignment cannot be applied to (double[],int)
case 4: updateMarks( asgMark, count);break;
^
S10122534c_Assignment.java:35: cannot find symbol
symbol : method exit()
location: class S10122534c_Assignment
case 5: exit();break;
^
S10122534c_Assignment.java:99: cannot find symbol
symbol : variable finalMark
location: class S10122534c_Assignment
finalMark = (0.4 * caMark[a]) + (0.3 * ctMark[a]) + (0.3 * asgMark[a]);
^
S10122534c_Assignment.java:100: cannot find symbol
symbol : variable finalMark
location: class S10122534c_Assignment
System.out.print(finalMark);
^
S10122534c_Assignment.java:102: cannot find symbol
symbol : variable finalMark
location: class S10122534c_Assignment
return finalMark;
^
S10122534c_Assignment.java:108: cannot find symbol
symbol : variable count
location: class S10122534c_Assignment
for (int l=0; l<count; l++)
^
S10122534c_Assignment.java:112: operator < cannot be applied to double[],int
if (finalMark < 50)
^
S10122534c_Assignment.java:113: cannot find symbol
symbol : method print(java.lang.String,double,double,double,double )
location: class java.io.PrintStream
System.out.print(name[l], caMark[l], ctMark[l], asgMark[l], finalMark[l]);
^
S10122534c_Assignment.java:121: cannot find symbol
symbol : variable input
location: class S10122534c_Assignment
String name = input.next();
^
S10122534c_Assignment.java:123: cannot find symbol
symbol : variable input
location: class S10122534c_Assignment
double caMark = input.nextDouble();
^
S10122534c_Assignment.java:125: cannot find symbol
symbol : variable input
location: class S10122534c_Assignment
double ctMark = input.nextDouble();
^
S10122534c_Assignment.java:127: cannot find symbol
symbol : variable input
location: class S10122534c_Assignment
double asgMark = input.nextDouble();
^
S10122534c_Assignment.java:135: cannot find symbol
symbol : variable input
location: class S10122534c_Assignment
i = input.nextInt();
^
S10122534c_Assignment.java:137: asgMark is already defined in updateMarks(int,double)
double asgMark = input.nextDouble();
^
S10122534c_Assignment.java:137: cannot find symbol
symbol : variable input
location: class S10122534c_Assignment
double asgMark = input.nextDouble();
^
S10122534c_Assignment.java:139: array required, but double found
asgMark[count-1] = asgMark;
^
19 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation comple
You are making progress... You have already corrected a list of errors. There are many more still. However still, treat them one at a time for the reasons stated in my post#53.
Sometimes the compiler gets confused and decides to quit before listing all of the errors. Sometimes the compiler THINKS there are multiple errors because of just one error. Do not get discouraged because the number of errors go up or down when you make changes. Every change you make causes the compiler to look at your new code from a new perspective. Take the first error, and fix it. Do not let those silly numbers or your deadline discourage you.
Now I'll have a look at your code and post again....
as of your code posted in post#82:
Line#26:your variable finalMark was declared as type double[] on line#20.finalMark = calculatefinalMark( count, caMark, ctMark, asgMark );
you are assigning the return value of the method calculatefinalMark to the varaible finalMark.
The return value of this method is double, not double[]. The compiler does not know what you meant to do. Did you mean to store a double in one index of your array finalMark? Did you mean to return an array of doubles from the method?
so what should it be instead?
That is a question for the author of the code I'm afraid. What is the method supposed to do?
Looking at your code I would say you had intended to store the return value into one index of the array. It looks like your method calculates the value of the final mark for one student. I would say you should determine which student you are working with, one at a time, and get their final mark from your method, and save it in your finalMark array in the corresponding studend's index. But you wrote the program, you would know best what you meant to do.
I really dont know mann!
yes..i intend to get their final mark from method and save it finalMark..
But i dont know how to do it?
I really appreciate your helpp.
But i really need to get my program to work
Could you like get to the point?
Im sorry mann
Im rushing for time now
There are multiple ways to solve this...
One way would be to loop through one at a time passing the necessary data to your calculatefinalMark method, getting the return value and storing it in your finalMark array.
That is probably the way I would go. That seems to be the way you intended for it to work. Judging by the method...
Now you have to think more about the problem at hand, and less about the error.
If you want to calculate the final mark for one student, what is required?
Well you would need to know which student and all of the marks needed to calculate his/her final mark. In your current method you pass in a reference to the array with all of the students' marks. This is a bit more overhead than you need for a method to do some math. You would only need to pass in the marks for the student in question at that time. So my suggestion would be to loop through your students name array, and for each student, use the index value of your loop to get the student's marks from each of the arrays, send them off to calculatefinalMark, and use the same index number to store the return in your finalMark array. This way student name[0] will correspond to finalMark[0].
so far you have corrected many errors, but many more exist. Its too bad you put this off for so long and are now almost out of time. The best advice I have for you is to keep making the progress you have since your first post. Take one error at a time, and fix it. That is the process we all have to go through. I will be here for a while to keep offering help. Give that method a few thoughts and see what you come up with.
There really is no "point" to get to. Of all the errors you have so far fixed, I got to the point for each of them. I pointed out your code, quoted the related error messages, explained what the error messages meant, and pointed you in the right direction for fixing the errors. Short of rewinding time for you there is not much more I can do to help you.
can you giv me one example dude with agnes tan nam[0] and finalMark[0]
its similar to what i've done right..
but i dont know how to store it in the array
theArray[theIndex] = aMethod(<the method's args here>); // store what method returns in an array
If you don't understand my answer, don't ignore it, ask a question.
well the problem is you are not currently accessing your array one element at a time. So far you have only used every array as an entire set, and never individually. You need to set up a loop to go through each element first. Then work on each element
is it this way
[case=java]
/*================================================= =================================
* FSP 2012 Assignment
* Student ID : S10122534C
* Student Name : Leonard Laura Rachel M
* Module Group : FI05
*
* ================================================== ================================*/
import java.util.Scanner;
public class S10122534c_Assignment
{
public static void main(String[] args)
{
final int MAXSIZE = 50; // maximum number of students
String[] name = new String[MAXSIZE]; // array to store the names of the students
double[] caMark = new double[MAXSIZE]; // array to store the Continuous Assessment marks
double[] ctMark = new double[MAXSIZE]; // array to store the Common Test marks
double[] asgMark = new double[MAXSIZE]; // array to store the Assignment marks
double[] finalMark = new double [MAXSIZE]; // array to store the Final marks
int count = 0;
Scanner input = new Scanner(System.in);
// initialize the array with students
count = initialization(name, caMark, ctMark, asgMark,finalMark);
int choice;
do
{
choice = input.nextInt();
switch (choice)
{ case 1: displayStudentResults( name, caMark, ctMark, asgMark, finalMark[0],finalMark[1],finalMark[2],finalMark[3],finalMark[4], count);break;
case 2: diplayFailedStudents( name, caMark, ctMark, asgMark, finalMark, count);break;
case 3: addNewStudent(count);break;
case 4: updateMarks( asgMark, count);break;
case 5: exit();break;
default:System.out.print("Thank you.");
}
}while (choice != 0);
}
// method to initialize the arrays with students
public static int initialization(String[] name, double[] caMark, double[] ctMark, double[] asgMark, double[] finalMark)
{
name [0] = "Agnes Tan";
caMark [0] = 75;
ctMark [0] = 68;
asgMark [0] = 82;
name [1] = "Benny Ong";
caMark [1] = 66;
ctMark [1] = 30;
asgMark [1] = 35;
name [2] = "Denise Ng";
caMark[2] = 55;
ctMark [2] = 42;
asgMark [2] = 50;
name [3] = "Jimmy Tay";
caMark [3] = 80;
ctMark [3] = 76;
asgMark[3] = 82;
name [4] = "Evelyn Low";
caMark [4] = 70;
ctMark [4] = 60;
asgMark [4] = 65;
return 5;
}
public static void displayMenu()
{
String[] nameArr; double[] caMarkArr; double[] ctMarkArr; double[] asgMarkArr; double[] finalMarkArr;
{
System.out.println ("MENU");
System.out.println ("========================================");
System.out.println (" [1]. Display the results of all students");
System.out.println (" [2]. Display the students who have failed");
System.out.println (" [3]. Add a new student");
System.out.println (" [4]. Update assignment mark of a student");
System.out.println (" [0]. Exit");
System.out.println ("Enter your option: _____ ");
System.out.println ("=========================================");
}
}
public static void displayStudentResults(String[] nameArr, double[] caMarkArr, double[] ctMarkArr, double[] asgMarkArr, double[] finalMarkArr)
{ int [] numArr = new int[50];
System.out.println("Student Name" + "CA" + "CT" + "ASG" + "FINAL" + "GRADE");
for (int i=0; i<numArr.length; i++)
{ System.out.println(nameArr[i] + caMarkArr[i] + ctMarkArr[i] + asgMarkArr[i] + finalMarkArr[i]);
numArr[i]=i+1;
}
}
//Calculate Final marks to compute whether the student has passed & to know the grades
public static double calculatefinalMark(int count, double[] caMark, double[] ctMark, double[] asgMark)
{
{
int a = count;
finalMark[0] = (0.4 * caMark[a]) + (0.3 * ctMark[a]) + (0.3 * asgMark[a]);
System.out.print(finalMark);
count++;
return finalMark[0];
}
{
int b=count;
finalMark[1]= (0.4 * caMark[b]) + (0.3 * ctMark[b]) + (0.3 * asgMark[b]);
System.out.print (finalMark);
count++;
return finalMark[1];
}
{
int c =count;
finalMark[2]= (0.4 * caMark[c]) + (0.3 * ctMark[c]) + (0.3 * asgMark[c]);
System.out.print (finalMark);
count++;
return finalMark[2];
}
{
intd=count;
finalMark[3]= (0.4 * caMark[d]) + (0.3 * ctMark[d]) + (0.3 * asgMark[d]);
System.out.print (finalMark);
count++;
return finalMark[3];
}
{
inte=count;
finalMark[4]= (0.4 * caMark[e]) + (0.3 * ctMark[e]) + (0.3 * asgMark[e]);
System.out.print (finalMark);
count++;
return finalMark[4];
}
{
name[0]= finalMark[0];
name[1]= finalMark[1];
name[2]= finalMark[2];
name[3]= finalMark[3];
name[4]= finalMark[4];
}
}
public static void displayfailedStudents (String[] name, double[] caMark, double[] ctMark, double[] asgMark, double[] finalMark)
{
System.out.println("No" + "Student Name" + "CA" + "CT" + "ASG" + "FINAL" + "GRADE");
for (int l=0; l<count; l++)
if (finalMark < 50)
System.out.print(name[l], caMark[l], ctMark[l], asgMark[l], finalMark[l]);
}
public static void addNewStudent(int count)
{
System.out.println("Option 3: Add New Student");
System.out.println("Enter Student Name: ");
String name = input.next();
System.out.println("Enter CA Marks: ");
double caMark = input.nextDouble();
System.out.println("Enter CT Marks: ");
double ctMark = input.nextDouble();
System.out.println("Enter ASG Marks: ");
double asgMark = input.nextDouble();
System.out.println("One Student Added.");
count++;
}
public static void updateMarks(int count, double asgMark)
{ int i = count;
System.out.println("Option 4: Update Assignment Mark of a Student: ");
System.out.println("Enter the serial number of the student to update : ");
i = input.nextInt();
System.out.println("Enter new assignment mark : ");
double asgMark = input.nextDouble();
System.out.println("The assignment mark is updated. ");
asgMark[count-1] = asgMark;
}
public static char gradeMark( double finalMark)
{
char gradeMark = 0;
if (finalMark >=80)
System.out.println("Grade A");
if ((finalMark >=70) && (finalMark < 80))
System.out.println("Grade B");
if ((finalMark >=60) && (finalMark < 70))
System.out.println("Grade C");
if ((finalMark >= 50) && (finalMark < 60))
System.out.println("Grade D");
if (finalMark < 50)
System.out.println("Grade F");
return gradeMark;
}
}
[/case]