Python to Java
Java Quirks
OOP
Inter/abstract
JCF
100

x = 5

print("My number is", x)

What is:

int x = 5;

System.out.println("My number is " + x);

100

BONUSSSS

more freee pointsss

100

What are the two types of variables in Java?


What is Primitives and objects/references


100

how do we form a "contract" with an interface

implements

100

What two methods must be overridden to use a Hash-based data structure? 

What is: equals and hashCode
200
BONUSSS

FREE POINTSSSS

200

What is a constructor?

What is:

a method that creates an object and sets the fields of said object. It then returns a reference to that object.  

200

In what two situations is toString automatically called? 

What is 

printing 

and String Concatenation

200

how many interfaces and abstract classes can in inherent from

interfaces: infinite

abstract class: 1

200

What uses natural order and what function does it call. 


What uses custom order and what function does it call. 

natural: comparable interface with compareTo

custom: comparator class with compare

300

a = [0, 1, 2, 3, 4, 5]

for x in a:

    print(x)

What is:

int[] a  = {0, 1, 2, 3, 4, 5};

for(int x: a){

    System.out.println(x);

}

300

This is used to reference the current reference of the class.

What is "this"

300
ALL classes have this class in common

what is Object

300
Wait....how do I class constructor if I'm a child class?

what is super(param1, ...., paramN)

300

Time complexity for contains for these classes:

TreeSet, HashSet, ArrayList

TreeSet: O(logn)

HashSet: O(1)

ArrayList: O(n)


400

x = 100

total = 0

for i in range(x):

     if i % 7 == 0 or i % 3 == 0 and i % 2 == 0:

          total += i

print(total)

int x = 100;

int total = 0;

for (tint i = 0; i < x; i++){

     if (i % 7 == 0 || i % 3 == 0 && i % 2 == 0){

        total += i;

}

}

System.out.println(total);

400
Describe this variable:

protected static final double VAR = 5.23;

this variable can be accessed by the class and subclasses. Likewise, its memory is shared between all instances of the class, and finally, it's constant such that it can be changed. 

400

What are the 4 pillars of OOP: EXPLAIN THEM

(Hint: I PEA)

Inheritance

Polymorphism

Encapsulation

Abstraction

400

write an Abstract class for a Person:

3 fields: name, age, alive (default = true)

2 methods

abstract speak and getName


public abstract class class Person{

    private String name;

     private int age;

     private boolean alive;


     public Person(String name, int age){

         this.name = name; this.age = age;

         this.alive = true;

    }


     public abstract String speak();

     public String getName(){ return this.name}

}

400

SPRINT:

Assuming we have a Person class with the method getAge write our compareTo method to sort the person by descending age. 

@Override

public int compareTo(Person o){

return age - o.age;

}

500

def print_range(start, end, step):

     for i in range(start, end, step):

          print(i)


def main():

    step1, step2= int(input()), int(input())

    print_range(100, 0, step1)

    print_range(0, 100, step2)


# hint use a boolean set to start < end and use that in your comparison in the for loop

What is import java.util.Scanner;

private static void printRange(int start, int end, int step){

    boolean greater = start < end;

    for (int i = start; i < end == greater; i += step){

         System.out.println(i);

    }

}

public static void main(String[] args){

    Scanner scan = new Scanner(System.in);

    int step1 = scan.nextInt();

    int step2 scan.nextInt();


    printRange(100, 0, step1);

    printRange(0, 100, step2);

}

500

SPRINT!!!!!

write a Java class about a book.

3 feilds: name, price, author

3 methods: getName, getPrice, equals

What is:


public class Book{

    private String name;

    private String author;

    private double price;

    public Book(String name, String author, double price){

    this.name = name; this.author = author; this.price = price;

}

public String getName(){ return this.name; }

public double getPrice(){ return this.price; }


@Override

public boolean equals(Object o){

     boolean result = false;

     if (o instanceof Book book){

          result = this.name.equals(book.name) && this.author.equals(book.author);

     }

      return result;

}

}

500

SPRINT!!!!

Given this outline draw the UML:

an interface Animal with the following methods:

speak, travel with integer, eat which takes in food

A food class with a name, and amount

An abstract class Dog

with a fur color and an abstract method bark that returns a string.

Finally two classes:

a fish which implements Animal

and Fido which implements Animal and extends Dog.

yes

500
SPRINT!!!!

write a generic stack interface

public interface StackInter<E>{


int getSize();

boolean isEmpty();

void push(E value);

E top();

E remove();

}
500

SPRINT!!!!

Assuming we have a Person class with a getName and getAge function, write a Comparator Class that orders a person by accessing name and descending age. 

public class PersonComparator implements Comparator<Person>{

     public PersonComparator(){}


     @Override

     public int compare(Person o1, Person o2){

          int result = o1.getName().compareTo(o2.getName())

          return result != 0  ? result : o2.getAge() - o1.getAge();

     }

}

M
e
n
u