Lab 1
Variables
Testing equivalence of two floating point numbers should be done as follows to account for error:
double_1 == double_2 // Returns False
Math.abs(double_1 - double_2) < 0.000001; // Returns True
To use the maths library for mathematical constants use the following to import:
import java.lang.Math
You would use the following in your code when you need $\pi$.
Math.PI
Control Flow
If statements can be made and chained as follows:
if (grade > 70) {
System.out.PrintLn("Congrats on your first!");
}
else if (grade > 60) {
System.out.PrintLn("Nicely done, you got a 2:1!");
}
else if (grade > 50) {
System.out.PrintLn("Looks like you could have passed some more of the unit tests, but your code still passes most. ");
}
else if (grade > 40) {
System.out.PrintLn("You've passed this lab, but try and make sure you follow the specification closely and make a good attempt at each problem. Semi-functional code is always better than no code at all.");
}
else {
System.out.PrintLn("You haven't managed to pass this lab, but don't worry as there is still plenty of time to go back and improve. Watch the lecture videos, try to follow what's needed in the labs, and ask the TA's for help in a lab session if there's any concepts you don't get, that's what they're there for!");
}
Remember to use curly braces {}
and to only end the content of the if
with ;
.