7: Data Structures
We will build our own photo editing tools as we study more complex nested loops to traverse and mutate 2D arrays.
Last updated
We will build our own photo editing tools as we study more complex nested loops to traverse and mutate 2D arrays.
Last updated
I can remove a column from a 2D array in Java.
I can write 2D array methods for the PicLab.
Convert 128 to binary
Covert 225 to binary
Convert 11010111 from base 2 to base 10
This is a byte.
Max red, green and blue (255, 255, 255) is white. No red, green and blue (0, 0, 0) is black. Sometimes we add a fourth byte to control alpha layer (transparency). rgba(255, 255, 255, 255)
is opaque black.
Two digits in base 16, hexadecimal, can describe 0 - 255. Eight digits can contain rgba. #FF0000FF
is opaque black.
What is the row index for the top left corner of the picture?
What is the column index for the top left corner of the picture?
The width of the picture is 640. What is the right most column index?
The height of the picture is 480. What is the bottom most row index?
Imagine a circumstance where you might use an interface and an abstract class. Create and implement the interface and abstract class. Instantiate objects that extend these. Create a polymorphic container or method.
Calculate the sum of an indicated column from an extremely rare occurrence of a 2D ArrayList:
public static int sumColumn(int col, List<List<Integer>> grid){
Remove a row from a 2D array:
public static String[][] removeRow(int row, String[][] names){
Calculate the sum of an entire 2D array:
public static double sum(double[][] grid){
Count the number of occurrences of a given number in a 2D array
public static int count(int[][] grid, int target){
Add a new column to a 2D array of Pixels with the average color at the end of the image
public static Pixel[][] addAverageColumn(Pixel[][] picture){
// each Pixel has .getColor() which gives a single int
// return an array that's one column wider, containing the average of every color in that row
// you can set the color of a pixel by using .setColor() and passing the method the average of that row's .getColor()
}
Convert an RGB value like 220, 175, 205 to a hex value
We have an array of Friends, Friends[] friends
, and we want to make sure that each of our friends has the items they requested from the store. Friend.getItems()
returns an array of Item objects (Item implements the Comparable
interface so you can use .equals()
to compare two items). If the Item is not on the shopping list, we'll add it to an ArrayList<Item>
called requests
. The Item class also has a publicly accessible boolean that marks if the Item has been claimed: Item.claimed
.
public ArrayList<Item> checkShoppingList(Friends[] friends, ArrayList<Item> list){