Constructors
Methods
Fields
public boolean isGreaterThan50(int number) {
if (number > 50) {
return true;
} else {
return false;
}
}
isGreaterThan50(20); // false
isGreaterThan50(60); // true
public int compare(int a, int b) {
if (a == b) {
return 0;
} else if (a < b) {
return -1;
} else {
return 1;
}
}
int z = compare(1, 1); // 0
int y = compare(1, 2); // -1
int x = compare(2, 1); // 1
void printXTimes(String somethingToPrint, int x) {
for (int i = 0; i < x; i++) {
System.out.println(somethingToPrint);
}
}
printXTimes("Heellooo", 3);
// Heellooo
// Heellooo
// Heellooo
ArrayList<Dog> dogs = new ArrayList<>();
Dog snoopy = new Dog("Snoopy");
Dog oscar = new Dog("Oscar");
Dog paul = new Dog("Paul");
dogs.add(snoopy);
dogs.add(oscar);
dogs.add(paul);
for (Dog dog : dogs) {
System.out.println(dog.getName());
}
// Snoopy
// Oscar
// Paul
int index = 5;
while (index > 2) {
System.out.println(index);
index--;
}
// Now at: 5
// Now at: 4
// Now at: 3
public void spin() {
System.out.println("Spinning!");
System.out.println("Dizzy...");
}
print "Spinning!"
print "Dizzy..."
End
Start
public void dance(String songName) {
System.out.println("Dancing to
" + songName + "!");
jump();
spin();
System.out.println("One more time!");
jump();
}
public void jump() {
System.out.println("Jumping!");
}
public void spin() {
System.out.println("Spinning!");
System.out.println("Dizzy...");
}
Start
print "Dancing..."
jump()
spin()
print "One more time!
jump()
End
public void printNum(int i) {
if (i == 3) {
print("three");
} else {
print("not 3!");
print(i);
}
print("done");
}
if i == 3
print "not 3"
F
T
print "three"
print i
print "done"
End
Start
public void printList(List<String> theList) {
for (String s : theList) {
print(s);
print("done item "+s);
}
print("done "+theList);
}
Start
for: s in theList
T
F
print "done..."
print "done item"
End
print s
public class Person {
private int age;
private String status;
public Person() {
this.status = "young";
this.age = 0;
}
public void getOlderByYears(int years) {
this.age = this.age + years;
if (age > 1) {
status = "old";
}
}
}
public class Main {
public static void main(String[] args) {
Person bubbles = new Person();
Person buttercup = new Person();
Person blossom = new Person();
ArrayList<Person> people = new ArrayList<>();
people.add(bubbles);
people.add(buttercup);
people.add(blossom);
int ageAmount = 1;
for (Person p : people) {
p.getOlderByYears(ageAmount);
ageAmount = ageAmount + 1;
//POINT A
}
//POINT B
}
}
We need flow charts for
Tank.handleBoundary
SIGame.moveMissiles
SIGame.checkGameOver
secret hint for Felix