Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
There are ten labs total in the course (C)CPS 209 Computer Science II taught by Ilkka Kokkarinen during the Spring 2018 term. The same ten labs are used in the daytime science transition program and in the Ryerson Chang School of Continuing Education.
Since many of these labs refer to the work done in the previous labs, you should create one BlueJ project folder named “209 Labs” into which you write all these ten labs. In this same project folder, you should also add the JUnit test classes provided by the instructor, and the text file warandpeace.txt of the classic novel known for its extreme length that is used as a “big data” (well, big enough for the era that it comes from) source for some of the JUnit tests for the labs. You should download and save this text file inside this project folder from the DropBox link. Do not edit this text file in any way, not even to just add or remove some little whitespace character.
Each of these ten labs is worth the same two points of your total course grade. For labs 5, 7 and 9 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 seven labs must cleanly pass the JUnit tester of that week to receive the two points for that lab. No partial marks whatsoever are given for labs that do not not pass these tests. In all computation, being 99% correct is same as being 0% correct. (And in fact, in many situations the former would be much worse.)
To compensate for this strict policy of correctness and to simplify the job for handling the labs in this double-paced course, in both daytime science transition course and evening Chang School course, all ten labs have the exact same deadline, the noon the day after the last lecture. Before that, there is no rush to complete any lab, so you can take your time to get each lab to work 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.
In all these labs, silence is golden. Since many of these JUnit testers will test your code with a large number of pseudo-randomly generated test cases, your methods should be absolutely silent and print nothing on the console during their execution. 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. Modifying a JUnit tester to make it seem that your class passes that test, even though it really does not, is considered serious academic dishonesty and will be automatically penalized by the forfeiture of all lab marks in the course.
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 “209 Labs” BlueJ project folder that contains all the source files and the provided JUnit testers. Even if you write your labs working on Eclipse or some other IDE, it is compulsory to submit these ten labs as one BlueJ project folder. No other form of submission is acceptable.
The students in the daytime transition program course will have the course TA set up a system for lab submissions, and they should not send their labs to the instructor.
ACCIDENTS HAPPEN, SO MAKE FREQUENT BACKUPS OF THE LAB WORK THAT YOU HAVE COMPLETED. SERIOUSLY. THIS CANNOT BE EMPHASIZED ENOUGH IN NOT JUST THIS COURSE, BUT IN ALL OUR LIVES IN THIS AGE OF COMPUTERS.
In spirit of the Fraction example class seen in the first lecture, your first task in this course is to implement the class Polynomial whose objects represent polynomials of variable x with integer coefficients, and their basic mathematical operations. (If your math skills on polynomials have become a bit rusty since you last used them back in high school, check out the page “Polynomials“ in the “College Algebra” section of “Paul’s Online Math Notes“, the best and still very concise online resource for college level algebra and calculus that I know of.) As is good programming style unless there exist good reasons to do otherwise, this class will be intentionally designed to be immutable so that Polynomial objects cannot change their internal state after they have been constructed. The public interface of Polynomial should consist of the following instance methods.
@Override public String toString()
Implement this method first to return some kind meaningful, human readable String representation of this instance of Polynomial. This method is not subject to testing by the JUnit testers, so you can freely choose for yourself the textual representation that you want this method to produce. Having this method implemented properly will become immensely useful for debugging the remaining methods that you will write inside Polynomial class.
public Polynomial(int[] coefficients)
The constructor that receives as argument the array of coefficients that define the polynomial. For a polynomial of degree n, the array coefficients contains exactly n + 1 elements so that the coefficient of the term of order k is in the element coefficients[k]. For example, the polynomial
5x3 – 7x + 42 that will be used as example in all of the following methods would be given as the coefficient array {42, -7, 0, 5}.
Terms missing from inside the polynomial are represented by having a zero coefficient in that position. However, the coefficient of the highest term of every polynomial should always be nonzero, unless the polynomial itself is identically zero. If this constructor is given as argument a coefficient array whose highest terms are zeroes, it should simply ignore those zero terms. For example, if given the coefficient array {-1, 2, 0, 0, 0}, the resulting polynomial would have degree of only one, as if that argument array had really been {-1, 2} without these leading zeros.
To guarantee that the Polynomial class is immutable so that no outside code can ever change the internal state of an object after its construction (at least not without resorting to underhanded tricks such as reflection), the constructor should not assign only the reference to the coefficients array to the private field of coefficients, but it must create a separate but identical defensive copy of the argument array, and store that defensive copy instead. This ensures that the stored coefficients of the polynomial do not change if somebody later changes the contents of the shared coefficients array that was given as the constructor argument.
public int getDegree()
Returns the degree of this polynomial. For example, the previous polynomial has degree 3.
public int getCoefficient(int k)
Returns the coefficient for the term of order k. For example, the term of order 3 of the previous polynomial equals 5, and the term of order 0 equals 42.
public int evaluate(int x)
Evaluates the polynomial using the value x for the unknown symbolic variable of the polynomial. For example, when called with x = 2 for the previous example polynomial, this method would return 68. Your method does not have to worry about potential integer overflows, but can assume that the final and intermediate results of this computation will always stay within the range of int.
JUnit: PolynomialTestTwo.java
The second lab continues with the Polynomial class from the first lab by adding new methods for polynomial arithmetic in its source code. (There is no inheritance or polymorphism yet in this lab.) Since the class Polynomial is designed to be immutable, none of the following methods should
modify the objects this or other in any way, but return the result of that arithmetic operation as a brand new Polynomial object created inside that method.
public Polynomial add(Polynomial other)
Creates and returns a new Polynomial object that represents the result of polynomial addition of the two polynomials this and other. This method should not modify this or other polynomial in any way. Make sure that just like with the constructor, the coefficient of the highest term of the result is nonzero, so that adding the two polynomials 5x10 – x2 + 3x and -5x10 + 7, each of them of degree 10, produces the result polynomial –x2 + 3x + 7 that has a degree of only 2 instead of 10.
public Polynomial multiply(Polynomial other)
Creates and returns a new Polynomial object that represents the result of polynomial multiplication of the two polynomials this and other. Polynomial multiplication works by multiplying all possible pairs of terms between the two polynomials and adding them together, combining the terms of equal rank together into the same term.