Lab 8 Oop
Lab 8 Oop
TASK 1:
SOOURCE CODE:
public static void main(String[] args) {//Main method to display working of code
System.out.println(b1.toString());
System.out.println(b2.toString());
class Book{
//attributes of book
public Book() {
this.price = 0;
this.quantity = 0;
this.bookName = name;
this.author = author;
this.price = price;
this.quantity = 0;
this.bookName = name;
this.author = author;
this.price = price;
this.quantity = qty;
//getters
return bookName;
}
public Author getAuthor() {
return author;
return quantity;
return price;
//setters
this.price = price;
this.quantity = qty;
class Author{
//attributes of authors
//constructors
public Author() {
this.name = "jamal";
this.email = "[email protected]";
this.gender = 'm';
this.name = name;
this.email = email;
this.gender = gender;
// getter
}
OUTPUT:
TASK 2:
SOOURCE CODE:
System.out.println(faculty.toString());
System.out.println(student.toString());
class Date{
//atributes of date
//contructors
public Date() {
this.date = 1;
this.month = 1;
this.year = 2000;
this.date = date;
this.month = month;
this.year = year;
//getters
return date;
return month;
return year;
}
class JobDescription{
//attrivbutes
//constructors
public JobDescription() {
this.designation = "";
this.salary = 0;
this.teachingLoad = 0;
this.designation = designation;
this.salary = salary;
this.teachingLoad = teachingLoad;
}
//getters
return designation;
return salary;
return teachingLoad;
//setters
this.designation = designation;
this.salary = salary;
this.teachingLoad = teachingLoad;
}
//tostring method to display output
class Person{
//attributes
//constructors
public Person() {
this.name = "";
this.cnic = "";
this.email = "";
this.contactNumber = 0;
}
public Person(String name, String cnic, String email, int contactNumber, Date date) {
this.name = name;
this.cnic = cnic;
this.email = email;
this.contactNumber = contactNumber;
this.date = date;
//getters
return name;
return cnic;
return email;
return contactNumber;
return date.toString();
}
//setters
this.name = name;
this.cnic = cnic;
this.email = email;
this.contactNumber = contactNumber;
this.date = date;
//attributes
//constructors
public Faculty() {
this.officeNumber = 0;
this.officeNumber = officeNumber;
this.jobDescription = jobDescription;
public Faculty(String name, String cnic, String email, int contactNumber, Date date, int officeNumber,
JobDescription jobDescription) {
this.officeNumber = officeNumber;
this.jobDescription = jobDescription;
//getters
return officeNumber;
}
public String getJobDescription() {
return jobDescription.toString();
//setter
this.officeNumber = officeNumber;
return "Faculty:\nName = " + this.getName() + "\nCnic = " + this.getCnic() + "\nEmail = " + this.getEmail() +
"\nContact Number = " + this.getContactNumber() + "\nHiring Date = " + this.getDate() + "\nOffice Number = " +
this.getOfficeNumber() + "\nJob Description = " + this.getJobDescription() + "\n";
//attributes
//constructors
public Student() {
this.batch = 0;
this.regNumber = 0;
}
public Student(int batch, int regNumber) {
this.batch = batch;
this.regNumber = regNumber;
public Student(String name, String cnic, String email, int contactNumber, Date date, int batch, int regNumber)
{
this.batch = batch;
this.regNumber = regNumber;
//getters
return batch;
return regNumber;
//setters
this.batch = batch;
}
public void setRegNumber(int regNumber) {
this.regNumber = regNumber;
return "Student:\nName = " + this.getName() + "\nCnic = " + this.getCnic() + "\nEmail = " + this.getEmail() +
"\nContact Number = " + this.getContactNumber() + "\nAdmission Date = " + this.getDate() + "\nBatch = " +
this.getBatch() + "\nRegNo = " + this.getRegNumber() + "\n";
OUTPUT: