THOUSANDS OF FREE BLOGGER TEMPLATES

Friday, August 21, 2009

INHERITANCE CLASSES

Programming Exercise showing Inheritance classes.

**----------------------------------------------------------------------------------** 

public class Person
{
 private String name;
 private int age;
 private String address;
 private String gender; 
 private int weight;
 private String height;

 public string whoIam()
 {
  String identity;
  return identity = "I am" + " " + name + "." +
  "\n" + age + " " + "years old" + "." +
  "\n" + "I live at" + " " + address + "." +
  "\n" + "I am a" + " " + gender + "." +
  "\n" + "Weighs" + " " + weight + " " +"kgs." +
  "\n" + And stands" + " " +height +" " + "tall.";
 }

 public void setname(String nname)
 {
 this.name=nname;
 }

 public void setage(int nage)
 {
 this.age=nage;
 } 

 public void setaddress(String naddress)
 {
 this.address=naddress;
 }

 public void setgender(String ngender)
 {
 this.gender=ngender;
 }
 
 public void setweight(int nweight)
 {
 this.weight=nweight;
 }

 public void setheight(String nheight)
 {
 this.height=nheight;
 } 

//constuctor

 public Person()
 {
  this.name="Juan Dela Cruz"; 
  this.age=29;
  this.address="17-4AP Magsaysay,Mati, Davao Oriental";
  this.gender="Male";
  this.weight=60; 
  this.height="5 feet 6 inches";
 }
}
**----------------------------------------------------------------------------------** 

public class Student extends Person
{
 private String course;
 private int IDno;
 private String department;
 private String term;
 private String yearlevel;
 private double GPA;

 public Student(String nname, int nage, String naddress,
  String ngender, int nweight, String nheight,String ncourse,
  int nIDno, String ndepartment, String nterm, String nyearlevel,
  double nGPA)
 {
  super(nname, nage, naddress, ngender, nweight, nheight);
  this.course=ncourse;
  this.IDno=nIDno;
  this.department=ndepartment;
  this.term=nterm;
  this.yearlevel=nyearlevel;
  this.GPA=nGPA;
 }
 
 public string whoIam()
 {
  String identity;
  return identity = "I am" + " " + name + "." +
  "\n" + age + " " + "years old" + "." +
  "\n" + "I live at" + " " + address + "." +
  "\n" + "I am a" + " " + gender + "." +
  "\n" + "Weighs" + " " + weight + " " +"kgs." +
  "\n" + "And stands" + " " +height +" " + "tall." +
  "\n" + "Course:" + " " + course + "." +
  "\n" + "With ID number :" + " " + IDno + "." +
  "\n" + "I belong in:" + " " + department + "." +
  "\n" + "Term : " + " " + term + "." +
  "\n" + "Year Level: " + " " + yearlevel + "." +
  "\n" + "With a GPA of: " + " " GPA +".";
 }

//constructor

 public Student()
 {
  this.course="BSIT";
  this.IDno=20080352;
  this.department="Information and Computer Studies Department";
  this.term="Second Sem";
  this.yearlevel="Second Year";
  this.GPA=2.99;
 }
}  
**----------------------------------------------------------------------------------** 

public class Genius extends Person
{

 private String achievement; 
 private String organization;
 private int IQlevel;
 

 public Genius(String nname, int nage, String naddress, 
  String ngender, int nweight, String nheight, String nachievement, 
  String norganization, int nIQlevel)
 {
 
  super(nname, nage, naddress, ngender, nweight, nheight);
  this.achievement=nachievement;
  this.organization=norganization;
  this.IQlevel=nIQlevel;
 }

 public string whoIam()
 {
  String identity;
  return identity = "I am" + " " + name + "." +
  "\n" + age + " " + "years old" + "." +
  "\n" + "I live at" + " " + address + "." +
  "\n" + "I am a" + " " + gender + "." +
  "\n" + "Weighs" + " " + weight + " " +"kgs." + 
  "\n" + "And stands" + " " +height +" " + "tall." + 
  "\n" + "Achievement/s:" + " " + achivement + "." +
  "\n" + "Organization I belong : " + " " + organization + "." +
  "\n" + "My IQ level is: " + " " + IQlevel + ".";

 }

//constructor

 public Genius()
 {
  this.achievement="I have thousands of awards and trophies";
  this.organization="Genius People of the Philippines Inc.";
  this.IQlevel=100;
 }
}

**----------------------------------------------------------------------------------** 

public class Employee extends Person
{
 private int Empnum; 
 private int PagIbignum;
 private String SSSnum;
 private String PhilHealthnum;
 private String designation;
 private String company;
 private double hourswork; 
 private double payRate;
 

 public Employee(String nname, int nage, String naddress, 
  String ngender, int nweight, String nheight, 
  int nEmpnum, int nPagIbignum, String nSSSnum,
  String nPhilHealthnum, String ndesignation,
  String ncompany, double nhourswork,
  double npayRate)
 {
  super(nname, nage, naddress, ngender, nweight, nheight);  
  this.Empnum=Empnum;
  this.PagIbignum=nPagIbignum;
  this.SSSnum=nSSSnum;
  this.PhilHealth=nPhilhealth; 
  this.designation=ndesignation;
  this.company=ncompany;
  this.hourswork=nhourswork; 
  this.payRate=npayRate; 
  this.salary=nsalary;
 }


 public string whoIam()
 {
  String identity;
  return identity = "I am" + " " + name + "." +
  "\n" + age + " " + "years old" + "." +
  "\n" + "I live at" + " " + address + "." +
  "\n" + "I am a" + " " + gender + "." +
  "\n" + "Weighs" + " " + weight + " " +"kgs." + 
  "\n" + "And stands" + " " +height +" " + "tall." + 
  "\n" + "With Employee Number :" + " " + Empnum + "." +
  "\n" + "Pag-Ibig Number : " + " " + PagIbignum + "." +
  "\n" + "SSS Number : " + " " + SSSnum + "." +
  "\n" + "PhilHealth Number : " + PhilHealthnum + "." +
  "\n" + "Designation :" +" " designation + "." +
  "\n" + "Working at :" + " " company + "." + 
  "\n" + "And has a salary of :" + " " salary+ ".";
 }

 public double gethourswork()
 {
  return hourswork;
 }

 public double getpayRate()
 {
  return payRate;
 }

 public double salary()
 {
  return (payRate * hourswork);
 }

//constructor

 public Employee()
 {
  this.Empnum = 143;
  this.PagIbignum = "123-4567-811";
  this.SSSnum = "123-7895-411"; 
  this.PhilHealthnum = "146-1311-388";
  this.designation = "Clerk-I";
  this.company = "Unilever";  
  this.hourswork = 8.5;
  sthis.payRate = 150.95;
 }
}

**----------------------------------------------------------------------------------**

public class FulltimeEmployee extends Emloyee

 private String benefits;
 private String incentives;
 
 public FullTimeEmployee((int nEmpnum, int nPagIbignum, String nSSSnum,
  String nPhilHealthnum, String ndesignation,
  String ncompany, double nhourswork,
  double npayRate, double nsalary, String nbenefits, String nincentives)
 {
  super(nEmpnum, nPagIbignum, nSSSnum, nPhilHealthnum, ndesignation, ncompany,
  nhourswork, npayRate, nsalary);
  this.benefits=nbenefits;
  this.incentives=nincentives;
 }

 public string whoIam()
 {
  String identity;
  return identity = "I am" + " " + name + "." +
  "\n" + age + " " + "years old" + "." +
  "\n" + "I live at" + " " + address + "." +
  "\n" + "I am a" + " " + gender + "." +
  "\n" + "Weighs" + " " + weight + " " +"kgs." + 
  "\n" + "And stands" + " " +height +" " + "tall." + 
  "\n" + "With Employee Number :" + " " + Empnum + "." +
  "\n" + "Pag-Ibig Number : " + " " + PagIbignum + "." +
  "\n" + "SSS Number : " + " " + SSSnum + "." +
  "\n" + "PhilHealth Number : " + PhilHealthnum + "." +
  "\n" + "Designation :" +" " designation + "." +
  "\n" + "Working at :" + " " company + "." + 
  "\n" + "And has a salary of :" + " " salary+ "." +
  "\n" + "Benefits: " + " " + benefits + "." +
  "\n" + "Incentives: " + " " + incentives + ".";

 }

//constructor

 public FullTimeEmployee()
 {
  this.benefits="Retirement Fees, Bonuses in Salary";
  this.incentives="Worry-free about the contract, holidays & vacation trips";
 }
}


**----------------------------------------------------------------------------------** 

public class PartTimeEmployee extends Employee

 private String contract;
  

 public PartTimeEmployee(int nEmpnum, int nPagIbignum, String nSSSnum,
  String nPhilHealthnum, String ndesignation,
  String ncompany, double nhourswork,
  double npayRate, double nsalary, String ncontract)
 {
 
  super(nEmpnum, nPagIbignum, nSSSnum, nPhilHealthnum, ndesignation, ncompany,
  nhourswork, npayRate, nsalary);
  this.contract=ncontract;
 }

 public string whoIam()
 {
  String identity;
  return identity = "I am" + " " + name + "." +
  "\n" + age + " " + "years old" + "." +
  "\n" + "I live at" + " " + address + "." +
  "\n" + "I am a" + " " + gender + "." +
  "\n" + "Weighs" + " " + weight + " " +"kgs." + 
  "\n" + "And stands" + " " +height +" " + "tall." + 
  "\n" + "With Employee Number :" + " " + Empnum + "." +
  "\n" + "Pag-Ibig Number : " + " " + PagIbignum + "." +
  "\n" + "SSS Number : " + " " + SSSnum + "." +
  "\n" + "PhilHealth Number : " + PhilHealthnum + "." +
  "\n" + "Designation :" +" " designation + "." +
  "\n" + "Working at :" + " " company + "." + 
  "\n" + "And has a salary of :" + " " salary+ "." +
  "\n" + "My contract is up to: " + " " + contract + ".";
 }
 
 
//constructor

 public PartTimeEmployee()
 {
  this.contract="6 months";
 }
}

**----------------------------------------------------------------------------------** 

public class PersonTester
{
 public static void main(String [] args)
 {
 System.out.println("WELCOME to our simple INHERITANCE Program");
 System.out.println();
 
 Person Student= new Person();
 System.out.println(Student.whoIam());
 System.out.println();
 
 Person Employee=new Person();
 System.out.println(Employee.whoIam());
 System.out.println();
 
 Person Genius=new Person();
 System.out.println(Genius.whoIam());
 System.out.println();
 
 Employee PartTimeEmployee =new Employee();
 System.out.println(PartTimeEmployee.whoIam());
 System.out.println();
 
 Employee FullTimeEmployee();
 System.out.println(FullTimeEmployee.whoIam()); 
 System.out.println();

 System.out.println("PROCESS COMPLETED!");
 System.out.println("Thank you so much!");
 }
 
}


 **------------------------------------------------------------------------------------**