In this PHW, you will practice working with two-dimensional arrays in main and as a reusable class.
main
We will be creating a 2-dimensional array that will take a width, height, & scaling factor and create a multiplication table based on the scaling factor:
main
method to learn the Java syntax of this particular problem.Now that you understand what you’re implementing, you’re ready to try rewriting it in a reusable, object-oriented way.
Once you’ve finished doing the practice HW a single time, watch me do it:
MultiplicationTable
classMultiplicationTable
with 2 fields: a two-dimensional integer array & a scaling factorarray[0][0] = scaling factor
array[w-1][h-1] = scaling factor * width * height
print
method to print out the tablelookup
method that takes two indexes (of the ranges 1 to width and 1 to height) and returns the appropriate value (or 0 otherwise)Optional: Want all your numbers to line up in nice columns?
String format = "%10d"; // padd number to take 10 spaces total
int value = 1250;
System.out.format(format, value);
Optional: Want all your numbers to line up relative to the length of the largest value? Figure out the length of your longest number:
String.valueOf(biggest).length();
Once you’ve finished doing the practice HW a single time, watch me do it: