You are on page 1of 14

KARACHI CAMPUS

COURSE: CSC-210 OBJECT-ORIENTED PROGRAMMING LAB


TERM: FALL 2022, CLASS: BCE-3A

Submitted By:

Muhammad Daniyal 02-132212-040

NAME
Enrollment No

Submitted To:

Miss Sidra Mudassir

Signed: Remarks: Score


LAB-04
TASK 01

package com.mycompany.lab4;

import java.util.Scanner;

public class Task1 {

public static void main(String[] args)

Student s= new Student();

Scanner input= new Scanner(System.in);

int a, b;

System.out.println("Enter value of a");

a=input.nextInt();

System.out.println("Enter value of b");

b=input.nextInt();

s.add(a,b);

s.display();
}

class Student {

int c;

public void add(int a, int b)

c=a+b;

public void display()

System.out.println(c);
LAB-04
TASK 2
package com.mycompany.lab4;

public class Task2

public static void main(String[] args) {

Calculator obj=new Calculator(6.0,2.0);

Calculator obj1=new Calculator(2.2f,4.4f);

Calculator obj2=new Calculator(4,2);

Calculator obj3=new Calculator(2,4,5);

class Calculator

{
public Calculator(double a, double b)

System.out.println(a/b);

public Calculator(float a, float b)

System.out.println("Multiplication: " + (a*b));

public Calculator(int a, int b)

System.out.println("Subtractiion: " + (a-b));

public Calculator(double a, double b, double c)

System.out.println("Addition: "+(a+b+c));

TASK 3
package com.mycompany.lab4;

import java.util.Scanner;

public class Task3 {

public static void main(String[] args) {

String name1, name2, name3, model, speed, location, model2;

double weight;

Scanner input= new Scanner(System.in);

System.out.println("================================");

System.out.println("-------BICYCLE INFORMATION------");

System.out.println("================================");

System.out.println("Enter the Name");

name1=input.next();

System.out.println("Enter the Location");

location=input.next();

Information bicycle= new Information( name1, location);

System.out.println("--------------------------------");

System.out.println("================================");
System.out.println("--------------CAR---------------");

System.out.println("================================");

System.out.println("");

System.out.println("Enter the Name of Driver");

name2=input.next();

System.out.println("Enter the Model");

model=input.next();

System.out.println("Enter the Speed");

speed=input.next();

Information car= new Information(name2, model, speed);

System.out.println("--------------------------------");

System.out.println("================================");

System.out.println("-------------LORRY--------------");

System.out.println("================================");

System.out.println("");

System.out.println("Enter the Name");

name3=input.next();

System.out.println("Enter the Model");

model2=input.next();

System.out.println("Enter the Weight");


weight=input.nextDouble();

Information cart= new Information(name3, model2, weight);

System.out.println("--------------------------------");

class Information

String name1, name2, name3, model, speed, location, model2;

double weight;

public Information(String name1, String location)

this.name1=name1;

this.location=location;

System.out.println(" Rider Name: " + name1);

System.out.println("Location: "+ location);

public Information(String name2, String model, String speed)


{

this.name2=name2;

this.model=model;

this.speed=speed;

System.out.println("Driver Name: " +name2 );

System.out.println("Model Name: " +model );

System.out.println("Speed: " +speed );

public Information(String name3, String model2, double weight)

this.name3=name3;

this.model2=model2;

this.weight=weight;

System.out.println("Name : " +name3 );

System.out.println("Model : " +model2 );

System.out.println("WeightCarried: " +weight );

TASK 5
package com.mycompany.lab4;

import java.util.Scanner;

public class Task5 {

public static void main(String[] args)

Scanner sc = new Scanner(System.in);

String str;

System.out.print("Enter a string: ");

str = sc.nextLine();

int count = 0;

for(int i = 0; i < str.length(); i++)

if(isVowel(str.charAt(i)))

count++;

System.out.println("Number of vowels: " + count);


} public static boolean isVowel(char letter)

{ return switch (letter) {

case 'a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U' -> true;

default -> false;

};

TASK 6
package com.mycompany.lab4;

import java.util.Scanner;

public class Task1 {

class Student {

Scanner input = new Scanner(System.in);

String firstName,lastName;

int id;

public Student(String firstName, String lastName, int id){

this.firstName = firstName;

this.lastName = lastName;

this.id = id;

void setStudent() {

System.out.println("Enter first 1st name: ");

firstName = input.next();

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

lastName = input.next();

System.out.println("Enter id: ");


id = input.nextInt();

public Student(){

setStudent();

int getId(){

return id;

String getFullName(){

return firstName+" "+lastName;

class Lab4

public static void main(String[] args)

Student sd1 = new Student();

System.out.println("Id of sd1: "+sd1.getId());


System.out.println("FullName of sd1: "+sd1.getFullName());

System.out.print("\n \n");

Student sd2 = new Student("Sharjeel","Baig",2);

System.out.println("Id of sd2: "+sd2.getId());

System.out.println("FullName of sd2: "+sd2.getFullName());

You might also like