0% found this document useful (0 votes)
14 views4 pages

Activity 9 Source Code

Source code for Java Programming

Uploaded by

lesiguesamier
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

Activity 9 Source Code

Source code for Java Programming

Uploaded by

lesiguesamier
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Activity 9 Source Code

1.
public class Person {

public static void main(String[] args) {


Person reima = new Person("Reima", 19);
Person avery = new Person("Avery");
reima.printInfo();
avery.printInfo();

}
private String name;
private int age;
public Person(String name) {
this.name = name;
this.age = 0;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getName(){
return this.name;
}
public int getAge(){
return this.age;
}
public void setName(String name){
this.name = name;
}
public void setAge(int age){
this.age = age;
}
public void printInfo(){
System.out.println(name + ", " + age + " yrs. old.");
}
}

2.
public class SimpleCalculator {

public static void main(String[] args) {


SimpleCalculator add = new SimpleCalculator(6, 9);
add.add();
SimpleCalculator sub = new SimpleCalculator(24, 6);
sub.subtract();
SimpleCalculator mult = new SimpleCalculator(6, 9);
mult.multiply();
SimpleCalculator div = new SimpleCalculator(420, 4);
div.divide();

}
private int x;
private int y;
public SimpleCalculator(int x, int y) {
this.x = x;
this.y = y;
}
public int getX(){
return this.x;
}
public int getY(){
return this.y;
}
public void setX(int x){
this.x = x;
}
public void setY(int y){
this.y = y;
}
public int add(){
System.out.println(x + y);
return x + y;
}
public int subtract(){
System.out.println(x - y);
return x - y;
}
public int multiply(){
System.out.println(x * y);
return x * y;
}
public int divide(){
System.out.println(x / y);
return x / y;
}
}

You might also like