Uploaded by Sora To Hoshi

ITL221-18 2BSIT-3 MP-3 CINCO-JOHN-MICHAEL-G.

advertisement
Name:
CINCO, JOHN MICHAEL G.
Section:
Class Schedule:
2BSIT-3
SATURDAY 10:00AM – 1:00PM
Machine Problem 3
Design a Person Class and use it in a Java Program. Here are the instructions.
* Use Lecture Module 3 as reference.
a) Using the Class Person you designed in Machine Problem 2, add accessor/getter and
mutator/setter methods for each attributes.
b) Create a Main class (class with a main method) to test if your setter/getter works properly.
Paste your Class here
package MachineProblem3;
public class Person {
private String Name;
private String Age;
private String gender;
private int height;
private int weight;
public Person() {
Name = "John Michael Cinco";
Age = "19";
gender = "Male";
height = 170;
weight = 78;
}
// Overloading Constructors
public Person(String Name) {
this.Name = Name;
}
public Person(String Name, String age) {
this.Name = Name;
this.Age = Age;
}
public Person(String Name, String age, String gender) {
this.Name = Name;
this.Age = Age;
this.gender = gender;
}
public Person(String Name, String age, String gender, int height) {
this.Name = Name;
this.Age = Age;
this.gender = gender;
this.height = height;
}
public Person(String Name, String age, String gender, int height, int
weight) {
this.Name = Name;
this.Age = Age;
this.gender = gender;
this.height = height;
this.weight = weight;
}
// Behaviors
public void Running() {
System.out.println("\r===========");
System.out.println("Behavior");
System.out.println("===========");
System.out.println("Running");
}
public void Walking() {
System.out.println("Walking");
}
public void Jogging() {
System.out.println("Jogging");
}
public void Eating() {
System.out.println("Eating");
}
public void Jumping() {
System.out.println("Jumping");
}
// Getters and Setters
public String getName() {
return Name;
}
public void setName(String Name) {
this.Name = Name;
}
public String getAge() {
return Age;
}
public void setAge(String Age) {
this.Age = Age;
}
public String getgender() {
return gender;
}
public void setgender(String Gender) {
this.gender = gender;
}
public int getheight() {
return height;
}
public void setheight(int height) {
this.height = height;
}
public int getweight() {
return weight;
}
public void setweight(int weight) {
this.weight = weight;
}
}
MAIN CLASS
package MachineProblem3;
public class Main {
public static void main(String[] args) {
Person mp3 = new Person();
mp3.setName("John Michael G. Cinco");
mp3.setAge("19");
mp3.setgender("Male");
mp3.setheight(170);
mp3.setweight(78);
System.out.println("Name:" + mp3.getName() + "\nAge: " + mp3.getAge()
+ "\nGender: " + mp3.getgender()
+ "\nHeight" + mp3.getheight() + "\nWeight: " +
mp3.getweight());
}
}
Paste Screenshot of your output:
Download