public class Person {
private int age;
public Person() {
this.age = 1;
}
public int getAge() {
return age;
}
public void getOlderByYears(int years) {
this.age = this.age + years;
years = years + 1;
// POINT A
}
}
public class Main {
public static void main(String[] args) {
Person jean = new Person();
int ageAmount = 3;
//POINT B
jean.getOlderByYears(ageAmount);
//POINT C
}
}
public class Person {
private int age;
public Person() {
this.age = 1;
}
public int getAge() {
return age;
}
public void getOlderByYears(int years) {
this.age = this.age + years;
years = years + 1;
// POINT A
}
}
public class Main {
public static void main(String[] args) {
Person jean = new Person();
int ageAmount = 3;
//POINT B
jean.getOlderByYears(ageAmount);
//POINT C
}
}
Q1
public class Person {
private int age;
public Person() {
this.age = 1;
}
public int getAge() {
return age;
}
public void getOlderByYears(int years) {
this.age = this.age + years;
years = years + 1;
// POINT A
}
}
public class Main {
public static void main(String[] args) {
Person jean = new Person();
int ageAmount = 3;
//POINT B
jean.getOlderByYears(ageAmount);
//POINT C
}
}
Q2
public class Person {
private int age;
public Person() {
this.age = 1;
}
public int getAge() {
return age;
}
public void getOlderByYears(int years) {
this.age = this.age + years;
years = years + 1;
// POINT A
}
}
public class Main {
public static void main(String[] args) {
Person jean = new Person();
int ageAmount = 3;
//POINT B
jean.getOlderByYears(ageAmount);
//POINT C
}
}
Q3
public class Person {
private int age;
public Person() {
this.age = 1;
}
public int getAge() {
return age;
}
public void getOlderByYears(int years) {
this.age = this.age + years;
years = years + 1;
}
public void copyInto(Person other) {
other = this;
}
}
public class Main {
public static void main(String[] args) {
Person jean = new Person();
Person manon = new Person();
jean.getOlderByYears(10);
jean.copyInto(manon);
System.out.println(manon.getAge());
}
}
Q4: BONUS
What does this print?
What happens to the argument when we reassign a parameter's value?
Please select an option (plus or quit):
plus
you selected: plus
Please enter the first number to plus
6
Please enter the second number to plus
2
that equals: 0
Please select an option (plus or quit):
plus
you selected: plus
Please enter the first number to plus
8
Please enter the second number to plus
5
that equals: 0
Please select an option (plus or quit):
plus
you selected: plus
Please enter the first number to plus
12
Please enter the second number to plus
32
that equals: 0
Please select an option (plus or quit):
quit
you selected: quit
Operation log: [
plus [6, 2, 8, 5, 12, 32] equals 44,
plus [6, 2, 8, 5, 12, 32] equals 44,
plus [6, 2, 8, 5, 12, 32] equals 44]
plus[6,2] equals 8, plus [8,5] equals 13...
Expected:
Branch: main
Branch: myfavoriteanimal
Create
Branch
Merge
Branch
Commits