OOPS with Java experiment related to fundamentals

samantaray3001 11 views 11 slides Oct 15, 2024
Slide 1
Slide 1 of 11
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11

About This Presentation

Java experiment related to fundamentals


Slide Content

Object Oriented Programming in Java Laboratory Dr. Aswini Kumar Samantaray Senior Assistant Professor Department of Electronics & Communication Engineering Manipal Institute of Technology Bengaluru

List of Experimets Lab No . Title 1. Simple Java Programs using Control Structures 2. Data Types, Operators and Arrays 3. Classes and Objects 4. Constructors and Static Members 5. Strings 6. Inheritance and Packages 7. Interfaces and Exception Handling 8. Multithreading 9. Generics 10. Input/Output 11. JavaFX and Event Handling -Part I 12. JavaFX and Event Handling -Part II

Assessment Rubrics Internal Assessment Internal Assessment Marks: 60% (60 Marks) The weekly evaluation scheme is as follows: (10 Evaluations) Conduction of experiment – 3 Marks Observation book – 3 Marks Lab record book – 4 Marks Continuous evaluation of 10 experiment for 10 marks each will be evaluate and 100 marks will be scaled down to 60 Marks . End semester Assessment End semester Assessment Marks: 40% (40 Marks) Write up –12 Marks Conduction/execution –12 Marks Viva- Voce –8 Marks Result –8 Marks

Understanding Java Development Kit (JDK)

A Simple Java Program /* This is a simple a program. Call this file "HelloWorld.java". */ class HelloWorld{ // program begins with a call to main () public static void main(String args []){ System.out.println (“Hello World”); } }

write a program in Java to find the area of a rectangle and verify the same with various inputs(length, breadth ). //program to find area of a rectangle import java.util.Scanner ; class RectangleArea { public static void main(String args []){       Scanner scanner = new Scanner(System.in);               System.out.print ("length of rectangle =");   int length= scanner.nextInt ();         System.out.print ("breadth of rectangle ="); int breadth= scanner.nextInt (); int area=length *breadth; System.out.print ("area of rectangle ="+ area); }} Exercise

2. W rite a java program to read 3 numbers and find the largest among them. Exercise import java.util.Scanner ; public class Main {     public static void main(String[] args ) {         Scanner scanner = new Scanner(System.in);         // Read three numbers from the user         System.out.print ("Enter the first number: ");         int num1 = scanner.nextInt ();                 System.out.print ("Enter the second number: ");         int num2 = scanner.nextInt ();                 System.out.print ("Enter the third number: ");         int num3 = scanner.nextInt ();                 // Determine the largest number         int largest = num1;         if (num2 > largest) {             largest = num2;         }         if (num3 > largest) {             largest = num3;         }                 // Display the largest number         System.out.println ("The largest number is: " + largest);                 scanner.close ();     } }

3. Write a method fact to find the factorial of a given number. Exercise public class Factorial {     public static int fact( int n) {         // Base case: factorial of 0 or 1 is 1         if (n == 0 || n == 1) {             return 1;         } else {             // Recursive case: factorial of n is n * factorial of (n-1)             return n * fact(n - 1);         }     }     public static void main(String[] args ) {         int number = 6;         int factorial = fact(number);         System.out.println ("Factorial of " + number + " is: " + factorial);     } }

4. Write a method is Prime to accept one integer parameter and to check whether that parameter is prime or not. Exercise public class PrimeCheck {     // Method to check if a number is prime     public static boolean isPrime ( int num ) {         // Corner cases         if ( num <= 1) {             return false; // 0 and 1 are not prime numbers         }         if ( num <= 3) {             return true; // 2 and 3 are prime numbers         }                 // Check for factors from 2 to sqrt ( num )         for ( int i = 2; i <= Math.sqrt ( num ); i ++) {             if ( num % i == 0) {                 return false; // Found a factor, not prime             }         }                 return true; // No factors found, prime number     }     public static void main(String[] args ) {         // Example usage:         int number = 17;         if ( isPrime (number)) {             System.out.println (number + " is a prime number.");         } else {             System.out.println (number + " is not a prime number.");         }     } }

5. Write a method find Sum to find the sum of digits of a number. Exercise public class SumOfDigits {     // Method to find the sum of digits of a number     public static int findSum ( int number) {         int sum = 0;                 // Handle negative numbers by taking absolute value         number = Math.abs (number);         // Iterate through each digit and add it to sum         while (number > 0) {             int digit = number % 10; // Get the last digit             sum += digit; // Add the digit to sum             number /= 10; // Remove the last digit from number         }                 return sum;     }     public static void main(String[] args ) {         // Example usage:         int num = 12345;         int sum = findSum ( num );         System.out.println ("Sum of digits of " + num + " is: " + sum); // Output: Sum of digits of 12345 is: 15     } }

Thank You
Tags