LAB ASSIGNMENT # 1
Object Oriented Programming
Submitted by: Syed Ahmad Hussain
Registration No.: SP18-BSE-108
Submitted to: Madam Saneeha Amir
COMPUTER LAB 7
COMSATS ISLAMABAD
Class Circle:
public class circle {
int radius;
public void setParameters(int r){
radius = r;
}
public void display(){
[Link](radius);
}
public void calculateCircumference(){
double circum;
circum = 2*3.14*radius;
[Link]("Circumference of a circle" + circum);
}
public void calculateArea(){
double area;
area = 3.14*(radius*radius);
[Link](radius);
}
}
Runner:
public static void main(String[] args) {
circle c1 = new circle();
[Link](8);
[Link]();
[Link]();
[Link]();
circle c2 = new circle();
[Link](6);
[Link]();
[Link]();
[Link]();
}
Class Rectangle:
public class Rectangle {
int length,width;
public void setParameters(int l,int w){
length = l;
width = w;
}
public void display(){
[Link]("Length is :" + length + " width is " + width);
}
public boolean checksquare(){
if (length==width)
return true;
else return false;
}
public void calculateArea(){
double area;
area = length*width;
[Link](area);
}
Runner:
Rectangle r1 = new Rectangle();
[Link](4, 6);
[Link]();
[Link]();
[Link]();
Rectangle r2 = new Rectangle();
[Link](5, 7);
[Link]();
[Link]();
[Link]();
Class Account:
public class account {
double balance;
int yearofOpening;
String CNIC ;
public void setParameters(double b,int y,String c){
balance = b;
yearofOpening = y;
CNIC = c;
}
public void display(){
[Link]("balance is " + balance +
" year of opening is" + yearofOpening +
"CNIC is" + CNIC);
}
public void withdraw(int w){
balance = balance - w;
}
public void deposit(int d){
balance = balance + d;
}
public boolean validCNIC(){
if ([Link]() == 13)
return true;
else return false;
}
}
Runner:
account a1 = new account();
[Link](5000, 2015, "6110106855343");
[Link](1000);
[Link](500);
[Link]();
account a2 = new account();
[Link](1000, 2017, "6110106855456");
[Link](2000);
[Link](1000);
[Link]();
Class Marks:
public class marks {
int sub1;
int sub2;
int sub3;
public void setparameters(int s1,int s2,int s3){
sub1 = s1;
sub2 = s2;
sub3 = s3;
}
public void display(){
[Link]("sub 1" + sub1 + "sub 2" + sub2 + "sub 3" + sub3);
}
public void sum(){
int sum;
sum = sub1+sub2+sub3;
}
public void percentage(){
int sum = sub1+sub2+sub3;
int percentage = (sum/300) * 100;
[Link]("percentage is" + percentage+"%");
}
public void checkFailure(){
double percentage = ((sub1+sub2+sub3)/300) * 100;
if (percentage<50)
[Link]("Fail");
else [Link]("pass");
}
}
Runner:
marks m1 = new marks();
[Link](56, 68, 80);
[Link]();
[Link]();
[Link]();
[Link]();
marks m2 = new marks();
[Link](56, 68, 80);
[Link]();
[Link]();
[Link]();
[Link]();
Class Point:
public class point {
int x;
int y;
public void setparameters(int x1,int y1){
x = x1;
y = y1;
}
public void display(){
[Link]("x =" + x + "y = " + y);
}
public void move(int dx,int dy){
x = x + dx;
y = y + dy;
}
public boolean checkorigin(){
if (x==0 & y==0)
return true;
else return false;
}
}
Runner:
point p1 = new point();
[Link](4, 5);
[Link](2, 3);
[Link]();
[Link]();
point p2 = new point();
[Link](5, 6);
[Link](4, 3);
[Link]();
[Link]();
Class book:
public class book {
String author;
String chapterNames[] = new String[5];
public void setparameters(String a,String[]cn){
author = a;
for(int i=0; i<5; i++)
chapterNames[i] = cn[i];
}
public void display(){
[Link]("Author is " + author);
for(int i=0; i<5; i++)
[Link](chapterNames[i]);
}
public boolean checkIfAuthorNameStartsWithA(){
if ([Link]("A"))
return true;
else return false;
}
public boolean searchChapter(String sc){
for(int i=0; i<5; i++)
if ([Link](chapterNames[i]))
return true;
else return false;
return false;
}
}
Runner:
String[] chapters= {"cho1","cho2","cho3","cho4","cho5"};
book b1 = new book();
[Link]("Charles Babbage", chapters);
[Link]();
[Link]("cho1");
[Link]();
String[] chapters1= {"cho1","cho2","cho3","cho4","cho5"};
book b2 = new book();
[Link]("Umaira Ahmed", chapters1);
[Link]();
[Link]("cho2");
[Link]();
Class student:
public class student {
String name;
double GPA;
String subjects[] = new String[5];
String email;
public void setparameters(String n, double gpa, String[]s,String e){
name = n;
GPA = gpa;
email = e;
for(int i=0; i<5; i++)
subjects[i] = s[i];
}
public void dispay(){
[Link]("name:" + name +
"GPA is " + GPA +
"email is" + email);
for(int i=0; i<5; i++)
[Link](subjects[i]);
}
public boolean Searchsubject(String subject){
for(int i=0; i<5; i++)
if ([Link](subjects[i]))
return true;
else return false;
return false;
}
public void checkprob(){
if (GPA < 2.0)
[Link]("Prob");
else
[Link]("Pass");
}
public boolean validateEmail(){
if ([Link]("@.com"))
return true;
else return false;
}
}
Runner:
String[] sub= {"maths","english","urdu","islamiat","physics"};
student s1 = new student();
[Link]("Ahmad", 3.0, sub, "[email protected]");
[Link]();
[Link]();
[Link]("urdu");
[Link]();
String[] sub1= {"maths","english","urdu","islamiat","physics"};
student s2 = new student();
[Link]("Saad", 2.7, sub1, "[email protected]");
[Link]();
[Link]();
[Link]("english");
[Link]();