0

I've managed to get the marks from the exam and coursework to add up together and get an average. I realized this is what needs to happen.

computed module mark = ((coursework mark * coursework weighting) + (examination mark * (100 - coursework weighting))) / 100

So, I need to make 2 arrays (if I'm correct), each having the weighting of each module, then do those calculations. How do I add an array to an array that already exists? This is what I have so far:

public static void main (String [] args)
{
    computeResults();
}
public static void part1 (){

    double examMarks [] = {50,40,60,80,70,11};
    double courseworkmarks [] = {65,49,58,77,35,40};

    System.out.println ("These are the exam marks and the course work marks");//First row is the exam marks, second row is the course work marks
    computeMarks (examMarks);
    computeMarks1 (courseworkmarks);

}
public static void computeMarks(double[] examMarks)
{
    for (int row=0;row<examMarks.length;row++){
            System.out.print (examMarks[row] +"\t");
        }
    System.out.println();
    }
public static void computeMarks1(double[] courseworkmarks)
{
    for (int row=0;row<courseworkmarks.length;row++){
            System.out.print (courseworkmarks[row] +"\t");
        }
    System.out.println();
    }
public static void computeResults()
{
     double examMarks [] = {50,40,60,80,70,11};
        double courseworkmarks [] = {65,49,58,77,35,40};

        double avgMarks[] =new double[examMarks.length];

        for(int i=0;i<avgMarks.length;i++){
            avgMarks[i]=(examMarks[i]+courseworkmarks[i])/2;

        System.out.println(avgMarks[i]);
        }
}

}

2
  • I think you're adding two arrays correctly in that last for loop in computeResults. What is it that you are facing an issue with? Are you getting some error? Or an unexpected result? Commented Nov 8, 2013 at 5:58
  • i got the average instead of the total of all them and return it for each, now i need to get the total of that, add all 6 different results and produce a result out of 100, for like an overall mark for a full year Commented Nov 8, 2013 at 6:11

1 Answer 1

2

It would be nice like this:

public static void main (String [] args)
{
    double examMarks [] = {50,40,60,80,70,11};
    double courseworkmarks [] = {65,49,58,77,35,40};
    System.out.println ("These are the exam marks and the course work marks");//First row is the exam marks, second row is the course work marks
    computeMarks (examMarks);
    computeMarks1 (courseworkmarks);
    System.out.println ("These are the final marks");
    computeResults(examMarks, courseworkmarks);
}

public static void computeMarks(double[] examMarks)
{
    for (int row=0;row<examMarks.length;row++){
            System.out.print (examMarks[row] +"\t");
        }
    System.out.println();
    }
public static void computeMarks1(double[] courseworkmarks)
{
    for (int row=0;row<courseworkmarks.length;row++){
            System.out.print (courseworkmarks[row] +"\t");
        }
    System.out.println("\n");
    }


public static void computeResults(double[] examMarks, double[] courseworkmarks)
{

        double avgMarks[] =new double[examMarks.length];

        for(int i=0;i<avgMarks.length;i++){
        int cwWeighting=40;
            avgMarks[i]=(examMarks[i]*(100-cwWeighting)+courseworkmarks[i]*cwWeighting)/100;

        System.out.print (avgMarks[i] +"\t");
        }
}
Sign up to request clarification or add additional context in comments.

8 Comments

1 more question, is there any way i could make a short cut for the 2 arrays that i have? like they are in Part1, and computeMarks method. is there a way to make a shortcut? so i dont have to change both when i need the marks to change? (just answer on this thread)
Are you saying you want to read them in from a file or something? If so, that's a new question entirely, and you might like to either post it as a new question, or have a look around at the plethora of similar questions that already exist on this site.
thanks man, that was great. it made it much simpler and neater :D
i added a few more codes in there, for it to print out the title of what the numbers meant. thanks again for your help
1 more thing, im sorry to bother you again.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.