Results 1 to 7 of 7

Thread: Code layout :)

  1. #1
    javaNoob2 is offline Member
    Join Date
    Feb 2009
    Posts
    13
    Rep Power
    0

    Smile 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."



    Java 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();
    
    }
    
        			
        		
        }
        
    }
    Last edited by javaNoob2; 03-30-2009 at 07:02 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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...

  3. #3
    javaNoob2 is offline Member
    Join Date
    Feb 2009
    Posts
    13
    Rep Power
    0

    Default

    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.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  5. #5
    javaNoob2 is offline Member
    Join Date
    Feb 2009
    Posts
    13
    Rep Power
    0

    Default

    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?

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  7. #7
    javaNoob2 is offline Member
    Join Date
    Feb 2009
    Posts
    13
    Rep Power
    0

    Default

    Ok thanks ill give it a look now hopefully ill understand it :)

Similar Threads

  1. Java GUI layout
    By nick2price in forum New To Java
    Replies: 2
    Last Post: 05-27-2008, 10:42 PM
  2. Border Layout
    By mark-mlt in forum Java Applets
    Replies: 5
    Last Post: 05-12-2008, 10:48 AM
  3. Help with Grid Layout
    By coco in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 09:03 PM
  4. Use the Layout in java
    By lenny in forum AWT / Swing
    Replies: 2
    Last Post: 07-26-2007, 08:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •