-
Code layout :)
This was my task write a program to take the computer programming grades of 8 IT students. The program should take the input of:
First names of Students and store them in an array
marks for ‘Computer Programming Assignment 1’ (out of 25 marks)
marks for ‘Computer Programming Assignment 2’ (out of 25 marks)
marks for ‘Computer Programming Exam’ (out of 50 marks)
Based on the above input, work out the ‘Final Grade’ for Computer Programming (Assignment 1 + Assignment 2 + Exam) and store it in an array.
Then work out
the average Final Grade for ‘Computer Programming’
the number of distinctions, merits, passes and fails for ‘Computer Programming’
The name and grade for each student.
"I would like to know could anyone improve the layout of the code because thers alot of marks going for that and i dont have a clue what the layout is supposed to look like and if you could see anything that could be improved upon let me know."
Code:
public class Assignment2 {
public static void main(String[] args) {
String student[] = new String[8];
int results[] = new int[8];
int assignment1;
int assignment2;
int exam;
int distinction = 0;
int merit = 0;
int pass = 0;
int fail = 0;
int sum=0;
int averagemark;
for(int j=0; j<8; j=j+1){
Screen.message("Please insert the student's name: ");
student[j] = Keyboard.readString();
Screen.message("Please put in the student's assignment1 result (out of 25 marks): ");
assignment1 = Keyboard.readInt();
Screen.message("Please put in the student's assignment2 result (out of 25 marks): ");
assignment2 = Keyboard.readInt();
Screen.message("Please insert the student's exam result (out of 50 marks):");
exam=Keyboard.readInt();
results[j]= assignment1 + assignment2 + exam;
sum+= results[j];
Screen.newline();
if (results[j]>100){
Screen.message("Show result as invalid");
}
else if (results[j]>= 80){
distinction += 1;
}
else if (results[j] >= 60){
merit += 1;
}
else if (results[j] >= 50){
pass += 1;
}
else if (results[j]<50){
fail += 1;
}
}
Screen.newline();
Screen.message("The amount of students that have received distinction is ");
Screen.writeint(distinction);
Screen.newline();
Screen.message("The amount of students that have received merit is ");
Screen.writeint(merit);
Screen.newline();
Screen.message("The amount of students that have received pass is ");
Screen.writeint(pass);
Screen.newline();
Screen.message("The amount of students that have failed is ");
Screen.writeint(fail);
averagemark = sum /8;
Screen.newline();
Screen.message("The average percentage of all of the students results is: ");
Screen.writeint(averagemark);
Screen.message("%");
Screen.newline();
Screen.message("The students average grade is: ");
if (averagemark >= 80){
Screen.message("Distinction");
}
else if (averagemark >= 60){
Screen.message("Merit");
}
else if (averagemark >=50){
Screen.message("Pass");
}
else if (averagemark<50){
Screen.message("Fail");
Screen.newline();
for ( int j = 0; j < results.length; j = j + 1){
Screen.newline();
Screen.message("Student Name: "+student[j]);
Screen.newline();
Screen.message("Student's Result: ");
Screen.writeint(results[j]);
Screen.message("% ");
Screen.newline();
Screen.message("Student's Grade: ");
if ( results[j] >= 80){
Screen.message("Distinction");
}
else if ( results[j] >= 60){
Screen.message("Merit");
}
else if ( results[j] >=50){
Screen.message("Pass");
}
else if (resluts[j]<50){
Screen.message("Fail");
}
Screen.newline();
}
}
}
-
First thing I would do would be to create OOP classes such as a Student class that holds a String for the student's name, an array of 25 ints for the marks, perhaps a String for Student ID. I'd give it a Constructor that accepts the name (and maybe the ID) and setter methods for the marks, etc...
-
How exactly would i do that i dont think i coverd that in my course or maybe i did and it just the way your phrasing it. Im still new to java and doing that assignment was hard for me.
-
Have you learned how to create classes that have non-static methods? You need to know this first before you can create a Student class.
-
Nope haven't learned about that yet,i only started OOP at the end of January i only do it 3 hour a week in my course. Would what your saying be hard to do?
-
Not hard, but you'll have to read up on the concepts before attempting to do it, that's all. The Sun tutorials have sections on creating classes and using OOPs. Give them a look.
-
Ok thanks ill give it a look now hopefully ill understand it :)