0% found this document useful (0 votes)
15 views6 pages

OOP Lab02 Saadmuhammadkhan 503774

The document outlines a lab assignment for a course in Object Oriented Programming at the National University of Sciences & Technology. It includes three tasks with Java code examples: collecting student information, calculating the product of three numbers, and determining the day of the week based on a given date. Each task is presented with its respective code and expected output.

Uploaded by

XdCatalyst Khan
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)
15 views6 pages

OOP Lab02 Saadmuhammadkhan 503774

The document outlines a lab assignment for a course in Object Oriented Programming at the National University of Sciences & Technology. It includes three tasks with Java code examples: collecting student information, calculating the product of three numbers, and determining the day of the week based on a given date. Each task is presented with its respective code and expected output.

Uploaded by

XdCatalyst Khan
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/ 6

NATIONAL UNIVERSITY OF SCIENCES & TECHNOLOGY

SCHOOL OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCE


FACULTY OF COMPUTING

CS 212: Object Oriented Programming


Lab 02: Getting Started With JAVA

NAME SAAD MUHAMMAD KHAN


CMS ID 503774
CLASS / SECTION BSCS-14C
INSTRUCTOR JAUDAT MAMOON
LAB ENGINEER NADEEM NAWAZ
LAB TASKS
Task#01:
CODE:
import java.util.*;

public class tsk1{

public static void main(String[] args)


{
Scanner MySC = new Scanner(System.in);

String student_name;
int cms_id;
String student_year;
int no_of_courses;
float GPA;

System.out.println("Enter you name: ");


student_name = MySC.nextLine();
System.out.println("Enter you CMS Id: ");
cms_id = MySC.nextInt();
MySC.nextLine();
System.out.println("Enter you year
(e.g. \'Freshman\', \'Sophomore\', \'Junior\', \'Senior\'): ");
student_year = MySC.nextLine();
System.out.println("Enter your number of courses: ");
no_of_courses = MySC.nextInt();
System.out.println("Enter you GPA (0.00 -- 4.00): ");
GPA = MySC.nextFloat();

System.out.println();
System.out.println("+-----------------------+");
System.out.println("Name: " + student_name);
System.out.println("CMS Id: " + cms_id);
System.out.println("Year: " + student_year);
System.out.println("Courses: " + no_of_courses);
System.out.println("GPA: " + GPA);
System.out.println("+-----------------------+");

}
}
OUTPUT:
Task#02:
CODE:
import java.util.*;

public class tsk2 {

public static void main(String[] args)


{
Scanner MySC = new Scanner(System.in);

System.out.println("Enter first number: ");


float x = MySC.nextFloat();

System.out.println("Enter second number: ");


float y = MySC.nextFloat();

System.out.println("Enter third number: ");


float z = MySC.nextFloat();

float result = x*y*z;

System.out.println("Product: " + result);

}
}

OUTPUT:
Task#03:
CODE:
import java.util.*;

public class tsk3 {


public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);

System.out.print("Enter the year (e.g. 2025): ");


int year = scanner.nextInt();
System.out.print("Enter the month (1-12): ");
int m = scanner.nextInt();
System.out.print("Enter the day of the month (1 - 31): ");
int q = scanner.nextInt();

if (m == 1 || m == 2)
{
m += 12;
year--;
}

int j = year / 100;


int k = year % 100;
int h = (q + (26 * (m + 1)) / 10 + k + k / 4 + j / 4 + (5 * j)) % 7;

String dayOfWeek = "";


switch(h)
{
case 0: dayOfWeek = "Saturday"; break;
case 1: dayOfWeek = "Sunday"; break;
case 2: dayOfWeek = "Monday"; break;
case 3: dayOfWeek = "Tuesday"; break;
case 4: dayOfWeek = "Wednesday"; break;
case 5: dayOfWeek = "Thursday"; break;
case 6: dayOfWeek = "Friday"; break;
default: dayOfWeek = "Invalid!"; break;
}

System.out.println("The day of the week is: " + dayOfWeek);

}
}
OUTPUT:

 END 

You might also like