Practical No:1 AIM: Java Basics and Introduction: Name: Enrollment Number
Practical No:1 AIM: Java Basics and Introduction: Name: Enrollment Number
3. Basic Syntax: It includes a class and a main method (public static void main(String[]
args)) as the entry point.
CODE:
OUTPUT:
CONCLUSION:
This simple Java program demonstrates the fundamental concepts of Java programming,
including defining a class, using the main method as the entry point, and outputting a message to
the console using System.out.println(). It serves as a basic introduction to syntax, string handling,
and printing output in Java.
CODE:
OUTPUT:
CONCLUSION:
This Java program demonstrates how to take user input, perform a simple addition, and display
the result. It highlights key concepts like using the Scanner class for input, defining methods for
functionality, and following basic Java syntax.
2. Functions: Defines methods like add(), subtract(), multiply(), and divide() to perform
tasks.
3. Input Handling: Takes user input for numbers and the operation using Scanner.
5. Control Flow: The switch statement handles different operations, with break to exit after
execution.
CODE:
OUTPUT:
CONCLUSION:
This program demonstrates a basic calculator using Java's switch-case and functions, allowing
users to perform simple arithmetic operations. The use of functions makes the code modular and
easy to maintain, while the switch-case structure handles user input efficiently.
Name: Sankesara Siddhant Vishalkumar
Enrollment number: 230149
Practical No :2
AIM: Arrays, Classes, and Overloading
A) Program demonstrating arrays in Java.
CONCEPT USED:
The concepts used in this Java program are:
2. Basic Operations: The program performs operations like sum, average, minimum, and
maximum on the elements of the ArrayList.
3. Enhanced For Loop: An enhanced for loop (for (int i : a)) is used to iterate over the
elements of the ArrayList.
4. Math Operations: It calculates sum, average, minimum, and maximum values using basic
arithmetic and conditional checks.
5. Output: The program prints the results of the calculations using System.out.println().
CODE:
OUTPUT:
CONCLUSION:
This Java program demonstrates how to use an ArrayList to store and manipulate a collection of
integers. It performs basic calculations like sum, average, minimum, and maximum, showcasing
the use of loops, conditional statements, and arithmetic operations to process data efficiently.
1. Class: Student is a class that defines a blueprint for student objects, with fields like name,
rollNo, and marks.
2. Object: An object student is created using the Student class to represent a specific student
with particular details.
3. Constructor: The constructor Student(String name, int rollNo, int[] marks) initializes the
object's fields when it is created.
4. Instance Variables: name, rollNo, and marks are instance variables that store
information specific to each object.
5. Method: The method displayDetails() performs operations on the instance variables and
displays the student's information.
6. Array: An array marks stores multiple values (marks for 5 subjects in this case).
7. Looping: A for-each loop is used to iterate through the marks array to calculate the total
marks.
8. Object Method Invocation: The student.displayDetails() call demonstrates invoking a
method on an object to perform an action.
CODE:
OUTPUT:
CONCLUSION:
This program demonstrates key Object-Oriented Programming concepts in Java, such as defining
a class, creating objects, using constructors for initialization, and encapsulating behavior within
methods. It shows how to store and manipulate data (like student marks) in an object-oriented
way.
3. Method Overloading: Addition overloads the add method to handle different numbers
and types of parameters (int, double).
CONCLUSION:
The code highlights method and constructor overloading, showcasing flexibility in handling
different inputs. Using inner classes keeps related functionality organized, demonstrating
modularity and key OOP principles like encapsulation and reusability.
Name: Sankesara Siddhant Vishalkumar
Enrollment number: 230149
Practical No :3
AIM: Inheritance and Mathematical Operations
A) BMI Calculator
CONCEPT USED:
=>Object-Oriented Programming (OOP): It defines a BMI class with attributes (weight,
height), a constructor, and a method (calculateBMI).
=>Encapsulation: The class encapsulates data using instance variables and provides a
constructor for initialization.
=>User Input Handling: The Scanner class is used to take input from the user for weight and
height.
CODE:
OUTPUT:
CONCLUSION:
It effectively calculates BMI using Object-Oriented Programming (OOP) principles. It
demonstrates encapsulation by storing weight and height as instance variables and using a
constructor for initialization.
The program defines reusable methods (determinant and solveEquations) to compute the
determinant and solve equations using Cramer’s Rule.
Conditional Statements:
The Scanner class is used to take coefficients as input from the user, demonstrating input
handling in Java.
Mathematical Computation:
Uses Cramer’s Rule to solve a system of two linear equations in two variables (x and y).
CODE:
OUTPUT:
CONCLUSION:
It demonstrates modularity with separate methods for determinant calculation and equation
solving. The program also ensures user interaction using the Scanner class for input handling and
applies conditional checks to handle cases where no unique solution exists.
2. Methods and Modularity: The sorting logic is encapsulated in the sortDescending method
for reusability.
3. User Input Handling: The Scanner class is used to take three integer inputs from the user.
CODE:
OUTPUT:
CONCLUSION:
This program efficiently sorts three numbers in descending order using a basic swapping
algorithm. It demonstrates modularity, conditional logic, and user input handling in Java.
Name: Sankesara Siddhant Vishalkumar
Enrollment number: 230149
Practical No :4
AIM: Inheritance and its concepts
CONCEPT USED:
1. Class & Object: vehicle, landvehicle, and Car are classes, and an object of Car is created
in main.
2. Constructor & Inheritance: landvehicle extends vehicle, and Car extends landvehicle to
reuse properties.
6. User Input & Scanner Class: Scanner takes user input for brand, wheels, and model.
2. Car object is created using the constructor, calling super to initialize parent class
attributes.
CONCLUSION:
This program demonstrates OOP concepts such as inheritance, interfaces, constructors, and
method overriding in Java. It efficiently models a vehicle hierarchy, ensuring code reusability
and structured design.