COMP1400 – Programming for Designers

Class announcements for Programming for Designers

COMP1400 – Programming for Designers random header image

Assignment 1

Posted by on August 6th, 2012 · Assignments

Due: 11:59pm Friday 17 August (i.e. the end of week 5)

This assignment is about arrays. You will write three methods to manipulate arrays. The first two are easy. The third one will require more thought about the design. You will submit the assignment using the CSE give system (see below).

Download the BlueJ project, Assignment1.zip. It contains three methods. You have to write the code that goes inside them.

The fist method finds the average of the elements of an integer array:

public double average(int[] data)

That is, given an integer array, data, calculate the average of its elements are return the average value. For example, the average of {1, 3, 2, 5, 8} is 3.8.

The second method is:

public int countInRange(int[] data, int lo, int hi)

For this, you have to count the number of elements of the array, data, that lie in the range lo to hi inclusive, and return the count. For example, if data is the array {1, 3, 2, 5, 8} then the call

countInRange(data, 2, 5)

should return 3 because there are three elements, 3, 2 and 5 that lie in the range 2 .. 5.

The third method is:

public int mode(int[] R)

This calculates the mode of the array elements. The mode is the value that occurs most frequently. For example the mode of the array

{1, 43, 12, 56, 88, 1, 12, 90, 90, 12, 1, 1, 1, 12, 90, 12, 12, 78}

is 12 because the value 12 occurs 5 times in the array, which is more than any other value. Note that, in general, the mode may not be unique as it is possible that more than one value will occur with the same frequency. However, for this assignment, we will assume that the mode will be unique, i.e. there will only be one value with the highest occurrence.

HINT: You can assume that the values in the area are limited to the range 1 .. maxValue, where maxValue is some positive integer, like 10 or 100. This assumption allows you to do the counting relatively easily with clever use of arrays.

Submission instructions

You will submit your assignment to the Give automated marked system.

  1. From within your assignment 1 BlueJ project, select Project -> Create Jar File…
  2. In the Dialog Box that appears:
    1. Set “Main Class” to none
    2. Ensure “Include Source” is checked
    3. Leave “Include Bluej project files” unchecked
    4. Press “Continue
    5. Save the filename as “assignment1.jar
  3. Open a web browser and go to the give web site
    1. Log-in with your Z-Pass
    2. Enter “COMP1400″ in for the course and press “Search for Assignments”.
    3. Select “Assignment1″ from the next drop down menu and press “Upload my Assignment
    4. Accept the student declaration
    5. Press “Choose File” and select the “assignment1.jar” file that you saved in step 4
    6. Press “Submit my Files
    7. Wait for the page to completely load. Then carefully read the output. If the assignment is successful you should see the following lines:

      Checking your submission...
      Checking for relevant classes...
      All files are OK

      If the page doesn’t load properly, that is OK just submit the assignment file again.
      If you see the final line, everything is good. Otherwise check the output to see what went wrong and resubmit.

Submission notes:

You can submit as many times as you wish, even after the deadline. Only your last submission will be marked.
Make sure you name everything the as instructed, including the classes and the submission file or the submission will not work.
If you have any problems with submission, email the class account

No Comments so far ↓

There are no comments yet...Kick things off by filling out the form below.

You must log in to post a comment.