1/19
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
How can you determine if an equation results in a double?
If one value in an equation is a double (5.0 / 2 = 2.5), if the final variable is a double and equation is cast with “(double)”
How can you return the last digit(s) of a variable?
Use modulus by 10 for 1 digit, 100 for 2 digits and so on (n % 10 = last digit)
How do you apply DeMorgan’s law(!) on Boolean statements? (ie. distribute !(n < 3 && x == 5))
! in front of a boolean statement reverses operators, with && becoming || and vice versa(ie. !(n < 3 && x == 5) becomes (n >= 3 || x !=5)
What do you set instance variables to and why?(public, private, none)
Private is set, letting the instance variable only be accessible within its class. This is done for security reasons and prevents its alteration from other classes.
What are mutators and accessors?
Mutators are setter methods that set instance variables from their parameter. Accessors are getter methods that return instance variables.
What occurs when a class is called with a different number of parameters or different parameter types than the parameters in the constructors?
A compile-time error occurs.
How can you add more to strings?
By concatenating, which glues strings together with a + sign(ie. String1 + “ hello world”)
What are string Objects, and how do they compare to other strings?
String Objects result from classes(ie. String s1 = new String(“HELLO”), called with s1), they cannot use == to compare(will always print false), but require .equals() to compare.
What is the compareTo method?
It takes the lexicographical order(dictionary in which each character is assigned a number) and subtracts the lexicographical sum of all numbers of the second string from the first string.
What is the substring method?
returns a part of a string. String indexes start at 0 and go up to the length - 1. Substring methods require string.substring(Start index, end index + 1)
What are reference variables?
Reference variables are variables that require a class and can be accessed and changed through methods of that class(ie. String car1 = new String(“audi”), car1.getCar())
Where are variables created by a for loop(ie. int i) able to be found?
Only within the loop, outside of the loop will throw an error. This can be prevented by initializing the variable before the loop.
What are the two ways to declare an array?
You can either pre-populate it with:
variableType[] ([][] for 2d) name = {values separated by commas}
(ie. String[] array1 = {“A”, “B”, “C”})
Or you can make an empty array with:
variableType[] ([][] for 2d) name = new variableType[length of array](add [length of cols] for 2d)
Then, fill up the array: name[location](add a second [location] for 2D) = input. The default value for empty indices is labelled as null for string, 0 for int, 0.0 for double, false for bool
How can you change the size of an array?
It is not directly possible; instead, a new array is required with elements copied from the first array, then more elements need to be added.
How do you initialize an arraylist?
Arraylist<dataType> name = new Arraylist<dataType>();
ie. Arraylist<String> colors = new Arraylist<String>();
How do you read text files?
In a method:
File FILENAME = new File(“NAMEOFCSVFILE”);
Scanner input = new Scanner(FILENAME);
input.nextLine(); //skips header at top of textfile
while(input.hasNext()){
String info = input.nextLine;
System.out.println(info);
System.out.println();
}
input.close();
What needs to be added at the end of text file method headers?
throws IOException
What is the split class?
The split class returns an array where all elements of the instance del have been spliced out, and each element in the array is pieces of the string between the instance del
What is a wrapper class(how do you convert doubles/ints into strings)?
For doubles, Double.parseDouble(string s) is used, while for integers, Integer.parseInt(string s) is used
What order are the rows and cols in a 2d array, and how do you find their lengths?
[row][col]
For rows, array.length is used; for columns, array[0].length is used.