-3

I'm doing an assignment for uni, for which I have to create a class file (ProcessMarks.class) that will calculate the max, min, range, mode, median etc. from an array of 125 integers that have been provided to us by our Lecturer in a class called Marks.class, that generates an array of 125 'marks' between 0 and 100.

So far I'm stuck on multiple fronts for this assignment, however the main issue I'm having currently (which I'm sure is probably basic stuff but I still can't seem to get it to work), is I'm trying to get my ProcessMarks.class that I created to import and use the marks created in the Marks.class file and then to hold the results (of marks.class) to use as needed when a user wants to calculate Min, Max, Mean etc.

I cant get eclipse to allow me import the class to be used by my ProcessMarks.class; I just keep getting an error that it cant be resolved.

  • Do I need to put the Marks.java or Marks.class in a specific folder?

  • Should I just run the Marks.class, and then copy, paste and initialise the results manually?

  • Is there anything obvious that I'm missing or maybe some basic java fundamentals I'm not understanding properly?

Also I'm not looking for anyone to do the work for me, I just need to be pointed in the correct direction.

import java.util.Random;

/**
 * A class that provides a random array of marks,
 * approximately normally distributed.
 * @author Ken Lodge
 */

public class Marks {
    private static final int NMARKS = 125;
    private static final double mean = 65.0;
    private static final double std = 15.0;

    /**
     * Returns an array of NMARKS integer marks approximately normally distributed,
     * with specified mean (mean) and standard deviation (std),
     * and with values outside 0..100 removed.
     * @return the array of marks.
     */
    public static int[] getMarks() {
        Random rand = new Random(1001L);
        int mark;
        int[] theMarks = new int[NMARKS];
        int n = 0;
        while (n < NMARKS) {
            mark = (int) Math.round(std*rand.nextGaussian() + mean);
            if (mark >= 0 && mark <= 100)
                theMarks[n++] = mark;
        }
        return theMarks;
    }

    /**
     * Test code
     * @param args not used
     */
    public static void main(String[] args) {
        int[] testMarks = getMarks();
        for (int n = 0; n < testMarks.length; n++) {
            System.out.print(testMarks[n] + " ");
            if (n % 10 == 9)
                System.out.println();
        }
    }
}
Draken
  • 3,134
  • 13
  • 34
  • 54
Julian
  • 1
  • 4

1 Answers1

0

This should get you started, put it inside your ProcessMarks.java:

public class ProcessMarks(){
    public static void main(String[] args) {
        int[] marksArray = Marks.getMarks();
        //Do something with the marksArray 
    }
}

Your teacher has created it the class with static variables, that means we do not need to initialize it with the standard new Marks(); format. We can instead just called Marks.getMarks(); to get the data. This will return us 125 integers being generated by your professor's code.

Just make sure this ProcessMarks.java and Marks.java are in the same folder. I would suggest using an IDE to help you do the work as well, a common one is Eclipse.

Good luck!

[EDIT] Also read up here to learn the difference between class files and java files, you seem to be a little confused what the difference is

Community
  • 1
  • 1
Draken
  • 3,134
  • 13
  • 34
  • 54