This assignment is about loops 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, . It contains three methods. You have to write the code that goes inside them.
The first method finds the average of the elements of an integer array:
public double average(int[] data)
That is, given an integer array, data, calculate what the average of its elements are and 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, arrayAdd, takes two arrays as parameters and returns a new array that is the sum of the first two.
public int[] arrayAdd(int[] R1, int[] R2)
The addition of two arrays yields an array whose elements are the sum of the corresponding elements in the parameter arrays, i.e.
R1[0] + R2[0], R1[1] + R2[1], R1[2] + R2[2], ....
R1 and R2 must be of equal length. Your code must test that they are the same length and output an error message, e.g. “The arrays must be the same length”.
You will submit your assignment to the Give automated marked system.
================================================Checking your submission...Checking for Assignment1.javaAssignment1.java Compiled SucessfullyAll files are OK================================================
Submission notes:
Each week, we will post several short quiz questions to encourage you to do some preparation before the lab. The intention of the quizzes is to give you quick feedback so that you know if you understand the material in the course so far and to encourage you to prepare for the labs by reading over the lecture material from the previous weeks.
You should attempt the quizzes in your own time before the lab and bring your answers to your tutor, who will give you feedback. For now, quizzes are voluntary and we hope you’ll try them.
This week’s quiz is .
This week’s lab exercises are concerned with data types, which were introduced in last week’s lectures. You should attempt the exercises below using the project for BlueJ.
What data type would you use to represent the following values? Why?
What are the value and type of the following expressions? Work these out on paper and then test your answers by typing them into the Code Pad in BlueJ. Can you explain the result?
The circleArea method in the Tut3 class calculates the area of a circle with a given radius.
If there are five people Alan, Bel, Cameron, Dan, and Emily in the room and they each have to shake hands with everyone else, how many handshakes occur? What if there were 10 people? What if there were only two? Work out a general formula.
Complete the ‘handshakes’ method in the Tut3 project to use your formula to compute the number of handshakes for a given size group.
For more complicated mathematical expressions, Java has a lot of built in methods in the Math class. Take a look at the to see what is available. Try typing the following
in CodePad. Explain the results.
Assume we have declared an integer variable x. Write an if-statement that will print “one” if the value of x is 1, “two” if the value of x is 2 and “something else” if the value x is some other value.
There are three tasks for this week’s lab:
The first thing we will do in this week’s lab is activate your CSE account, if you haven’t done so already.
This is an exercise in breaking down a task into a sequence of simple instructions. Work in pairs. Your tutor will give each of you a small, incomplete pack of cards.
Experiment with the BlueJ projects we saw in lectures.
This course introduces you to the foundations of the programming discipline, which underlies most technical subjects such as software design, data management and algorithms. It will involve both a theoretical component (e.g. learning about basic programming concepts like loops, arrays and functions) as well as a practical component (e.g. implementing simple algorithms in a computer laboratory). The course also provides a first step towards learning the principles of object-oriented design and programming through the use of the Java programming language.
The course is suitable for students with no prior programming experience. It is particularly targeted at IS students as it relates to a number of core concepts that are essential in understanding the technologies behind information systems in business without getting overmuch into low-level technical details.
All students should ensure they have read the .
To clarify, you may not bring an A4 sheet of reference notes into the written exam. This exam is different to the practical ones. If you need to know specific details from the class libraries, the documentation will be provided in the exam.
We do however assume that you remember the fundamental and commonly used methods for ArrayList’s
Assignment 3 marks and tutor comments can be collected from the
Assignment 2 marks and tutor comments can be collected from the
The Weekly Quizzes held in labs have been and are also linked from the side bar.
Marks for the mid-semester practical exam can be accessed at: .
INFS Students will need to enter “COMP1400” for the course code.
This page also contains marks for labs, quiz’s and assignments. However please note that not all marks have been uploaded.
Update: Your marked exam can now be collected from the . Select “midsem” from the list of assignments and press “Collect my assignment”. INFS Students will need to enter “COMP1400” for the course code.
Don’t forget that the prac exam will be held in the regular lab times in week 13. This is compulsory and comprises 20% of your marks. It will have the same format as the mid-semester prac exam, except that you’ll have the full two hours.
Like the mid-semester exam, you will be allowed to bring one A4 page of notes to help you.