0% found this document useful (0 votes)
4 views9 pages

Object-Oriented Programming Assignment

This document contains the solutions to 3 questions for an object oriented programming assignment submitted by Muhammad Awais. The first question creates a Date class with data members for day, month and year. It includes a constructor to initialize a date object with valid values and methods to get/set date values and display the date. The second question asks to create a Circle class to calculate the area of a circle with appropriate fields and methods. The third question creates an Employee class with data members for first name, last name, years of service and monthly salary. It includes logic to not set salary if monthly salary is not positive, and gives a 10% raise if years of service is over 10. Two employee objects are

Uploaded by

Awais
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views9 pages

Object-Oriented Programming Assignment

This document contains the solutions to 3 questions for an object oriented programming assignment submitted by Muhammad Awais. The first question creates a Date class with data members for day, month and year. It includes a constructor to initialize a date object with valid values and methods to get/set date values and display the date. The second question asks to create a Circle class to calculate the area of a circle with appropriate fields and methods. The third question creates an Employee class with data members for first name, last name, years of service and monthly salary. It includes logic to not set salary if monthly salary is not positive, and gives a 10% raise if years of service is over 10. Two employee objects are

Uploaded by

Awais
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ASSIGNMENT NO.

1
OBJECT ORIENTED
PROGRAMMING

SUBMITTED BY:
MUHAMMAD AWAIS
SP15-BSE-101
BSSE-2B
SUBMITTED TO:
MAAM NAJMUN NISA

Q1: Create a data class that includes 3 data members


variables: day, month, year. Provide a constructer that
can inialize a data object with the valid values. Provide
get and set functions, display date method.
Solution:

import [Link];
public class Quiz_Q1

{
int day,month,year;
Quiz_Q1(int x, int y, int z)
{

if(x>0 && x<=31 && (y==1 || y==3|| y==5||


y==7||y==8||y==10||y==12 ) && z>999)
{
day=x;
month=y;
year=z;

}
else if(x>0 && x<=30 && (y==4 || y==6||
y==9|| y==11 ) && z>999)
{
day=x;
month=y;
year=z;
}
else if(x>0 && x<=29 && y==2 && z%4==0
&& z%100!=0)
{ [Link]("its a leap year.");
day=x;
month=y;
year=z;
}
else if(x>0 && x<29 && y==2 && z>999)
{
day=x;
month=y;

year=z;
}
else
{
[Link]("Date is Invalid... Try
Again");
[Link](0);
}
}
void show ()
{
[Link]("Date is
"+day+"/"+month+"/"+year);
}
public static void main(String[]args)
{
int l,m,n;
Scanner input = new Scanner([Link]);
[Link]("Enter Date");

l=[Link]();
[Link]("Enter Month");
m=[Link]();
[Link]("Enter Year");
n=[Link]();
Quiz_Q1 date=new Quiz_Q1(l,m,n);
[Link]();
}
}

Q2: Create a circle class to find the area of the circle with
the appropriate fields and member functions.
Q3: Create an employ class that includes three variables:
First name, last name, year of service and monthly salary.
If monthly salary is not positive then dont set its value.
Create two employs objects and display objects yearly
salary. Give each employ 10% raise if year of service is
greater than 10 years.
Solution:
import [Link].*;
public class Assignment_Q3
{

String FirstName=null;
String LastName=null;
int Salary=0;
int MonthlySalary=0;
int YearsOfService=0;

Assignment_Q3()
{
[Link]("-To check the annual salary of an
employ-" + "\n");
}

void input ()
{
Scanner input = new Scanner([Link]);
[Link]("Enter the First name of the Employ");
FirstName=[Link]();
[Link]("Enter the Last name of the Employ");
LastName=[Link]();
[Link]("Enter the Monthly Salary of the
Employ");

MonthlySalary=[Link]();
[Link]("Enter the number of Service Year of
the Employ");
YearsOfService=[Link]();
conditions();

}
void conditions()
{
if(MonthlySalary<=0)
Salary=0;

else if(YearsOfService > 10)


more_10();

else
Salary=MonthlySalary*12;
}

void more_10()
{

Salary=MonthlySalary*12;
Salary=Salary+(Salary*10/100);

}
void output()
{
[Link]("\n"+"The Name of the employ is
"+FirstName+" "+LastName);
[Link]("The Employ has done service for
"+YearsOfService+" Years");
[Link]("The annual salary of the employ is
"+Salary+"\n");
}

public static void main(String[]args)


{
Assignment_Q3 a = new Assignment_Q3();
Assignment_Q3 b = new Assignment_Q3();
[Link]();
[Link]();
[Link]();

[Link]();
}
}

You might also like