Professional Documents
Culture Documents
REG NO : 2262070
PROBLEM STATEMENT
Write a Java Program to implement basic arithmetic operations using basic symbols and
operators.
AIM
Implementation of arithmetic operation using basic symbols
PROGRAM
import java.util.Scanner;
if (num2 != 0) {
double quotient = num1 / num2;
System.out.println("Quotient: " + quotient);
} else {
System.out.println("Cannot divide by zero.");
}
if (num2 != 0) {
double remainder = num1 % num2;
System.out.println("Remainder: " + remainder);
} else {
System.out.println("Cannot calculate remainder when dividing by zero."); }
scanner.close();
}
}
2
CS433P Programming Paradigm Lab
OUTPUT
Enter the first number: 15
Enter the second number: 7
Sum: 22.0
Difference: 8.0
Product: 105.0
Quotient: 2.142857142857143
Remainder: 1.0
RESULT
Demonstration of arithmetic operators and if-else conditional statements has been successfully
executed.
3
CS433P Programming Paradigm Lab
REG NO : 2262054 NAME : Denil Jos EXPERIMENT NO 2 : Objects & Strings
DATE : 28/11/2023
PROBLEM STATEMENT
Write a Java Program using objects of Student and Employee by using looping statements. Get
the details of 5 students and display it.
AIM
From main function, create objects of student and employee by using looping statement. Get 5
students details and display it.
PROGRAM
import java.util.Scanner;
class Student {
String name;
int age;
String course;
4
CS433P Programming Paradigm Lab
return String.format("| %-15s | %-5d | %-15s |", name, age, course); }
}
class Employee {
String name;
int age;
String designation;
5
CS433P Programming Paradigm Lab
System.out.println("Enter details for Student " + (i + 1) + ":");
System.out.print("Name: ");
String studentName = scanner.next();
System.out.print("Age: ");
int studentAge = scanner.nextInt();
System.out.print("Course: ");
String studentCourse = scanner.next();
System.out.println("\nRecord Book\n");
System.out.println("Details of 5 Students:");
System.out.printf("| %-15s | %-5s | %-15s |\n", "Name", "Age", "Course"); for
(int i = 0; i < 5; i++) {
6
CS433P Programming Paradigm Lab
System.out.println(students[i].getRecord());
}
System.out.println("\nDetails of 5 Employees:");
System.out.printf("| %-15s | %-5s | %-15s |\n", "Name", "Age", "Designation"); for
(int i = 0; i < 5; i++) {
System.out.println(employees[i].getRecord());
}
scanner.close();
}
}
OUTPUT
Enter details for Student 1:
Name: John
Age: 20
Course: Computer Science
Enter details for Student 2:
Name: Alice
Age: 22
Course: Mathematics
Enter details for Student 3:
Name: Bob
Age: 21
7
CS433P Programming Paradigm Lab
Course: Physics
Enter details for Student
4: Name: Carol
Age: 23
Course: Chemistry
Enter details for Student
5: Name: Dave
Age: 25
Course: Biology
Enter details for Employee
1: Name: ProfA
Age: 40
Designation: Professor
Enter details for Employee
2: Name: DrB
Age: 35
Designation: Associate
Professor Enter details for
Employee 3: Name: ProfC
Age: 45
Designation: Professor
Enter details for Employee
4: Name: DrD
Age: 38
Designation: Assistant
Professor Enter details for
Employee 5: Name: ProfE
Age: 42
8
CS433P Programming Paradigm Lab
Designation: Professor
Record Book
Details of 5 Students:
| Name | Age | Course |
| John | 20 | Computer Science |
| Alice | 22 | Mathematics |
| Bob | 21 | Physics |
| Carol | 23 | Chemistry |
| Dave | 25 | Biology |
Details of 5 Employees:
| Name | Age | Designation |
| ProfA | 40 | Professor |
| DrB | 35 | Associate Professor |
| ProfC | 45 | Professor |
| DrD | 38 | Assistant Professor |
| ProfE | 42 | Professor |
RESULT
Thus the program to implement the Student and Employee details by using Java has been
implemented successfully & verified.
9
CS433P Programming Paradigm Lab
REG NO : 2262054 NAME : Denil Jos EXPERIMENT NO 3a: Array
Implementation
DATE : 12/12/2023
ARRAY IMPLEMENTATION
PROBLEM STATEMENT
Write a Java program to get Student & Faculty details using arrays.
AIM
From main function, implement Student & Faculty information using arrays.
PROGRAM
import java.util.Scanner;
class Person {
String name;
int age;
10
CS433P Programming Paradigm Lab
@Override
public String getRecord() {
return super.getRecord() + String.format(" %-15s |", course); }
}
@Override
public String getRecord() {
return super.getRecord() + String.format(" %-15s |", designation); }
}
11
CS433P Programming Paradigm Lab
12
CS433P Programming Paradigm Lab
}
scanner.close();
}
}
OUTPUT
Enter Student Name: John
Enter Student Age: 20
Enter Student Course: ComputerScience
Enter Student Name: Alice
Enter Student Age: 22
Enter Student Course: Mathematics
Enter Student Name: Bob
Enter Student Age: 21
Enter Student Course: Physics
Enter Student Name: Carol
Enter Student Age: 23
Enter Student Course: Chemistry
13
CS433P Programming Paradigm Lab
Enter Student Name: Dave
Enter Student Age: 25
Enter Student Course: Biology
Enter Faculty Name: ProfA
Enter Faculty Age: 40
Enter Faculty Designation: Professor
Enter Faculty Name: DrB
Enter Faculty Age: 35
Enter Faculty Designation: AssociateProfessor
Enter Faculty Name: ProfC
Enter Faculty Age: 45
Enter Faculty Designation: Professor
Enter Faculty Name: DrD
Enter Faculty Age: 38
Enter Faculty Designation: AssistantProfessor
Enter Faculty Name: ProfE
Enter Faculty Age: 42
Enter Faculty Designation: Professor
| Name | Age | Course | Designation |
| John | 20 | ComputerScience | Professor | | Alice | 22 |
Mathematics | AssociateProfessor | | Bob | 21 | Physics |
Professor |
| Carol | 23 | Chemistry | AssistantProfessor | | Dave | 25
| Biology | Professor |
RESULT
Implementation of arrays has been done successfully and without errors.
14
CS433P Programming Paradigm Lab
REG NO : 2262054 NAME : Denil Jos EXPERIMENT NO 3b: Constructor
Overloading
DATE : 12/12/2023
CONSTRUCTOR OVERLOADING
PROBLEM STATEMENT
Write a Java program to find the area of a shape with 4 sides where the input of each side may or
may not be given.
AIM
To demonstrate the working of Java constructor overloading.
PROGRAM
import java.util.Scanner;
class Shape {
double side1, side2, side3, side4;
public Shape() {
// Default constructor
}
15
CS433P Programming Paradigm Lab
this.side1 = side1;
this.side2 = side2;
}
16
CS433P Programming Paradigm Lab
System.out.print("Enter the length of side 3 (or 0 if not provided): ");
double side3 = scanner.nextDouble();
scanner.close();
}
}
OUTPUT
Enter the length of side 1 (or 0 if not provided): 5
Enter the length of side 2 (or 0 if not provided): 8
Enter the length of side 3 (or 0 if not provided): 0
Enter the length of side 4 (or 0 if not provided): 0
Area of the shape: 40.0
RESULT
Implementation of the given program using constructor overloading has been successfully
implemented without errors.
17
CS433P Programming Paradigm Lab
REG NO : 2262054 NAME : Denil Jos EXPERIMENT NO 4a: Code Debugging
DATE : 19/12/2023
CODE DEBUGGING
PROBLEM STATEMENT
Add appropriate code in the subclass and the base class to print the
following. class A {
int i;
void display()
{
}
}
class B
{
void display()
{
System.out.println(j);
}
}
class inheritance_demo
{
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
18
CS433P Programming Paradigm Lab
obj.display();
}
}
AIM
To debug the problem statement and to get the output
PROGRAM
class A {
int i;
void display() {
System.out.print(i + " ");
}
}
class B extends A {
int j;
void display() {
super.display(); // Call display() of class A
System.out.println(j);
}
}
19
CS433P Programming Paradigm Lab
obj.display();
}
}
OUTPUT
1
2
RESULT
Inheritance concept has been successfully implemented without any errors.
20
CS433P Programming Paradigm Lab
REG NO : 2262054 NAME : Denil Jos EXPERIMENT NO 4b: Code Debugging
DATE : 19/12/2023
CODE DEBUGGING
PROBLEM STATEMENT
Add appropriate code to print the following output. Find Out the
appropriate variable names and its data types.
class A
{
}
class B extends A
{
}
class Mainclass
{
public static void main(String args[])
{
B p=new B();
System.out.println("B salary is:"+p.sal);
System.out.println("Bonus of B is:"+p.bonus);
}
}
AIM
To debug the given code and to get the expected output
21
CS433P Programming Paradigm Lab
PROGRAM
class A {
}
class B extends A {
double sal = 4000.0;
double bonus = 10000;
}
public class Mainclass {
public static void main(String args[])
{ B p = new B();
System.out.println("B salary is: " + p.sal);
System.out.println("Bonus of B is: " + p.bonus); }
}
OUTPUT
B salary is: 4000.0
Bonus of B is: 10000
RESULT
Single-level inheritance implemented successfully.
22
CS433P Programming Paradigm Lab
REG NO : 2262054 NAME : Denil Jos EXPERIMENT NO 4c: Code Debugging
DATE : 19/12/2023
CODE DEBUGGING
PROBLEM STATEMENT
Add the appropriate code to print the following output. Use only the child class
object. class Parent
{
void display(){
System.out.println(“Parent”);
}
class Child
{
void display(){
System.out.println(“Child”);
}
}
class MainClass
{
public static void main(String args[]){
}
}
AIM
To debug the given program and to get the expected output.
23
CS433P Programming Paradigm Lab
PROGRAM
class Parent {
void display() {
System.out.println("Parent");
}
}
OUTPUT
Parent
Child
RESULT
Multi-Level inheritance has been successfully implemented without errors.
24
CS433P Programming Paradigm Lab
REG NO : 2262054 NAME : Denil Jos EXPERIMENT NO 4d: Code Debugging
DATE : 19/12/2023
CODE DEBUGGING
PROBLEM STATEMENT
Complete the code to get the following output. Don't change anything in the main class.
In all the classes, you need to show the methods for displaying at least any one of the
output. Demonstrate multilevel inheritance
public class Side
{
}
public class Square extends Side
{
}
public class Cuboid extends Square
{
}
public class MainClass
{
public static void main(String argos[])
{
//Dont Change anything here.
Cuboid C1=new Cuboid();
C1.getValueOfSide();
C1.Display();
}
25
CS433P Programming Paradigm Lab
}
AIM
To debug the given program and to get the desired output
PROGRAM
class Side {
double side;
void getValueOfSide() {
System.out.print("Enter the value of a side: ");
side = 5
}
}
class Square extends Side {
void Display() {
System.out.println("The value of the side is: " + side);
System.out.println("The area of the square is: " + side * side); }
}
26
CS433P Programming Paradigm Lab
OUTPUT
Enter the value of a side : 5
The value of the side is : 5
The area of the square is : 25
The volume of the cuboid is : 125.
RESULT
The given program has been successfully implemented without any errors.
27
CS433P Programming Paradigm Lab
REG NO : 2262054 NAME : Denil Jos EXPERIMENT NO 5 : Access Specifiers
DATE : 5/01/2024
ACCESS SPECIFIERS
PROBLEM STATEMENT
Write a Java program to implement all types of access specifiers.
AIM
To demonstrate access specifiers
-public -private -default -protected
PROGRAM
class AccessSpecifiersDemo {
private int privateVariable = 10;
int defaultVariable = 20;
protected int protectedVariable = 30;
public int publicVariable = 40;
void defaultMethod() {
System.out.println("Default Method");
}
28
CS433P Programming Paradigm Lab
protected void protectedMethod() {
System.out.println("Protected Method");
}
/
// obj.privateMethod(); // Error: privateMethod() has private access
obj.defaultMethod();
obj.protectedMethod();
obj.publicMethod();
}
}
29
CS433P Programming Paradigm Lab
OUTPUT
20
30
40
Default Method
Protected Method
Public Method
RESULT
The implementation of access specifiers has been successfully implemented without any errors.
30
CS433P Programming Paradigm Lab
REG NO : 2262054 NAME : Denil Jos EXPERIMENT NO 6 : Interfaces
DATE : 9/01/2024
INTERFACES
PROBLEM STATEMENT
Write a Java program to implement the area of square, rectangle & circle by using interfaces
with the base class as Shape class.
AIM
To implement interfaces in Java
PROGRAM
interface Shape {
double calculateArea();
}
@Override
public double calculateArea() {
return side * side;
31
CS433P Programming Paradigm Lab
}
}
@Override
public double calculateArea() {
return length * width;
}
}
@Override
public double calculateArea() {
return Math.PI * radius * radius;
32
CS433P Programming Paradigm Lab
}
}
OUTPUT
Area of Square: 25.0
Area of Rectangle: 24.0
Area of Circle: 28.274333882308138
RESULT
The implementation of interfaces in Java has been done successfully without any errors.
33
CS433P Programming Paradigm Lab
REG NO : 2262054 NAME : Denil Jos EXPERIMENT NO 7 : Inner Class
DATE : 16/01/2024
INNER CLASS
PROBLEM STATEMENT
Write a Java program to demonstrate the usage of static, nested and inner class methods.
AIM
To implement static, nested and inner class methods.
PROGRAM
class OuterClass {
private static String staticVariable = "Static Variable in OuterClass";
34
CS433P Programming Paradigm Lab
class InnerClass {
void innerMethod() {
System.out.println("Inner Method in InnerClass");
System.out.println(staticVariable); // Accessing static variable from outer class }
}
}
OUTPUT
outer_x = 10
outer_private = 30
outer_y = 20
RESULT
The implementation of static, inner & nested class has been done successfully without any errors.
35
CS433P Programming Paradigm Lab
PROBLEM STATEMENT
Write a Java program to construct a Login Page UI.
AIM
To implement a Login Page UI in Java.
PROGRAM
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
36
CS433P Programming Paradigm Lab
panel.setLayout(new GridLayout(3, 2));
panel.add(userLabel);
panel.add(userTextField);
panel.add(passwordLabel);
panel.add(passwordField);
panel.add(new JLabel()); // Empty label for spacing
panel.add(loginButton);
frame.add(panel, BorderLayout.CENTER);
frame.setVisible(true);
37
CS433P Programming Paradigm Lab
}
}
OUTPUT
RESULT
The implementation of Login Page UI has been done successfully without any errors.
38