UOW Week 10 Flashcards
What does %s, %d, %f do?
s formarts Strings, d formats decimal integers, f formats floating-point numbers
System.out.printf(“%s%10s%n”, “Ticker Symbol”, “Position”);
Ticker Symbol Position
Example of array initialiser
String[] Stocks = {“BABA”, “JD”, “QCOM”};
Minimize this function: L(S) = N/S + S - 1
0 = 1 - N/S^2 which then equals to S = square root of N
What is the quadratic formula?
x = -b(+-) root b^2 -4ac / 2a
print a random number from a rand of 100 to 200
(int)Math.floor(Math.random() * ((200 - 100 + 1) + 100);
What do these mean: ∈, ∉, ⊂, ⊆, ⊄, |, ℤ
∈ - Element of
∉ - Not element of
⊂ - Proper subset of (A is a part of B but they aren’t equal, as in B is bigger)
⊆ - Subset of/Every element of (Since all of the members of set A are members of set D, A is a subset of D. Symbolically this is represented as A ⊆ D. Note that A ⊆ D implies that n(A) ≤ n(D) (i.e. 3 ≤ 6).)
⊄ - Not a subset of/Not every element of
|- Such that
ℤ - Integers (A number which is not a fraction; a whole number. Whole-valued positive or negative number or 0. The integers are generated from the set of counting numbers 1, 2, 3, . . . and the operation of subtraction. When a counting number is subtracted from itself, the result is zero. When a larger number is subtracted from a smaller number, the result is a negative whole number)
What are the benefits of seperating concepts into different classes in code?
To make recycling and reusing code easier and more efficient. In addition, testing the program is much easier when it has been divided into several concepts, each of which has its own separate logic and can function alone as a unit
What is the difference between == and .equals()
== is a reference comparison, ie both objects point to the same memory location. .equals() evaluates to the comparison of values in the objects
What is Random(), ie Random draw = new Random();
Creates a new random number generator. ie int wtf = draw.nextInt(100); (generate number between 0 and 100)
What is a stack trace?
prints what type of error occured followed by the line it occured at.
Name 5 things for troubleshooting
- Indenting code properly with the necessary parentheses.
- Verify variables are correctly named.
- Verify variables are initialised, or a NullPointerException error will occur.
- Testing the program flow with different inputs.
- Add print commands at stages of the program is see the values of certain variables at different stages of the programs execution to determine where the bug or error is located.
What is test-driven development?
Test-driven development is constructing a software in small interations. Benefits include: focusing on requirements before writing code, code is easier to maintain and less debugging.
What is refactoring in coding?
Cleaning the code while maintaining the functionailty of the program. Cleaning refers to improving readibility, dividing program into small classes and methods, and removing repetitive code.
Name one catastrophe caused by a software error
NASA’s Mars Climate Orbiter, crashed because a sub contractor on the engineering team failed to make a simple conversion imperial units to metric, leading to a navigation error which caused the $125 million dollar craft crashing.