0% found this document useful (0 votes)
16 views

Lab 01

Uploaded by

basit.ul.ibad
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)
16 views

Lab 01

Uploaded by

basit.ul.ibad
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
You are on page 1/ 7

Object Oriented

Programming
Lab# 1
Name: Muhammad Talal
Hamid
Class: BSE-3A
Professor: Sir. Muzaffar Iqbal
Activity Tasks
Task 01:

import java.util.Scanner;
public class Task01 {
public static void main(String [] args){
Scanner in = new Scanner(System.in);
System.out.print("Enter Date: ");
int date = in.nextInt();
System.out.print("Enter Month: ");
int month = in.nextInt();
System.out.print("Enter Year: ");
int year = in.nextInt();
System.out.print("Validity of date: "+checkDate(date,month,year));
}
public static boolean checkDate(int d, int m, int y){
if(y%4 == 0){
if(y%100 != 0){
if(m == 2){
if(d>0 && d<=29){
return true;
}
else
return false;
}
}
else if(y % 400 == 0){
if(m == 2){
if(d>0 && d<=29){
return true;
}
else
return false;
}
}
}
if(m > 0 && m <= 12){
if(m == 2){
if(d > 0 && d<=28 ){
return true;
}
}
else if(m % 2 == 0){
if(d > 0 && d <=30){
return true;
}
}
else
if(d > 0 && d <=31)
return true;
}
return false;
}
}
Output:

Task 02:

import java.util.Scanner;
public class Task02 {
public static void main(String [] args){
Scanner in = new Scanner(System.in);
String [] name = new String[5];
int [] marks = new int[5];
for (int i = 0; i < 5; i++) {
System.out.print("Enter name: ");
name[i] = in.next();
System.out.print("Enter marks: ");
marks[i] = in.nextInt();
}
System.out.println("Students with max marks: ");
maxMarks(name,marks);
}
public static void maxMarks(String[] name, int[] marks){
int index=0;
for (int i = 0; i < 5; i++) {
for (int j = i; j < 5; j++) {
if(marks[i] < marks[j])
index=j;
}
}
for (int i = 0; i < 5; i++) {
if(marks[index] == marks[i]){
System.out.println("Name: "+name[i]);
System.out.println("Marks: "+marks[i]);
}
}
}
}
Output:
Task 03:

import java.util.Scanner;
public class Task03 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num1,num2,num3;
double num4,num5;
System.out.print("Enter three number integers: ");
num1=in.nextInt();
num2=in.nextInt();
num3=in.nextInt();
System.out.print("Enter two float numbers: ");
num4=in.nextDouble();
num5=in.nextDouble();
System.out.println("Sum of two integers: "+add(num1,num2));
System.out.println("Sum of three integers: "+add(num1,num2,num3));
System.out.println("Sum of two float numbers: "+add(num4,num5));
}
public static int add(int a, int b){
return a+b;
}
public static int add(int a, int b, int c){
return a+b+c;
}
public static double add(double a, double b){
return a+b;
}
}
Output:

You might also like