CSCI 255 — Programming Expectations

This lab gives an example of the programming expertise needed for this course. If you have a lot of trouble with this assignment, you may need to do a bit of review.

The task

You can use either NetBeans or Processing for this lab. In either case, you will be given driver code that calls an exceeds method. The exceeds method takes two arguments: The first is an array of integers, and the second is an integer. The exceeds method returns the number of elements of the array that are greater than the second argument. For example, all of the following calls should return 1.
    exceeds(new int[]{-100000, 2016}, 150)
    exceeds(new int[]{150, 2016}, 150)
    exceeds(new int[]{2016}, 150)

The only difference between the pure Java and Processing implementations is that the public static modifier is required in Java. (The Processing IDE inserts the appropriate modifier into your code before passing it to the Java compiler.)

Either Or

The Java route

Start up NetBeans and create a project for a Java Application. Use the project and class names of your choice.

Delete the default main method and replace it with the following:

    public static void main(String[] args) {
        java.util.Random g = new java.util.Random() ;
        int X[] = new int[1000 + g.nextInt(10)] ;
        for (int i = 0; i<X.length; ++i) {
            X[i] = g.nextInt(10) ;
        }
        System.out.println(exceeds(X, 3)) ;
        System.out.println(exceeds(X, 7)) ;
        System.out.println(exceeds(new int[]{}, 2015)) ;
     }

The Processing route

Start up Processing with the following program.

void setup() {
  noLoop() ;
}

void draw()
{
  java.util.Random g = new java.util.Random() ;
  int X[] = new int[1000 + g.nextInt(10)] ;
  for (int i = 0; i<X.length; ++i) {
    X[i] = g.nextInt(10) ;
   }
   println(exceeds(X, 3)) ;
   println(exceeds(X, 7)) ;
   println(exceeds(new int[]{}, 2015)) ;
}

Writing and testing the missing method

Whatever your choice, implement the missing exceeds method. You may consult the internet, but write this method on your own. When appropriate the lab instructor will provide hints to the entire class to make sure we leave on time.

When run, this problem should print three numbers. The first should be close to 600, the second should be close to 200, and the third should be 0.

Show the lab instructor the result of your program’s execution.