You are on page 1of 3

Name:

Delima, Marlon Jr. G.


Section: Class Schedule:
2BSIT3 SAT 10:00am – 1:00pm

Machine Problem 2
Design a Person Class and use it in a Java Program. Here are the instructions.
* Use Lecture Module 2 as reference.

a) Using the Class Person you designed in Machine Problem 1, add 4 more constructors to your
class. (See examples in Module 2)

b) Use the this reference in your constructors.

c) Create a Main class (class with a main method) to test if your Constructors work properly.

Write your Class here


package Activities;

public class Person {

String nationality;
int age;
String gender;
String hairColor;
String skinColor;

public Person(){

nationality="Filipino";
age=21;
gender="male";
hairColor="black";
skinColor="brown";

public Person(String nationality, int age) {


this.nationality = nationality;
this.age = age;
}

public Person(String nationality, int age, String gender) {


this.nationality = nationality;
this.age = age;
this.gender = gender;
}

public Person(String nationality, int age, String gender, String


hairColor) {
this.nationality = nationality;
this.age = age;
this.gender = gender;
this.hairColor = hairColor;
}
public Person(String nationality, int age, String gender, String
hairColor, String skinColor) {
this.nationality = nationality;
this.age = age;
this.gender = gender;
this.hairColor = hairColor;
this.skinColor = skinColor;
}

public void walk() {


System.out.println("WALK");
}

public void jog() {


System.out.println("JOG");

public void run() {


System.out.println("RUN");
}

public void eat() {


System.out.println("EAT");
}

public void sleep() {


System.out.println("SLEEP");
}

MAIN METHOD
package Activities;

public class MainClass {

public static void main(String[] args) {

Person Marlon = new Person();


Person marlonDelima = new Person("Filipino", 21);
Person merlyDelima = new Person("Filipino", 45 , "Female");
Person glaicyDelima = new Person("Filipino", 16 , "Female",
"Black");
Person hanenDelima = new Person("Filipino", 16 , "Female",
"Black", "Brown");

//ATTRIBUTES
System.out.println("marlonDelima Nationality :
"+marlonDelima.nationality+"\n"
+ "marlonDelima Age:"+marlonDelima.age);
System.out.println("merlyDelima Gender: "+merlyDelima.gender);
System.out.println("glaicyDelima Hair Color:
"+glaicyDelima.hairColor);
System.out.println("hanenDelima Skin Color:
"+hanenDelima.skinColor);
System.out.println();
//BEHAVIOR
marlonDelima.walk();
Marlon.jog();
Marlon.run();
Marlon.eat();
Marlon.sleep();

Paste Screenshot of Sample output:

You might also like