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.

Results 1 to 5 of 5

Thread: Java help

  1. #1
    Member
    Join Date
    Nov 2013
    Posts
    51
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Java help

    Hey,

    This is assessed work, so please don't provide any answers. Just some guidance towards where i'm going wrong.

    The first part of my code is just user input ect which asks the user to input their coursework weight, module grade and exam grade.
    	[B]public String[] computeMarks(int[] marks) {
     
    		final int[] WEIGHTING = { 60, 40, 50, 40,30, 20 };
    		String[] results = new String[WEIGHTING.length];
    		for (int i = 0; i < marks.length / 2; i++) {
     
    			int exam = marks[i+6];
    			int cw = marks[i+6];
    			int weight = WEIGHTING[i];
    			int formula = ((cw + weight) + (exam * (100 - weight)) / 100);
     
    			if (formula >= 40){
    				results[i]="PASS";
    			} else if ((formula < 39) && (formula > 35)){
    				results[i]="COMPENSATION PASS";
    			}else{
    				results[i]="FAIL";
     
    			}
     
    		}
     
    	}
    }
     
    [/B]

    At the top of all this way above i also have

    static int[] marks = new int[12];



    The program runs and asks the student for their grades and weighting. However once the user inputs all then the program terminates. I don't know why it doesn't state whether they've passed, failed or passed with computation.

    --- Update ---

    anyone...


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Java help

    Try adding a test print to find out what the value of formula is before the series of if statements. Then, if you can't figure out why the value of formula is not what you expect, come back with the details and we'll work that.

  3. #3
    Member
    Join Date
    Nov 2013
    Posts
    51
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Java help

    Quote Originally Posted by GregBrannon View Post
    Try adding a test print to find out what the value of formula is before the series of if statements. Then, if you can't figure out why the value of formula is not what you expect, come back with the details and we'll work that.
    Sorry, I don't really understand you. The formula outcome will purely depend on 'x' numbers, so how am i supposed to work out a specific value ? I've got no set numbers, the program is supposed to run using all numbers 1%-100%. My bad if i'm chatting completely off topic from what you meant to say

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Java help

    What Greg is saying is to use println's to debug your code. You do this by printing out values, running the code to see what it prints, and if it doesn't print what you expect (or anything at all) backtrack upwards in the code to add more println's and/or figure out what went wrong.

    See http://www.javaprogrammingforums.com...t-println.html

  5. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Java help

    copeg explained my point just fine, but here's more detail:
    public String[] computeMarks(int[] marks)
    {
        final int[] WEIGHTING = { 60, 40, 50, 40,30, 20 };
        String[] results = new String[WEIGHTING.length];
        for (int i = 0; i < marks.length / 2; i++) {
     
            int exam = marks[i+6];
            int cw = marks[i+6];
            int weight = WEIGHTING[i];
            int formula = ((cw + weight) + (exam * (100 - weight)) / 100);
     
            // GB: my suggestion is to add a print statement here to see what
            // 'formua' is before the if statements:
            System.out.println( "formula = " + formula );
     
            // GB: I believe your original question is "why don't these
            // if statements provide results? knowing what 'formula' is
            // with the preceding print statement should give you some
            // insight
            if (formula >= 40)
            {
                results[i]="PASS";
            } else if ((formula < 39) && (formula > 35)){
                results[i]="COMPENSATION PASS";
            }else{
                results[i]="FAIL";
     
            }
     
        }
     
    }