CB Vocab
- Casting
- Wrapper classes
- Concatenation
- Math Class
- Boolean Expressions
- Comparing Numbers
- Truth Tables and De Morgan's Law
- Comparing Strings & Comparing Objects
- For Loop & Enhanced For Loop
- While Loops VS Do-While Loops
- Nested Loops
- Creating Classes
- Constructors
- Setter/Getter Methods
- Access Modifiers
- Static VS Non Static Methods
- .this Keyword
- Main/Tester Methods
- Inheritance/Extends/Subclass
- Overloading a Method
- Overriding a Method
- Abstract Class/Methods
- Standard Methods
- Late Binging of Object
- Polymorphism
- Binary Search
int x;
int y;
double casting1;
double casting2;
x = 10;
y = 15;
casting1 = (double) y / x;
casting2 = y / x;
System.out.printf("With casting: %.2f\nWithout casting: %.2f", casting1, casting2);
Integer num = new Integer(5);
System.out.printf("int: %d\n", num);
num.toString();
System.out.printf("string: \"%s\"", num);
String message1;
String message2;
int num;
String finalMessage;
String finalMessage2;
message1 = "Hello";
message2 = "World";
num = 5;
finalMessage = message1 + message2;
finalMessage2 = message1 + message2 + num;
System.out.printf("%s\n%s", finalMessage, finalMessage2);
double x;
double y;
double randomX;
double randomY;
x = 5;
y = 12;
randomX = Math.random() * x;
randomY = Math.random() * y;
System.out.printf("%.2f\n%.2f", randomX, randomY);
public class GreatestNumber
{
public static boolean num1Largest(int num1, int num2, int num3)
{
// num1 is the greatest
if ((num2 > num3) && (num1 > num2))
{
return true;
}
return false;
}
public static boolean num2Largest(int num1, int num2, int num3)
{
// num2 is the greatest
if (((num1 > num3) && (num2 > num1)) || ((num3 > num1) && (num3 < num2)))
{
return true;
}
return false;
}
public static boolean num3Largest(int num1, int num2, int num3)
{
// num3 is the greatest
if((num1 < num2) && (num2 < num3))
{
return true;
}
return false;
}
public static void main (String[] Args)
{
int num1 = 10;
int num2 = 15;
int num3 = 5;
boolean num1Largest;
boolean num2Largest;
boolean num3Largest;
num1Largest = num1Largest(num1, num2, num3);
num2Largest = num2Largest(num1, num2, num3);
num3Largest = num3Largest(num1, num2, num3);
System.out.printf("%d, %d, %d\nnum1 is the largest: %b\nnum2 is the largest: %b\nnum3 is the largest: %b\n",
num1, num2, num3, num1Largest, num2Largest, num3Largest);
}
}
GreatestNumber.main(null);
int[] nums = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
// regular
for(int i = 0; i < nums.length; i+=2)
{
System.out.printf("%d\n", nums[i]);
}
System.out.printf("\n");
// enhanced
for(int i : nums)
{
System.out.printf("%d\n", i);
}
Nested Loops
- In Tic-Tac-Toe, the board is a 2D-Array which is initialized by two for loops iterating through each column and each row
// getter
private double getGPA(double gpa)
{
return gpa;
}
// setter
private String name(String name)
{
String student = "";
name = student;
return student;
}