Oop
COMSATS UNIVERSITY
ISLAMABAD
DEPARTMENT:
SOFTWARE ENGINEERING
ASSIGNMENT:
OBJECT ORIENTED PROGRAMMING
SUBMITTED BY:
AREEBA SUNDAL(CIIT-SP22-BSE-021WAH)
SUBMITTED TO:
MS. SAMIA ZAFFAR
Oop
Q1: Rectangle Class
CODE:
package javaapplication30;
import [Link];
class rectangle{
private int length;
private int width;
private String color;
void setlength(int l){
length = l;
}
void setwidth(int w){
width = w;
}
void setcolor(String c){
color = c;
Oop
}
int getlength(){
return length;
}
int getwidth(){
return width;
}
String getcolor(){
return color;
}
void calcArea(int l , int w ){
double area = l*w;
[Link]("Area is : "+area);
}
public rectangle(){
}
public rectangle(int l , int w , String c){
length = l;
width = w;
color = c;
Oop
}
public rectangle(rectangle r1){
[Link]("This is copy constructor");
length = [Link];
width = [Link];
color = [Link];
}
}
public class JavaApplication30 {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter length , width and color");
int l = [Link]();
int w = [Link]();
Scanner s = new Scanner([Link]);
String c = [Link]();
rectangle r = new rectangle();
[Link]("this is simple constructor");
[Link](l);
[Link](w);
Oop
[Link](c);
[Link]("details : "+[Link]() +" "+[Link]() +"
"+[Link]());
[Link](l, w);
rectangle r1 = new rectangle(l,w,c);
[Link]("details : "+[Link]() +" "+[Link]() +"
"+[Link]());
[Link](l, w);
rectangle r2 = new rectangle(r1);
[Link]("details : "+[Link]() +" "+[Link]() +"
"+[Link]());
[Link](l, w);
Q2: Date Class
CODE:
package javaapplication31;
import [Link];
Oop
class Date{
private int day;
private int year;
private String month;
void setday(int d){
day = d;
}
void setmonth(String m){
month = m;
}
void setyear(int y){
year = y;
}
int getday(){
return day;
}
int getyear(){
return year;
}
String getmonth(){
return month;
}
Oop
void display(int d , int y , String m ){
[Link]("Date is : "+d + m +y);
}
public Date(){
}
public Date(int d , int y , String m){
[Link]("This is parameterized constructor");
day = d;
year = y;
month = m;
}
public Date(Date d1){
[Link]("This is copy constructor");
day = [Link];
year = [Link];
month = [Link];
}
}
public class JavaApplication31 {
Oop
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter day , year and month");
int d = [Link]();
int y = [Link]();
Scanner s = new Scanner([Link]);
String m = [Link]();
Date d0 = new Date();
[Link]("this is simple constructor");
[Link](d);
[Link](m);
[Link](y);
[Link]("details : "+[Link]() +" "+[Link]() +"
"+[Link]());
[Link](d,y,m);
Date d1 = new Date(d,y,m);
[Link]("details : "+[Link]() +" "+[Link]() +"
"+[Link]());
[Link](d,y,m);
Date d2 = new Date(d1);
[Link]("details : "+[Link]() +" "+[Link]() +"
"+[Link]());
[Link](d,y,m); }
}
Oop