Codingassignmenthelper | Home Codingassignmenthelper | University

Assignment Lab 20127

Assignment :


The BlueJ project that you work on, once it is ready for submission, should look something like the following screenshot taken from the private model solution of the instructor, except that you need to submit only ten labs of your choice instead of all nineteen. (Of course the boxes representing the individual classes can be positioned any which way inside your project window.)

Image1

Each of these labs is worth the same two points of your total course grade. For the labs that ask you to write a Swing component, these two marks are given for these components passing the visual inspection of the behaviour specified in the lab. The other labs must cleanly pass the entire JUnit tester to receive the two points for that lab. These two points are all or nothing for that lab, and no partial marks whatsoever are given for labs that do not not pass these tests. Since you have a total of now fifteen labs to choose your ten labs from, choose the labs that you are able to get to work.

To compensate for this strict policy of correctness, all the labs have the same deadline of one day before the finl exam. Before that day, there is no real rush to complete any lab, so you can take your time to get each lab to work smoothly so that it will pass the JUnit tests. You can then simply come to each lab session to work on and get help for whichever lab you are currently working on, to make the most efficient use of your time. However, please do not . Any lab that prints anything at all on the console during the execution will be unconditionally rejected and receive a zero mark.

You may not modify the JUnit testers provided by the instructor in any way whatsoever, but your classes must pass these tests exactly the way that your instructor wrote them. Once you have completed all the labs that you think you are going to complete before deadline, you will submit all your completed labs in one swoop as the entire "Labs" BlueJ project folder that contains all the source files and the provided JUnit testers, compressed into a zip file that you upload into the assignment tab on D2L. Even if you write your labs working on Eclipse or some other IDE, it is compulsory to submit these labs as a single BlueJ project folder. No other form of submission is acceptable.


Lab 0(A): Arrays and Arithmetic

Inside your fresh new BlueJ project, create the first class that must be named exactly P2J1. Erase the nonsense template that BlueJ fills inside the class body in its misguided effort to "help" you, and in its place, write the following four methods.


public static long fallingPower(int n, int k)

Python has the integer exponentiation operator ** conveniently built in the language, whereas Java unfortunately does not have that operator. (In both languages, the caret character ^ denotes bitwise exclusive or that has nothing to do with exponentiation.)

However, in the related operation of falling power that is useful in many combinatorial formulas and denoted syntactically by underlining the exponent, each term that gets multiplied into the product is always one less than the previous term. For example, the falling power 83 would be computed as 8 * 7 * 6 = 336. Similarly, the falling power 105 would equal 10 * 9 * 8 * 7 * 6 = 30240. Nothing important changes if the base n is negative. For example, the falling power (-4)5 is computed the exact same way as -4 * -5 * -6 * -7 * -8 = -6720.

This method should compute and return the falling power nk where n can be any integer, and k can be any nonnegative integer. (Analogous to ordinary powers, n0 = 1 for any n.) The automated tester is designed so that your method does not need to worry about potential integer overflow as long as you perform computations using long type of 64-bit integers.


public static int[] everyOther(int[] arr)

Given an integer array arr, create and return a new array that contains precisely the elements in the even-numbered positions in the array arr. Make sure that your method works correctly for arrays of both odd and even lengths, and for arrays that contain zero or only one element. The length of the result array that you return must be exactly right so that there are no extra zeros at the end of the array.


public static int[][] createZigZag(int rows, int cols, int start)

This method creates and returns a new two-dimensional integer array, which in Java is really just a one-dimensional array whose elements are one-dimensional arrays of type int[ ]. The returned array must have the correct number of rows that each have exactly cols columns. This array must contain the numbers start, start + 1, ..., start + (rows * cols - 1) in its rows in order, except that the elements in each odd-numbered row must be listed in descending order.
For example, when called with rows = 4, cols = 5 and start = 4, this method should create and return the two-dimensional array whose contents are
 4  5  6  7  8
 13  12  11  10  9
 14  15  16  17  18
 23  22  21  20  19

when displayed in the traditional matrix form that is more readable for the human than the more realistic form of a one-dimensional array whose elements are one-dimensional arrays of rows.

To Continue Click Here > Assignment Lab 20127.pdf
Codingassignmenthelper | Home Codingassignmenthelper | Home