Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: zz-x2580
Java
Important Notes
1. The assignment is an individual project, to be finished on one’s own effort.
2. 20%
3.
mark deduction will be given for late submission within 2 days, and 0 for even later;
Plagiarism is strictly forbidden, regardless of the role in the process. Notably, ten consecutive
lines of identical codes are treated as plagiarism. Using AI to directly generate code will also
be regarded as plagiarism. Depending on the seriousness of the plagiarism, 30% − 100% marks
will be deducted.
Marking Criterion
1. The full score of the assignment is 300 marks.
2. Three java programs are to be submitted. Each program will be evaluated with several unseen
test cases. A submission obtains the full score if and only if both programs pass all test cases.
Running Environment
1. The submissions will be evaluated in the OJ system running Java SDK 21. It is the students’
responsibility to make sure that his/her submissions are compatible with the OJ system.
2. The submission is only allowed to import four packages of (java.lang.*; java.util.*; java.math.*;
java.io.*) included in Java SDK, and StdIn / StdOut from textbook. No other packages are
allowed.
3. All students will have an opportunity to test their programs in the OJ platform prior to the
official submission.
Submission Guidelines
1. You will get your grade only if you submit your code both on OJ and on bb on time.
2. For bb submission, you need to directly upload your java file on bb. That is, your submission
should be V ector.java, and StringSorter.java. Wrong submission format will receive 10%
mark deduction.
3. Inconsistency with or violation from the guideline leads to marks deduction.
4. All students are reminded to read this assignment document carefully and in detail. No argument will be accepted on issues that have been specified in this document.
1
Programs
There are 2 independent programs in this assignment, and each is worth 150 points.
Vector
Write a Java program (Vector.java) according to the following tutorial:
1. Create a class “Vector” which is used to store an n-dimensional vector and do relevant operations. Write a constructor for “Vector” that takes an int array as parameter.
2. Write a static method “plus(Vector v1, Vector v2)” that returns the sum of v1 and v2, which
is also a Vector. Also, write a static method “subtract(Vector v1, Vector v2)” that returns v1
– v2.
3. Write a non-static method “multiply(int a)” that returns the result of multiplying a Vector by
the integer a.
4. Write a non-static method “norm(int p)” that returns the p-norm of a Vector as a double.
Overload the method so that it will return the infinity-norm of the Vector when taking no
parameter.
5. Write a static method “dot(Vector v1, Vector v2)” that returns the dot product of v1 and v2
as an integer.
6. Write a static method “angle(Vector v1, Vector v2)” that returns the angle between v1 and v2
as a double, provided that v1 and v2 are not 0 vector.
7. Override the non-static method “toString()” that returns a String in the form:
(v1, v2, . . . , vn)
How to test your code: Go to the problem on OJ, and click ”Open Scratchpad”; Copy your
code to the top-right textbox, and copy the sample input to the bottom-left textbox; Click ”run
pretest” to generate output. Note that in this program, the class name must be ”Vector”. You can
also test your code locally by yourself. Input and output handling is implemented in the OJ for this
problem, so you can focus on implement the Vector class.