sahello 0.2.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sa/__init__.py ADDED
@@ -0,0 +1,2236 @@
1
+ def hello():
2
+ print("""Experiment 1: Control Structures, Arrays, and String Methods
3
+ import java.util.Scanner;
4
+ public class Experiment1 {
5
+ public static void main(String[] args) {
6
+ Scanner sc = new Scanner(System.in);
7
+ System.out.println("===== PART A: CONTROL STRUCTURES =====");
8
+ System.out.print("Enter marks (0-100): ");
9
+ int marks = sc.nextInt();
10
+ char grade;
11
+ if (marks >= 90 && marks <= 100) {
12
+ grade = 'A';
13
+ } else if (marks >= 80 && marks < 90) {
14
+ grade = 'B';
15
+ } else if (marks >= 70 && marks < 80) {
16
+ grade = 'C';
17
+ } else if (marks >= 60 && marks < 70) {
18
+ grade = 'D';
19
+ } else if (marks >= 0 && marks < 60) {
20
+ grade = 'F';
21
+ } else {
22
+ grade = 'X'; // Invalid
23
+ }
24
+ switch (grade) {
25
+ case 'A':
26
+ System.out.println("Grade: A - Excellent!");
27
+ break;
28
+ case 'B':
29
+ System.out.println("Grade: B - Very Good!");
30
+ break;
31
+ case 'C':
32
+ System.out.println("Grade: C - Good");
33
+ break;
34
+ case 'D':
35
+ System.out.println("Grade: D - Satisfactory");
36
+ break;
37
+ case 'F':
38
+ System.out.println("Grade: F - Fail");
39
+ break;
40
+ default:
41
+ System.out.println("Invalid marks entered!");
42
+ }
43
+ System.out.println("\n===== PART B: ARRAYS =====");
44
+ int[] numbers = {45, 78, 12, 89, 34, 56, 23, 90, 67, 11};
45
+ System.out.print("Array elements: ");
46
+ int sum = 0, max = numbers[0], min = numbers[0];
47
+ for (int num : numbers) {
48
+ System.out.print(num + " ");
49
+ sum += num;
50
+ if (num > max) max = num;
51
+ if (num < min) min = num;
52
+ }
53
+ System.out.println("\nSum: " + sum);
54
+ System.out.println("Average: " + (double) sum / numbers.length);
55
+ System.out.println("Maximum: " + max);
56
+ System.out.println("Minimum: " + min);
57
+ System.out.println("\n===== PART C: STRING METHODS =====");
58
+ String str1 = "Hello World";
59
+ String str2 = " Java Programming ";
60
+ String str3 = "hello world";
61
+ System.out.println("Original String: \"" + str1 + "\"");
62
+ System.out.println("Length: " + str1.length());
63
+ System.out.println("Character at index 4: " + str1.charAt(4));
64
+ System.out.println("Substring (0,5): " + str1.substring(0, 5));
65
+ System.out.println("Uppercase: " + str1.toUpperCase());
66
+ System.out.println("Lowercase: " + str1.toLowerCase());
67
+ System.out.println("Replace 'o' with '0': " + str1.replace('o', '0'));
68
+ System.out.println("Index of 'World': " + str1.indexOf("World"));
69
+ System.out.println("Starts with 'Hello': " + str1.startsWith("Hello"));
70
+ System.out.println("Ends with 'World': " + str1.endsWith("World"));
71
+ System.out.println("Equals (case-sensitive): " + str1.equals(str3));
72
+ System.out.println("Equals (ignore case): " + str1.equalsIgnoreCase(str3));
73
+ System.out.println("Trimmed string: \"" + str2.trim() + "\"");
74
+ System.out.println("Concatenation: " + str1.concat(" - Java"));
75
+ System.out.println("Split by space: ");
76
+ String[] words = str1.split(" ");
77
+ for (int i = 0; i < words.length; i++) {
78
+ System.out.println(" Word " + (i + 1) + ": " + words[i]);
79
+ }
80
+ sc.close();
81
+ }
82
+ }
83
+ Experiment 2: super, this Keywords, and Constructors
84
+ public class Experiment2 {
85
+ public static void main(String[] args) {
86
+ System.out.println("===== CREATING OBJECTS WITH DIFFERENT CONSTRUCTORS =====\n");
87
+ System.out.println("1. Creating Student with default constructor:");
88
+ Student s1 = new Student();
89
+ System.out.println();
90
+ System.out.println("2. Creating Student with parameterized constructor:");
91
+ Student s2 = new Student("Alice Johnson", 20, "STU001", "Computer Science");
92
+ System.out.println();
93
+ System.out.println("3. Creating Student with copy constructor:");
94
+ Student s3 = new Student(s2);
95
+ System.out.println();
96
+ System.out.println("===== DISPLAYING STUDENT DETAILS =====\n");
97
+ System.out.println("Student 1 (Default):");
98
+ s1.display();
99
+ System.out.println("\nStudent 2 (Parameterized):");
100
+ s2.display();
101
+ System.out.println("\nStudent 3 (Copy of Student 2):");
102
+ s3.display();
103
+ s2.showThisUsage();
104
+ System.out.println("\n===== CREATING PARENT CLASS OBJECT =====");
105
+ Person p1 = new Person("Bob Smith", 45);
106
+ System.out.println("\nPerson details:");
107
+ p1.display();
108
+ }
109
+ }
110
+ class Person {
111
+ protected String name;
112
+ protected int age;
113
+ public Person() {
114
+ this.name = "Unknown";
115
+ this.age = 0;
116
+ System.out.println("Person: Default constructor called");
117
+ }
118
+ public Person(String name, int age) {
119
+ this.name = name;
120
+ this.age = age;
121
+ System.out.println("Person: Parameterized constructor called");
122
+ }
123
+ public Person(Person p) {
124
+ this.name = p.name;
125
+ this.age = p.age;
126
+ System.out.println("Person: Copy constructor called");
127
+ }
128
+ public void display() {
129
+ System.out.println("Name: " + name + ", Age: " + age);
130
+ }
131
+ }
132
+ class Student extends Person {
133
+ private String studentId;
134
+ private String course;
135
+ public Student() {
136
+ this("Unknown", 0, "N/A", "N/A");
137
+ System.out.println("Student: Default constructor called");
138
+ }
139
+ public Student(String name, int age, String studentId, String course) {
140
+ super(name, age);
141
+ this.studentId = studentId;
142
+ this.course = course;
143
+ System.out.println("Student: Parameterized constructor called");
144
+ }
145
+ public Student(Student s) {
146
+ super(s);
147
+ this.studentId = s.studentId;
148
+ this.course = s.course;
149
+ System.out.println("Student: Copy constructor called");
150
+ }
151
+ public Student getSelf() {
152
+ return this;
153
+ }
154
+ @Override
155
+ public void display() {
156
+ super.display();
157
+ System.out.println("Student ID: " + studentId + ", Course: " + course);
158
+ }
159
+ public void showThisUsage() {
160
+ System.out.println("\n--- Demonstrating 'this' keyword ---");
161
+ System.out.println("this.name: " + this.name);
162
+ System.out.println("this.studentId: " + this.studentId);
163
+ System.out.println("this.getSelf() returns: " + this.getSelf());
164
+ System.out.println("Current object hashcode: " + this.hashCode());
165
+ }
166
+ }
167
+ Experiment 3: Method Overloading
168
+ public class Experiment3 {
169
+ public static void main(String[] args) {
170
+ System.out.println("===== CALCULATOR - METHOD OVERLOADING =====\n");
171
+ Calculator calc = new Calculator();
172
+ System.out.println("--- Overloading by Number of Parameters ---");
173
+ System.out.println("Result: " + calc.add(10, 20));
174
+ System.out.println("Result: " + calc.add(10, 20, 30));
175
+ System.out.println("Result: " + calc.add(10, 20, 30, 40));
176
+ System.out.println("\n--- Overloading by Type of Parameters ---");
177
+ System.out.println("Result: " + calc.add(10.5, 20.5));
178
+ System.out.println("Result: " + calc.add(5.5f, 4.5f));
179
+ System.out.println("Result: " + calc.add("Hello", " World"));
180
+ System.out.println("\n--- Overloading by Order of Parameters ---");
181
+ System.out.println("Result: " + calc.add("Value: ", 100));
182
+ System.out.println("Result: " + calc.add(200, " is the number"));
183
+ System.out.println("\n--- Multiply Operations ---");
184
+ System.out.println("multiply(5, 3) = " + calc.multiply(5, 3));
185
+ System.out.println("multiply(2.5, 4.0) = " + calc.multiply(2.5, 4.0));
186
+ System.out.println("multiply(2, 3, 4) = " + calc.multiply(2, 3, 4));
187
+ System.out.println("\n===== AREA CALCULATOR - METHOD OVERLOADING =====\n");
188
+ AreaCalculator area = new AreaCalculator();
189
+ System.out.printf("Area = %.2f sq units%n%n", area.calculateArea(7.0));
190
+ System.out.printf("Area = %.2f sq units%n%n", area.calculateArea(10.0, 5.0));
191
+ System.out.printf("Area = %.2f sq units%n%n", area.calculateArea(8.0, 6.0, "triangle"));
192
+ System.out.printf("Area = %.2f sq units%n%n", area.calculateArea(5));
193
+ System.out.println("===== DISPLAY HELPER - METHOD OVERLOADING =====\n");
194
+ DisplayHelper dh = new DisplayHelper();
195
+ dh.display(42);
196
+ dh.display(3.14159);
197
+ dh.display("Hello Java!");
198
+ dh.display(new int[]{1, 2, 3, 4, 5});
199
+ System.out.println();
200
+ dh.display("Java is awesome!", 3);
201
+ }
202
+ }
203
+ class Calculator {
204
+ public int add(int a, int b) {
205
+ System.out.println("add(int, int) called");
206
+ return a + b;
207
+ }
208
+ public int add(int a, int b, int c) {
209
+ System.out.println("add(int, int, int) called");
210
+ return a + b + c;
211
+ }
212
+ public int add(int a, int b, int c, int d) {
213
+ System.out.println("add(int, int, int, int) called");
214
+ return a + b + c + d;
215
+ }
216
+ public double add(double a, double b) {
217
+ System.out.println("add(double, double) called");
218
+ return a + b;
219
+ }
220
+ public float add(float a, float b) {
221
+ System.out.println("add(float, float) called");
222
+ return a + b;
223
+ }
224
+ public String add(String a, String b) {
225
+ System.out.println("add(String, String) called");
226
+ return a + b;
227
+ }
228
+ public String add(String str, int num) {
229
+ System.out.println("add(String, int) called");
230
+ return str + num;
231
+ }
232
+ public String add(int num, String str) {
233
+ System.out.println("add(int, String) called");
234
+ return num + str;
235
+ }
236
+ public int multiply(int a, int b) {
237
+ return a * b;
238
+ }
239
+ public double multiply(double a, double b) {
240
+ return a * b;
241
+ }
242
+ public int multiply(int a, int b, int c) {
243
+ return a * b * c;
244
+ }
245
+ }
246
+ class AreaCalculator {
247
+ public double calculateArea(double radius) {
248
+ System.out.println("Calculating area of Circle");
249
+ return Math.PI * radius * radius;
250
+ }
251
+ public double calculateArea(double length, double breadth) {
252
+ System.out.println("Calculating area of Rectangle");
253
+ return length * breadth;
254
+ }
255
+ public double calculateArea(double base, double height, String shape) {
256
+ if (shape.equalsIgnoreCase("triangle")) {
257
+ System.out.println("Calculating area of Triangle");
258
+ return 0.5 * base * height;
259
+ }
260
+ return 0;
261
+ }
262
+ public double calculateArea(int side) {
263
+ System.out.println("Calculating area of Square");
264
+ return side * side;
265
+ }
266
+ }
267
+ class DisplayHelper {
268
+ public void display(int value) {
269
+ System.out.println("Integer value: " + value);
270
+ }
271
+ public void display(double value) {
272
+ System.out.println("Double value: " + value);
273
+ }
274
+ public void display(String value) {
275
+ System.out.println("String value: " + value);
276
+ }
277
+ public void display(int[] arr) {
278
+ System.out.print("Array values: ");
279
+ for (int num : arr) {
280
+ System.out.print(num + " ");
281
+ }
282
+ System.out.println();
283
+ }
284
+ public void display(String message, int times) {
285
+ System.out.println("Repeating message " + times + " times:");
286
+ for (int i = 0; i < times; i++) {
287
+ System.out.println(" " + (i + 1) + ". " + message);
288
+ }
289
+ }
290
+ }
291
+ Experiment 4: Single, Multilevel, Hierarchical, and Hybrid Inheritance
292
+ public class Experiment4 {
293
+ public static void main(String[] args) {
294
+ System.out.println("========== SINGLE INHERITANCE ==========");
295
+ System.out.println("(Animal -> Dog)\n");
296
+ Dog dog = new Dog("Buddy", "Golden Retriever");
297
+ dog.displayInfo();
298
+ dog.eat();
299
+ dog.sleep();
300
+ dog.bark();
301
+ System.out.println("\n========== MULTILEVEL INHERITANCE ==========");
302
+ System.out.println("(LivingBeing -> Human -> Employee)\n");
303
+ Employee emp = new Employee("John Doe", "EMP001", "Engineering");
304
+ emp.displayDetails();
305
+ emp.breathe();
306
+ emp.speak();
307
+ emp.work();
308
+ System.out.println("\n========== HIERARCHICAL INHERITANCE ==========");
309
+ System.out.println("(Shape -> Circle, Rectangle, Triangle)\n");
310
+ Circle circle = new Circle("Red", 5.0);
311
+ circle.display();
312
+ System.out.println();
313
+ Rectangle rect = new Rectangle("Blue", 10.0, 6.0);
314
+ rect.display();
315
+ System.out.println();
316
+ Triangle tri = new Triangle("Green", 8.0, 5.0);
317
+ tri.display();
318
+ System.out.println("\n========== HYBRID INHERITANCE ==========");
319
+ System.out.println("(Machine + Printable/Scannable interfaces)\n");
320
+ System.out.println("--- Printer ---");
321
+ Printer printer = new Printer("HP", "LaserJet Pro");
322
+ printer.powerOn();
323
+ printer.print();
324
+ printer.powerOff();
325
+ System.out.println("\n--- Scanner ---");
326
+ Scanner scanner = new Scanner("Canon", "CanoScan LiDE");
327
+ scanner.powerOn();
328
+ scanner.scan();
329
+ scanner.powerOff();
330
+ System.out.println("\n--- All-in-One Printer ---");
331
+ AllInOnePrinter allinone = new AllInOnePrinter("Epson", "EcoTank ET-4850");
332
+ allinone.powerOn();
333
+ allinone.print();
334
+ allinone.scan();
335
+ allinone.copy();
336
+ allinone.powerOff();
337
+ }
338
+ }
339
+ class Animal {
340
+ String name;
341
+ public void eat() {
342
+ System.out.println(name + " is eating.");
343
+ }
344
+ public void sleep() {
345
+ System.out.println(name + " is sleeping.");
346
+ }
347
+ }
348
+ class Dog extends Animal {
349
+ String breed;
350
+ public Dog(String name, String breed) {
351
+ this.name = name;
352
+ this.breed = breed;
353
+ }
354
+ public void bark() {
355
+ System.out.println(name + " is barking!");
356
+ }
357
+ public void displayInfo() {
358
+ System.out.println("Name: " + name + ", Breed: " + breed);
359
+ }
360
+ }
361
+ class LivingBeing {
362
+ public void breathe() {
363
+ System.out.println("Breathing...");
364
+ }
365
+ }
366
+ class Human extends LivingBeing {
367
+ String name;
368
+ public Human(String name) {
369
+ this.name = name;
370
+ }
371
+ public void speak() {
372
+ System.out.println(name + " is speaking.");
373
+ }
374
+ }
375
+ class Employee extends Human {
376
+ String employeeId;
377
+ String department;
378
+ public Employee(String name, String employeeId, String department) {
379
+ super(name);
380
+ this.employeeId = employeeId;
381
+ this.department = department;
382
+ }
383
+ public void work() {
384
+ System.out.println(name + " is working in " + department + " department.");
385
+ }
386
+ public void displayDetails() {
387
+ System.out.println("Employee: " + name + " | ID: " + employeeId + " | Dept: " + department);
388
+ }
389
+ }
390
+ class Shape {
391
+ String color;
392
+ public Shape(String color) {
393
+ this.color = color;
394
+ }
395
+ public void displayColor() {
396
+ System.out.println("Color: " + color);
397
+ }
398
+ public double calculateArea() {
399
+ return 0;
400
+ }
401
+ }
402
+ class Circle extends Shape {
403
+ double radius;
404
+ public Circle(String color, double radius) {
405
+ super(color);
406
+ this.radius = radius;
407
+ }
408
+ @Override
409
+ public double calculateArea() {
410
+ return Math.PI * radius * radius;
411
+ }
412
+ public void display() {
413
+ System.out.println("Circle - Radius: " + radius);
414
+ displayColor();
415
+ System.out.printf("Area: %.2f%n", calculateArea());
416
+ }
417
+ }
418
+ class Rectangle extends Shape {
419
+ double length, width;
420
+ public Rectangle(String color, double length, double width) {
421
+ super(color);
422
+ this.length = length;
423
+ this.width = width;
424
+ }
425
+ @Override
426
+ public double calculateArea() {
427
+ return length * width;
428
+ }
429
+ public void display() {
430
+ System.out.println("Rectangle - Length: " + length + ", Width: " + width);
431
+ displayColor();
432
+ System.out.printf("Area: %.2f%n", calculateArea());
433
+ }
434
+ }
435
+ class Triangle extends Shape {
436
+ double base, height;
437
+ public Triangle(String color, double base, double height) {
438
+ super(color);
439
+ this.base = base;
440
+ this.height = height;
441
+ }
442
+ @Override
443
+ public double calculateArea() {
444
+ return 0.5 * base * height;
445
+ }
446
+ public void display() {
447
+ System.out.println("Triangle - Base: " + base + ", Height: " + height);
448
+ displayColor();
449
+ System.out.printf("Area: %.2f%n", calculateArea());
450
+ }
451
+ }
452
+ interface Printable {
453
+ void print();
454
+ }
455
+ interface Scannable {
456
+ void scan();
457
+ }
458
+ class Machine {
459
+ String brand;
460
+ String model;
461
+ public Machine(String brand, String model) {
462
+ this.brand = brand;
463
+ this.model = model;
464
+ }
465
+ public void powerOn() {
466
+ System.out.println(brand + " " + model + " is powered ON.");
467
+ }
468
+ public void powerOff() {
469
+ System.out.println(brand + " " + model + " is powered OFF.");
470
+ }
471
+ }
472
+ class Printer extends Machine implements Printable {
473
+ public Printer(String brand, String model) {
474
+ super(brand, model);
475
+ }
476
+ @Override
477
+ public void print() {
478
+ System.out.println("Printing document using " + brand + " " + model);
479
+ }
480
+ }
481
+ class Scanner extends Machine implements Scannable {
482
+ public Scanner(String brand, String model) {
483
+ super(brand, model);
484
+ }
485
+ @Override
486
+ public void scan() {
487
+ System.out.println("Scanning document using " + brand + " " + model);
488
+ }
489
+ }
490
+ class AllInOnePrinter extends Machine implements Printable, Scannable {
491
+ public AllInOnePrinter(String brand, String model) {
492
+ super(brand, model);
493
+ }
494
+ @Override
495
+ public void print() {
496
+ System.out.println("Printing using All-in-One: " + brand + " " + model);
497
+ }
498
+ @Override
499
+ public void scan() {
500
+ System.out.println("Scanning using All-in-One: " + brand + " " + model);
501
+ }
502
+ public void copy() {
503
+ System.out.println("Copying document using " + brand + " " + model);
504
+ }
505
+ }
506
+ Experiment 5: Packages
507
+ mathoperations/BasicMath.java
508
+ package mathoperations;
509
+ public class BasicMath {
510
+ public int add(int a, int b) {
511
+ return a + b;
512
+ }
513
+ public int subtract(int a, int b) {
514
+ return a - b;
515
+ }
516
+ public int multiply(int a, int b) {
517
+ return a * b;
518
+ }
519
+ public double divide(int a, int b) {
520
+ if (b == 0) {
521
+ throw new ArithmeticException("Cannot divide by zero");
522
+ }
523
+ return (double) a / b;
524
+ }
525
+ }
526
+ mathoperations/AdvancedMath.java
527
+ package mathoperations;
528
+ public class AdvancedMath {
529
+ public double power(double base, double exponent) {
530
+ return Math.pow(base, exponent);
531
+ }
532
+ public double squareRoot(double number) {
533
+ if (number < 0) {
534
+ throw new IllegalArgumentException("Cannot calculate square root of negative number");
535
+ }
536
+ return Math.sqrt(number);
537
+ }
538
+ public long factorial(int n) {
539
+ if (n < 0) {
540
+ throw new IllegalArgumentException("Factorial not defined for negative numbers");
541
+ }
542
+ long result = 1;
543
+ for (int i = 2; i <= n; i++) {
544
+ result *= i;
545
+ }
546
+ return result;
547
+ }
548
+ public boolean isPrime(int n) {
549
+ if (n <= 1) return false;
550
+ if (n <= 3) return true;
551
+ if (n % 2 == 0 || n % 3 == 0) return false;
552
+ for (int i = 5; i * i <= n; i += 6) {
553
+ if (n % i == 0 || n % (i + 2) == 0) return false;
554
+ }
555
+ return true;
556
+ }
557
+ }
558
+ utilities/StringHelper.java
559
+ package utilities;
560
+ public class StringHelper {
561
+ public String reverse(String str) {
562
+ return new StringBuilder(str).reverse().toString();
563
+ }
564
+ public boolean isPalindrome(String str) {
565
+ String clean = str.replaceAll("\\s+", "").toLowerCase();
566
+ return clean.equals(new StringBuilder(clean).reverse().toString());
567
+ }
568
+ public int countVowels(String str) {
569
+ int count = 0;
570
+ String vowels = "aeiouAEIOU";
571
+ for (char c : str.toCharArray()) {
572
+ if (vowels.indexOf(c) != -1) {
573
+ count++;
574
+ }
575
+ }
576
+ return count;
577
+ }
578
+ public String toTitleCase(String str) {
579
+ StringBuilder result = new StringBuilder();
580
+ boolean capitalizeNext = true;
581
+ for (char c : str.toCharArray()) {
582
+ if (Character.isWhitespace(c)) {
583
+ capitalizeNext = true;
584
+ result.append(c);
585
+ } else if (capitalizeNext) {
586
+ result.append(Character.toUpperCase(c));
587
+ capitalizeNext = false;
588
+ } else {
589
+ result.append(Character.toLowerCase(c));
590
+ }
591
+ }
592
+ return result.toString();
593
+ }
594
+ }
595
+ utilities/ArrayHelper.java
596
+ package utilities;
597
+ import java.util.Arrays;
598
+ public class ArrayHelper {
599
+ public int findMax(int[] arr) {
600
+ int max = arr[0];
601
+ for (int num : arr) {
602
+ if (num > max) max = num;
603
+ }
604
+ return max;
605
+ }
606
+ public int findMin(int[] arr) {
607
+ int min = arr[0];
608
+ for (int num : arr) {
609
+ if (num < min) min = num;
610
+ }
611
+ return min;
612
+ }
613
+ public double findAverage(int[] arr) {
614
+ int sum = 0;
615
+ for (int num : arr) {
616
+ sum += num;
617
+ }
618
+ return (double) sum / arr.length;
619
+ }
620
+ public int[] sortArray(int[] arr) {
621
+ int[] sorted = arr.clone();
622
+ Arrays.sort(sorted);
623
+ return sorted;
624
+ }
625
+ public int[] reverseArray(int[] arr) {
626
+ int[] reversed = new int[arr.length];
627
+ for (int i = 0; i < arr.length; i++) {
628
+ reversed[i] = arr[arr.length - 1 - i];
629
+ }
630
+ return reversed;
631
+ }
632
+ }
633
+ Experiment5.java
634
+ import mathoperations.BasicMath;
635
+ import mathoperations.AdvancedMath;
636
+ import utilities.*;
637
+ import java.util.Date;
638
+ import java.util.Random;
639
+ import java.text.SimpleDateFormat;
640
+ import java.util.Arrays;
641
+ public class Experiment5 {
642
+ public static void main(String[] args) {
643
+ System.out.println("╔════════════════════════════════════════════╗");
644
+ System.out.println("║ JAVA PACKAGES DEMONSTRATION ║");
645
+ System.out.println("╚════════════════════════════════════════════╝\n");
646
+ System.out.println("===== MATH OPERATIONS PACKAGE =====\n");
647
+ BasicMath basicMath = new BasicMath();
648
+ System.out.println("--- Basic Math Operations ---");
649
+ System.out.println("Addition: 15 + 7 = " + basicMath.add(15, 7));
650
+ System.out.println("Subtraction: 20 - 8 = " + basicMath.subtract(20, 8));
651
+ System.out.println("Multiplication: 6 × 9 = " + basicMath.multiply(6, 9));
652
+ System.out.println("Division: 100 ÷ 8 = " + basicMath.divide(100, 8));
653
+ System.out.println();
654
+ AdvancedMath advMath = new AdvancedMath();
655
+ System.out.println("--- Advanced Math Operations ---");
656
+ System.out.println("Power: 2^10 = " + (int) advMath.power(2, 10));
657
+ System.out.println("Square Root: √144 = " + (int) advMath.squareRoot(144));
658
+ System.out.println("Factorial: 7! = " + advMath.factorial(7));
659
+ System.out.println("Is 97 Prime? " + advMath.isPrime(97));
660
+ System.out.println("Is 100 Prime? " + advMath.isPrime(100));
661
+ System.out.println("\n===== UTILITIES PACKAGE =====\n");
662
+ StringHelper strHelper = new StringHelper();
663
+ System.out.println("--- String Helper Operations ---");
664
+ String testStr = "Hello World";
665
+ System.out.println("Original: \"" + testStr + "\"");
666
+ System.out.println("Reversed: \"" + strHelper.reverse(testStr) + "\"");
667
+ System.out.println("Vowel Count: " + strHelper.countVowels(testStr));
668
+ System.out.println("Title Case of 'jAVA proGRAMMING': \"" + strHelper.toTitleCase("jAVA proGRAMMING") + "\"");
669
+ System.out.println("Is 'A man a plan a canal Panama' palindrome? " + strHelper.isPalindrome("A man a plan a canal Panama"));
670
+ System.out.println();
671
+ ArrayHelper arrHelper = new ArrayHelper();
672
+ System.out.println("--- Array Helper Operations ---");
673
+ int[] numbers = {64, 34, 25, 12, 22, 11, 90};
674
+ System.out.println("Original Array: " + Arrays.toString(numbers));
675
+ System.out.println("Maximum: " + arrHelper.findMax(numbers));
676
+ System.out.println("Minimum: " + arrHelper.findMin(numbers));
677
+ System.out.printf("Average: %.2f%n", arrHelper.findAverage(numbers));
678
+ System.out.println("Sorted Array: " + Arrays.toString(arrHelper.sortArray(numbers)));
679
+ System.out.println("Reversed Array: " + Arrays.toString(arrHelper.reverseArray(numbers)));
680
+ System.out.println("\n===== BUILT-IN JAVA PACKAGES =====\n");
681
+ System.out.println("--- java.util.Date and SimpleDateFormat ---");
682
+ Date currentDate = new Date();
683
+ SimpleDateFormat sdf = new SimpleDateFormat("EEEE, MMMM dd, yyyy HH:mm:ss");
684
+ System.out.println("Current Date/Time: " + sdf.format(currentDate));
685
+ System.out.println();
686
+ System.out.println("--- java.util.Random ---");
687
+ Random rand = new Random();
688
+ System.out.print("5 Random Numbers (1-100): ");
689
+ for (int i = 0; i < 5; i++) {
690
+ System.out.print(rand.nextInt(100) + 1);
691
+ if (i < 4) System.out.print(", ");
692
+ }
693
+ System.out.println();
694
+ System.out.println();
695
+ System.out.println("--- java.lang.Math (imported by default) ---");
696
+ System.out.println("PI value: " + Math.PI);
697
+ System.out.println("E value: " + Math.E);
698
+ System.out.println("Max(45, 78): " + Math.max(45, 78));
699
+ System.out.println("Round(4.7): " + Math.round(4.7));
700
+ System.out.println("Abs(-99): " + Math.abs(-99));
701
+ System.out.println("\n===== PACKAGE STRUCTURE =====");
702
+ System.out.println("├── mathoperations/");
703
+ System.out.println("│ ├── BasicMath.java");
704
+ System.out.println("│ └── AdvancedMath.java");
705
+ System.out.println("├── utilities/");
706
+ System.out.println("│ ├── StringHelper.java");
707
+ System.out.println("│ └── ArrayHelper.java");
708
+ System.out.println("└── Experiment5.java (Main)");
709
+ }
710
+ }
711
+ Experiment 6: Interfaces
712
+ public class Experiment6 {
713
+ public static void main(String[] args) {
714
+ System.out.println("╔════════════════════════════════════════════╗");
715
+ System.out.println("║ JAVA INTERFACES DEMONSTRATION ║");
716
+ System.out.println("╚════════════════════════════════════════════╝\n");
717
+ System.out.println("===== INTERFACE STATIC METHOD =====");
718
+ Drawable.info();
719
+ System.out.println("\n===== SINGLE INTERFACE IMPLEMENTATION =====");
720
+ SimpleCircle simpleCircle = new SimpleCircle(5.0);
721
+ simpleCircle.draw();
722
+ simpleCircle.displayTool();
723
+ System.out.println("\n===== MULTIPLE INTERFACE IMPLEMENTATION (Rectangle) =====");
724
+ Rectangle rect = new Rectangle(10, 5);
725
+ rect.displayDimensions();
726
+ rect.draw();
727
+ System.out.printf("Area: %.2f sq units%n", rect.getArea());
728
+ System.out.printf("Perimeter: %.2f units%n", rect.getPerimeter());
729
+ rect.shapeInfo();
730
+ System.out.println();
731
+ rect.resize(1.5);
732
+ System.out.printf("New Area: %.2f sq units%n", rect.getArea());
733
+ System.out.println("\n===== MULTIPLE INTERFACE IMPLEMENTATION (Circle) =====");
734
+ Circle circle = new Circle(7);
735
+ circle.displayDimensions();
736
+ circle.draw();
737
+ System.out.printf("Area: %.2f sq units%n", circle.getArea());
738
+ System.out.printf("Perimeter (Circumference): %.2f units%n", circle.getPerimeter());
739
+ System.out.println("\n===== POLYMORPHISM WITH INTERFACES =====");
740
+ Shape2D[] shapes = {new Rectangle(8, 4), new Circle(5)};
741
+ for (Shape2D shape : shapes) {
742
+ System.out.println("\n--- Shape ---");
743
+ shape.displayDimensions();
744
+ System.out.printf("Area: %.2f sq units%n", shape.getArea());
745
+ }
746
+ System.out.println("\n===== FUNCTIONAL INTERFACE WITH LAMBDA =====");
747
+ Calculator add = (a, b) -> a + b;
748
+ Calculator subtract = (a, b) -> a - b;
749
+ Calculator multiply = (a, b) -> a * b;
750
+ Calculator divide = (a, b) -> b != 0 ? a / b : 0;
751
+ int x = 20, y = 5;
752
+ System.out.println("Numbers: " + x + " and " + y);
753
+ System.out.println("Addition: " + add.calculate(x, y));
754
+ System.out.println("Subtraction: " + subtract.calculate(x, y));
755
+ System.out.println("Multiplication: " + multiply.calculate(x, y));
756
+ System.out.println("Division: " + divide.calculate(x, y));
757
+ System.out.println("\n===== INTERFACE WITH DEFAULT AND PRIVATE METHODS =====");
758
+ Application app = new Application("MyApp");
759
+ app.start();
760
+ app.handleError("Connection timeout occurred");
761
+ app.stop();
762
+ System.out.println("\n===== INTERFACE REFERENCE =====");
763
+ Drawable d = new Circle(3);
764
+ d.draw();
765
+ Resizable r = new Rectangle(6, 4);
766
+ r.resize(2);
767
+ System.out.printf("Area after resize: %.2f%n", r.getArea());
768
+ }
769
+ }
770
+ interface Drawable {
771
+ String DRAWING_TOOL = "Digital Pen";
772
+ void draw();
773
+ default void displayTool() {
774
+ System.out.println("Using: " + DRAWING_TOOL);
775
+ }
776
+ static void info() {
777
+ System.out.println("Drawable interface - Provides drawing capability");
778
+ }
779
+ }
780
+ interface Resizable {
781
+ void resize(double factor);
782
+ double getArea();
783
+ }
784
+ interface Shape2D extends Drawable, Resizable {
785
+ void displayDimensions();
786
+ default void shapeInfo() {
787
+ System.out.println("This is a 2D shape that is drawable and resizable.");
788
+ }
789
+ }
790
+ interface Perimeter {
791
+ double getPerimeter();
792
+ }
793
+ class SimpleCircle implements Drawable {
794
+ private double radius;
795
+ public SimpleCircle(double radius) {
796
+ this.radius = radius;
797
+ }
798
+ @Override
799
+ public void draw() {
800
+ System.out.println("Drawing a simple circle with radius: " + radius);
801
+ }
802
+ }
803
+ class Rectangle implements Shape2D, Perimeter {
804
+ private double length;
805
+ private double width;
806
+ public Rectangle(double length, double width) {
807
+ this.length = length;
808
+ this.width = width;
809
+ }
810
+ @Override
811
+ public void draw() {
812
+ System.out.println("Drawing Rectangle: " + length + " x " + width);
813
+ System.out.println(" +---" + "-".repeat((int)length) + "---+");
814
+ for (int i = 0; i < width / 2; i++) {
815
+ System.out.println(" | " + " ".repeat((int)length) + " |");
816
+ }
817
+ System.out.println(" +---" + "-".repeat((int)length) + "---+");
818
+ }
819
+ @Override
820
+ public void resize(double factor) {
821
+ length *= factor;
822
+ width *= factor;
823
+ System.out.println("Rectangle resized by factor " + factor);
824
+ System.out.println("New dimensions: " + length + " x " + width);
825
+ }
826
+ @Override
827
+ public double getArea() {
828
+ return length * width;
829
+ }
830
+ @Override
831
+ public double getPerimeter() {
832
+ return 2 * (length + width);
833
+ }
834
+ @Override
835
+ public void displayDimensions() {
836
+ System.out.println("Length: " + length + ", Width: " + width);
837
+ }
838
+ }
839
+ class Circle implements Shape2D, Perimeter {
840
+ private double radius;
841
+ public Circle(double radius) {
842
+ this.radius = radius;
843
+ }
844
+ @Override
845
+ public void draw() {
846
+ System.out.println("Drawing Circle with radius: " + radius);
847
+ System.out.println(" ***");
848
+ System.out.println(" * *");
849
+ System.out.println(" * *");
850
+ System.out.println(" * *");
851
+ System.out.println(" * *");
852
+ System.out.println(" ***");
853
+ }
854
+ @Override
855
+ public void resize(double factor) {
856
+ radius *= factor;
857
+ System.out.println("Circle resized by factor " + factor);
858
+ System.out.println("New radius: " + radius);
859
+ }
860
+ @Override
861
+ public double getArea() {
862
+ return Math.PI * radius * radius;
863
+ }
864
+ @Override
865
+ public double getPerimeter() {
866
+ return 2 * Math.PI * radius;
867
+ }
868
+ @Override
869
+ public void displayDimensions() {
870
+ System.out.println("Radius: " + radius);
871
+ }
872
+ }
873
+ @FunctionalInterface
874
+ interface Calculator {
875
+ int calculate(int a, int b);
876
+ }
877
+ interface Logger {
878
+ default void logInfo(String message) {
879
+ log("INFO", message);
880
+ }
881
+ default void logError(String message) {
882
+ log("ERROR", message);
883
+ }
884
+ private void log(String level, String message) {
885
+ System.out.println("[" + level + "] " + message);
886
+ }
887
+ }
888
+ class Application implements Logger {
889
+ private String name;
890
+ public Application(String name) {
891
+ this.name = name;
892
+ }
893
+ public void start() {
894
+ logInfo(name + " application started");
895
+ }
896
+ public void stop() {
897
+ logInfo(name + " application stopped");
898
+ }
899
+ public void handleError(String error) {
900
+ logError(error);
901
+ }
902
+ }
903
+ Experiment 7: Exception Handling
904
+ import java.util.Scanner;
905
+ import java.util.InputMismatchException;
906
+ import java.io.*;
907
+ public class Experiment7 {
908
+ public static int divide(int a, int b) throws ArithmeticException {
909
+ if (b == 0) {
910
+ throw new ArithmeticException("Division by zero is not allowed");
911
+ }
912
+ return a / b;
913
+ }
914
+ public static void readFile(String filename) throws FileNotFoundException, IOException {
915
+ FileReader fr = null;
916
+ BufferedReader br = null;
917
+ try {
918
+ fr = new FileReader(filename);
919
+ br = new BufferedReader(fr);
920
+ String line;
921
+ System.out.println("File contents:");
922
+ while ((line = br.readLine()) != null) {
923
+ System.out.println(line);
924
+ }
925
+ } finally {
926
+ if (br != null) br.close();
927
+ if (fr != null) fr.close();
928
+ }
929
+ }
930
+ public static void validateAge(int age) {
931
+ if (age < 0) {
932
+ throw new IllegalArgumentException("Age cannot be negative");
933
+ } else if (age < 18) {
934
+ throw new IllegalArgumentException("Age must be 18 or above");
935
+ }
936
+ System.out.println("Age " + age + " is valid. Access granted!");
937
+ }
938
+ public static void methodA() throws Exception {
939
+ System.out.println("Inside methodA");
940
+ methodB();
941
+ }
942
+ public static void methodB() throws Exception {
943
+ System.out.println("Inside methodB");
944
+ methodC();
945
+ }
946
+ public static void methodC() throws Exception {
947
+ System.out.println("Inside methodC");
948
+ throw new Exception("Exception thrown from methodC");
949
+ }
950
+ public static void tryWithResourcesDemo() {
951
+ System.out.println("\n--- Try-With-Resources Demo ---");
952
+ String data = "Hello, Java Exception Handling!";
953
+ try (FileWriter fw = new FileWriter("test_output.txt");
954
+ BufferedWriter bw = new BufferedWriter(fw)) {
955
+ bw.write(data);
956
+ System.out.println("Data written to file successfully");
957
+ } catch (IOException e) {
958
+ System.out.println("Error writing to file: " + e.getMessage());
959
+ }
960
+ try (FileReader fr = new FileReader("test_output.txt");
961
+ BufferedReader br = new BufferedReader(fr)) {
962
+ String line = br.readLine();
963
+ System.out.println("Data read from file: " + line);
964
+ } catch (IOException e) {
965
+ System.out.println("Error reading file: " + e.getMessage());
966
+ }
967
+ new File("test_output.txt").delete();
968
+ }
969
+ public static void main(String[] args) {
970
+ Scanner sc = new Scanner(System.in);
971
+ System.out.println("╔════════════════════════════════════════════╗");
972
+ System.out.println("║ EXCEPTION HANDLING IN JAVA ║");
973
+ System.out.println("╚════════════════════════════════════════════╝\n");
974
+ System.out.println("===== 1. BASIC TRY-CATCH =====");
975
+ try {
976
+ int[] arr = {1, 2, 3};
977
+ System.out.println("Accessing index 5: " + arr[5]);
978
+ } catch (ArrayIndexOutOfBoundsException e) {
979
+ System.out.println("Exception caught: " + e.getClass().getSimpleName());
980
+ System.out.println("Message: " + e.getMessage());
981
+ }
982
+ System.out.println("\n===== 2. MULTIPLE CATCH BLOCKS =====");
983
+ try {
984
+ int[] numbers = {10, 20, 30, 0, 50};
985
+ int index = 2;
986
+ System.out.println("Value at index " + index + ": " + numbers[index]);
987
+ int result = numbers[index] / numbers[3];
988
+ System.out.println("Result: " + result);
989
+ } catch (ArrayIndexOutOfBoundsException e) {
990
+ System.out.println("Array index error: " + e.getMessage());
991
+ } catch (ArithmeticException e) {
992
+ System.out.println("Arithmetic error: " + e.getMessage());
993
+ } catch (Exception e) {
994
+ System.out.println("General exception: " + e.getMessage());
995
+ }
996
+ System.out.println("\n===== 3. TRY-CATCH-FINALLY =====");
997
+ FileWriter writer = null;
998
+ try {
999
+ System.out.println("Attempting to open file...");
1000
+ writer = new FileWriter("temp.txt");
1001
+ System.out.println("File opened successfully");
1002
+ writer.write("Test data");
1003
+ System.out.println("Data written");
1004
+ int x = 10 / 0;
1005
+ } catch (IOException e) {
1006
+ System.out.println("IO Exception: " + e.getMessage());
1007
+ } catch (ArithmeticException e) {
1008
+ System.out.println("Arithmetic Exception: " + e.getMessage());
1009
+ } finally {
1010
+ System.out.println("Finally block executed - Cleaning up resources");
1011
+ try {
1012
+ if (writer != null) {
1013
+ writer.close();
1014
+ System.out.println("File closed successfully");
1015
+ }
1016
+ } catch (IOException e) {
1017
+ System.out.println("Error closing file");
1018
+ }
1019
+ new File("temp.txt").delete();
1020
+ }
1021
+ System.out.println("\n===== 4. THROW KEYWORD =====");
1022
+ int[] testAges = {25, -5, 15, 30};
1023
+ for (int age : testAges) {
1024
+ try {
1025
+ System.out.print("Validating age " + age + ": ");
1026
+ validateAge(age);
1027
+ } catch (IllegalArgumentException e) {
1028
+ System.out.println("Error - " + e.getMessage());
1029
+ }
1030
+ }
1031
+ System.out.println("\n===== 5. THROWS KEYWORD =====");
1032
+ try {
1033
+ System.out.println("20 / 4 = " + divide(20, 4));
1034
+ System.out.println("15 / 0 = " + divide(15, 0));
1035
+ } catch (ArithmeticException e) {
1036
+ System.out.println("Exception caught: " + e.getMessage());
1037
+ }
1038
+ System.out.println("\n===== 6. NESTED TRY-CATCH =====");
1039
+ try {
1040
+ System.out.println("Outer try block");
1041
+ try {
1042
+ System.out.println("Inner try block");
1043
+ String str = null;
1044
+ System.out.println(str.length());
1045
+ } catch (NullPointerException e) {
1046
+ System.out.println("Inner catch: NullPointerException caught");
1047
+ }
1048
+ int[] arr = new int[3];
1049
+ arr[5] = 100;
1050
+ } catch (ArrayIndexOutOfBoundsException e) {
1051
+ System.out.println("Outer catch: ArrayIndexOutOfBoundsException caught");
1052
+ }
1053
+ System.out.println("\n===== 7. EXCEPTION PROPAGATION =====");
1054
+ try {
1055
+ methodA();
1056
+ } catch (Exception e) {
1057
+ System.out.println("Exception caught in main: " + e.getMessage());
1058
+ System.out.println("Stack trace:");
1059
+ for (StackTraceElement element : e.getStackTrace()) {
1060
+ System.out.println(" at " + element);
1061
+ }
1062
+ }
1063
+ System.out.println("\n===== 8. MULTI-CATCH BLOCK =====");
1064
+ try {
1065
+ String numStr = "abc";
1066
+ int num = Integer.parseInt(numStr);
1067
+ int[] arr = new int[2];
1068
+ arr[5] = num;
1069
+ } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
1070
+ System.out.println("Caught exception: " + e.getClass().getSimpleName());
1071
+ System.out.println("Message: " + e.getMessage());
1072
+ }
1073
+ tryWithResourcesDemo();
1074
+ System.out.println("\n===== 10. COMMON RUNTIME EXCEPTIONS =====");
1075
+ try {
1076
+ String s = null;
1077
+ System.out.println(s.toUpperCase());
1078
+ } catch (NullPointerException e) {
1079
+ System.out.println("✗ NullPointerException: " + e.getMessage());
1080
+ }
1081
+ try {
1082
+ int n = Integer.parseInt("12.34");
1083
+ } catch (NumberFormatException e) {
1084
+ System.out.println("✗ NumberFormatException: " + e.getMessage());
1085
+ }
1086
+ try {
1087
+ Object obj = Integer.valueOf(10);
1088
+ String str = (String) obj;
1089
+ } catch (ClassCastException e) {
1090
+ System.out.println("✗ ClassCastException: " + e.getMessage());
1091
+ }
1092
+ System.out.println("\n===== PROGRAM COMPLETED SUCCESSFULLY =====");
1093
+ sc.close();
1094
+ }
1095
+ }
1096
+ Experiment 8: ATM Withdrawal with Custom Exception
1097
+ import java.util.Scanner;
1098
+ import java.util.InputMismatchException;
1099
+ import java.io.*;
1100
+ public class Experiment8 {
1101
+ public static void main(String[] args) {
1102
+ Scanner sc = new Scanner(System.in);
1103
+ BankAccount account = new BankAccount("1234567890", "Rahul Sharma", 75000.00, 1234);
1104
+ ATM atm = new ATM();
1105
+ System.out.println("╔════════════════════════════════════════════╗");
1106
+ System.out.println("║ ATM WITHDRAWAL SYSTEM WITH CUSTOM ║");
1107
+ System.out.println("║ EXCEPTION HANDLING ║");
1108
+ System.out.println("╚════════════════════════════════════════════╝");
1109
+ try {
1110
+ atm.insertCard(account);
1111
+ boolean pinVerified = false;
1112
+ while (!pinVerified) {
1113
+ System.out.print("\nEnter your 4-digit PIN: ");
1114
+ int pin = sc.nextInt();
1115
+ try {
1116
+ pinVerified = atm.verifyPIN(pin);
1117
+ } catch (InvalidPINException e) {
1118
+ System.out.println("✗ " + e.getMessage());
1119
+ if (e.getRemainingAttempts() > 0) {
1120
+ System.out.println(" Remaining attempts: " + e.getRemainingAttempts());
1121
+ }
1122
+ }
1123
+ }
1124
+ boolean exit = false;
1125
+ while (!exit) {
1126
+ System.out.println("\n╔═══════════════════════════════════════╗");
1127
+ System.out.println("║ ATM MENU ║");
1128
+ System.out.println("╠═══════════════════════════════════════╣");
1129
+ System.out.println("║ 1. Check Balance ║");
1130
+ System.out.println("║ 2. Withdraw Cash ║");
1131
+ System.out.println("║ 3. Deposit Cash ║");
1132
+ System.out.println("║ 4. Exit ║");
1133
+ System.out.println("╚═══════════════════════════════════════╝");
1134
+ System.out.print("Enter your choice: ");
1135
+ int choice = sc.nextInt();
1136
+ switch (choice) {
1137
+ case 1:
1138
+ atm.checkBalance();
1139
+ break;
1140
+ case 2:
1141
+ System.out.print("Enter amount to withdraw (multiples of ₹100): ₹");
1142
+ double withdrawAmount = sc.nextDouble();
1143
+ try {
1144
+ atm.withdraw(withdrawAmount);
1145
+ } catch (InsufficientBalanceException e) {
1146
+ System.out.println("\n✗ TRANSACTION FAILED");
1147
+ System.out.println(" " + e.getMessage());
1148
+ System.out.println(" Minimum balance of ₹" + account.getMinBalance() + " must be maintained.");
1149
+ } catch (DailyLimitExceededException e) {
1150
+ System.out.println("\n✗ TRANSACTION FAILED");
1151
+ System.out.println(" " + e.getMessage());
1152
+ System.out.println(" Daily limit: ₹" + account.getDailyLimit());
1153
+ System.out.println(" Remaining limit for today: ₹" + e.getRemainingLimit());
1154
+ } catch (InvalidAmountException e) {
1155
+ System.out.println("\n✗ INVALID AMOUNT");
1156
+ System.out.println(" " + e.getMessage());
1157
+ }
1158
+ break;
1159
+ case 3:
1160
+ System.out.print("Enter amount to deposit (multiples of ₹100): ₹");
1161
+ double depositAmount = sc.nextDouble();
1162
+ try {
1163
+ atm.deposit(depositAmount);
1164
+ } catch (InvalidAmountException e) {
1165
+ System.out.println("\n✗ INVALID AMOUNT");
1166
+ System.out.println(" " + e.getMessage());
1167
+ }
1168
+ break;
1169
+ case 4:
1170
+ exit = true;
1171
+ atm.ejectCard();
1172
+ break;
1173
+ default:
1174
+ System.out.println("Invalid choice. Please try again.");
1175
+ }
1176
+ }
1177
+ } catch (CardBlockedException e) {
1178
+ System.out.println("\n╔═══════════════════════════════════════╗");
1179
+ System.out.println("║ CARD BLOCKED ║");
1180
+ System.out.println("╠═══════════════════════════════════════╣");
1181
+ System.out.println("║ " + e.getMessage());
1182
+ System.out.println("╚═══════════════════════════════════════╝");
1183
+ }
1184
+ System.out.println("\n\n===== DEMONSTRATION OF ALL CUSTOM EXCEPTIONS =====");
1185
+ BankAccount demoAccount = new BankAccount("9876543210", "Demo User", 5000.00, 9999);
1186
+ ATM demoATM = new ATM();
1187
+ try {
1188
+ demoATM.insertCard(demoAccount);
1189
+ demoATM.verifyPIN(9999);
1190
+ System.out.println("\n--- Demo 1: Insufficient Balance ---");
1191
+ try {
1192
+ demoATM.withdraw(10000);
1193
+ } catch (InsufficientBalanceException e) {
1194
+ System.out.println("Exception: " + e.getClass().getSimpleName());
1195
+ System.out.println("Message: " + e.getMessage());
1196
+ }
1197
+ System.out.println("\n--- Demo 2: Invalid Amount (not multiple of 100) ---");
1198
+ try {
1199
+ demoATM.withdraw(1550);
1200
+ } catch (InvalidAmountException e) {
1201
+ System.out.println("Exception: " + e.getClass().getSimpleName());
1202
+ System.out.println("Message: " + e.getMessage());
1203
+ }
1204
+ System.out.println("\n--- Demo 3: Daily Limit Exceeded ---");
1205
+ BankAccount richAccount = new BankAccount("1111222233", "Rich User", 100000.00, 1111);
1206
+ ATM richATM = new ATM();
1207
+ richATM.insertCard(richAccount);
1208
+ richATM.verifyPIN(1111);
1209
+ richATM.withdraw(48000);
1210
+ System.out.println("\nAttempting to withdraw ₹5000 more...");
1211
+ try {
1212
+ richATM.withdraw(5000);
1213
+ } catch (DailyLimitExceededException e) {
1214
+ System.out.println("Exception: " + e.getClass().getSimpleName());
1215
+ System.out.println("Message: " + e.getMessage());
1216
+ System.out.println("Remaining daily limit: ₹" + e.getRemainingLimit());
1217
+ }
1218
+ } catch (Exception e) {
1219
+ System.out.println("Unexpected error: " + e.getMessage());
1220
+ }
1221
+ System.out.println("\n--- Demo 4: Card Blocked (3 wrong PIN attempts) ---");
1222
+ BankAccount blockedAccount = new BankAccount("4444555566", "Block Test", 10000.00, 1234);
1223
+ ATM blockATM = new ATM();
1224
+ try {
1225
+ blockATM.insertCard(blockedAccount);
1226
+ for (int i = 1; i <= 3; i++) {
1227
+ try {
1228
+ System.out.println("Attempt " + i + ": Entering wrong PIN...");
1229
+ blockATM.verifyPIN(0000);
1230
+ } catch (InvalidPINException e) {
1231
+ System.out.println(" " + e.getMessage());
1232
+ }
1233
+ }
1234
+ } catch (CardBlockedException e) {
1235
+ System.out.println("\n" + e.getMessage());
1236
+ }
1237
+ sc.close();
1238
+ }
1239
+ }
1240
+ class InsufficientBalanceException extends Exception {
1241
+ private double currentBalance;
1242
+ private double requestedAmount;
1243
+ public InsufficientBalanceException(double currentBalance, double requestedAmount) {
1244
+ super("Insufficient balance! Available: ₹" + currentBalance + ", Requested: ₹" + requestedAmount);
1245
+ this.currentBalance = currentBalance;
1246
+ this.requestedAmount = requestedAmount;
1247
+ }
1248
+ public double getCurrentBalance() {
1249
+ return currentBalance;
1250
+ }
1251
+ public double getRequestedAmount() {
1252
+ return requestedAmount;
1253
+ }
1254
+ }
1255
+ class InvalidPINException extends Exception {
1256
+ private int attempts;
1257
+ private static final int MAX_ATTEMPTS = 3;
1258
+ public InvalidPINException(int attempts) {
1259
+ super("Invalid PIN! Attempt " + attempts + " of " + MAX_ATTEMPTS);
1260
+ this.attempts = attempts;
1261
+ }
1262
+ public int getAttempts() {
1263
+ return attempts;
1264
+ }
1265
+ public int getRemainingAttempts() {
1266
+ return MAX_ATTEMPTS - attempts;
1267
+ }
1268
+ public boolean isCardBlocked() {
1269
+ return attempts >= MAX_ATTEMPTS;
1270
+ }
1271
+ }
1272
+ class DailyLimitExceededException extends Exception {
1273
+ private double dailyLimit;
1274
+ private double alreadyWithdrawn;
1275
+ private double requestedAmount;
1276
+ public DailyLimitExceededException(double dailyLimit, double alreadyWithdrawn, double requestedAmount) {
1277
+ super("Daily withdrawal limit exceeded!");
1278
+ this.dailyLimit = dailyLimit;
1279
+ this.alreadyWithdrawn = alreadyWithdrawn;
1280
+ this.requestedAmount = requestedAmount;
1281
+ }
1282
+ public double getRemainingLimit() {
1283
+ return dailyLimit - alreadyWithdrawn;
1284
+ }
1285
+ }
1286
+ class InvalidAmountException extends Exception {
1287
+ public InvalidAmountException(String message) {
1288
+ super(message);
1289
+ }
1290
+ }
1291
+ class CardBlockedException extends Exception {
1292
+ public CardBlockedException() {
1293
+ super("Your card has been blocked due to multiple incorrect PIN attempts. Please contact your bank.");
1294
+ }
1295
+ }
1296
+ class BankAccount {
1297
+ private String accountNumber;
1298
+ private String accountHolder;
1299
+ private double balance;
1300
+ private int pin;
1301
+ private double dailyWithdrawn;
1302
+ private static final double DAILY_LIMIT = 50000.0;
1303
+ private static final double MIN_BALANCE = 1000.0;
1304
+ public BankAccount(String accountNumber, String accountHolder, double balance, int pin) {
1305
+ this.accountNumber = accountNumber;
1306
+ this.accountHolder = accountHolder;
1307
+ this.balance = balance;
1308
+ this.pin = pin;
1309
+ this.dailyWithdrawn = 0;
1310
+ }
1311
+ public String getAccountNumber() {
1312
+ return accountNumber;
1313
+ }
1314
+ public String getAccountHolder() {
1315
+ return accountHolder;
1316
+ }
1317
+ public double getBalance() {
1318
+ return balance;
1319
+ }
1320
+ public double getDailyWithdrawn() {
1321
+ return dailyWithdrawn;
1322
+ }
1323
+ public double getDailyLimit() {
1324
+ return DAILY_LIMIT;
1325
+ }
1326
+ public double getRemainingDailyLimit() {
1327
+ return DAILY_LIMIT - dailyWithdrawn;
1328
+ }
1329
+ public boolean validatePIN(int enteredPIN) {
1330
+ return this.pin == enteredPIN;
1331
+ }
1332
+ public void withdraw(double amount) {
1333
+ this.balance -= amount;
1334
+ this.dailyWithdrawn += amount;
1335
+ }
1336
+ public void deposit(double amount) {
1337
+ this.balance += amount;
1338
+ }
1339
+ public double getMinBalance() {
1340
+ return MIN_BALANCE;
1341
+ }
1342
+ public void resetDailyLimit() {
1343
+ this.dailyWithdrawn = 0;
1344
+ }
1345
+ }
1346
+ class ATM {
1347
+ private BankAccount currentAccount;
1348
+ private int pinAttempts;
1349
+ private boolean cardBlocked;
1350
+ private static final int MAX_PIN_ATTEMPTS = 3;
1351
+ public ATM() {
1352
+ this.pinAttempts = 0;
1353
+ this.cardBlocked = false;
1354
+ }
1355
+ public void insertCard(BankAccount account) throws CardBlockedException {
1356
+ if (cardBlocked) {
1357
+ throw new CardBlockedException();
1358
+ }
1359
+ this.currentAccount = account;
1360
+ this.pinAttempts = 0;
1361
+ System.out.println("\n╔═══════════════════════════════════════╗");
1362
+ System.out.println("║ Welcome to ABC Bank ATM ║");
1363
+ System.out.println("╚═══════════════════════════════════════╝");
1364
+ System.out.println("Card inserted: ****" + account.getAccountNumber().substring(account.getAccountNumber().length() - 4));
1365
+ }
1366
+ public boolean verifyPIN(int enteredPIN) throws InvalidPINException, CardBlockedException {
1367
+ if (cardBlocked) {
1368
+ throw new CardBlockedException();
1369
+ }
1370
+ if (!currentAccount.validatePIN(enteredPIN)) {
1371
+ pinAttempts++;
1372
+ if (pinAttempts >= MAX_PIN_ATTEMPTS) {
1373
+ cardBlocked = true;
1374
+ throw new CardBlockedException();
1375
+ }
1376
+ throw new InvalidPINException(pinAttempts);
1377
+ }
1378
+ pinAttempts = 0;
1379
+ System.out.println("✓ PIN verified successfully!");
1380
+ return true;
1381
+ }
1382
+ public void withdraw(double amount) throws InsufficientBalanceException, DailyLimitExceededException, InvalidAmountException {
1383
+ if (amount <= 0) {
1384
+ throw new InvalidAmountException("Withdrawal amount must be positive");
1385
+ }
1386
+ if (amount % 100 != 0) {
1387
+ throw new InvalidAmountException("Amount must be in multiples of ₹100. Please enter a valid amount.");
1388
+ }
1389
+ if (currentAccount.getDailyWithdrawn() + amount > currentAccount.getDailyLimit()) {
1390
+ throw new DailyLimitExceededException(currentAccount.getDailyLimit(), currentAccount.getDailyWithdrawn(), amount);
1391
+ }
1392
+ double availableForWithdrawal = currentAccount.getBalance() - currentAccount.getMinBalance();
1393
+ if (amount > availableForWithdrawal) {
1394
+ throw new InsufficientBalanceException(availableForWithdrawal, amount);
1395
+ }
1396
+ currentAccount.withdraw(amount);
1397
+ System.out.println("\n╔═══════════════════════════════════════╗");
1398
+ System.out.println("║ TRANSACTION SUCCESSFUL ║");
1399
+ System.out.println("╠═══════════════════════════════════════╣");
1400
+ System.out.printf("║ Amount Withdrawn: ₹%-18.2f║%n", amount);
1401
+ System.out.printf("║ Remaining Balance: ₹%-17.2f║%n", currentAccount.getBalance());
1402
+ System.out.printf("║ Daily Limit Left: ₹%-18.2f║%n", currentAccount.getRemainingDailyLimit());
1403
+ System.out.println("╚═══════════════════════════════════════╝");
1404
+ System.out.println("\nPlease collect your cash.");
1405
+ }
1406
+ public void checkBalance() {
1407
+ System.out.println("\n╔═══════════════════════════════════════╗");
1408
+ System.out.println("║ ACCOUNT BALANCE ║");
1409
+ System.out.println("╠═══════════════════════════════════════╣");
1410
+ System.out.printf("║ Account Holder: %-21s║%n", currentAccount.getAccountHolder());
1411
+ System.out.printf("║ Current Balance: ₹%-19.2f║%n", currentAccount.getBalance());
1412
+ System.out.printf("║ Today's Withdrawal: ₹%-16.2f║%n", currentAccount.getDailyWithdrawn());
1413
+ System.out.printf("║ Remaining Daily Limit: ₹%-13.2f║%n", currentAccount.getRemainingDailyLimit());
1414
+ System.out.println("╚═══════════════════════════════════════╝");
1415
+ }
1416
+ public void deposit(double amount) throws InvalidAmountException {
1417
+ if (amount <= 0) {
1418
+ throw new InvalidAmountException("Deposit amount must be positive");
1419
+ }
1420
+ if (amount % 100 != 0) {
1421
+ throw new InvalidAmountException("Amount must be in multiples of ₹100. Please enter valid notes.");
1422
+ }
1423
+ currentAccount.deposit(amount);
1424
+ System.out.println("\n╔═══════════════════════════════════════╗");
1425
+ System.out.println("║ DEPOSIT SUCCESSFUL ║");
1426
+ System.out.println("╠═══════════════════════════════════════╣");
1427
+ System.out.printf("║ Amount Deposited: ₹%-18.2f║%n", amount);
1428
+ System.out.printf("║ New Balance: ₹%-23.2f║%n", currentAccount.getBalance());
1429
+ System.out.println("╚═══════════════════════════════════════╝");
1430
+ }
1431
+ public void ejectCard() {
1432
+ System.out.println("\n╔═══════════════════════════════════════╗");
1433
+ System.out.println("║ Thank you for using ABC Bank ATM ║");
1434
+ System.out.println("║ Please collect your card. ║");
1435
+ System.out.println("╚═══════════════════════════════════════╝");
1436
+ currentAccount = null;
1437
+ }
1438
+ }
1439
+ Experiment 9: Multithreading using Thread Class and Runnable Interface
1440
+ public class Experiment9 {
1441
+ public static void main(String[] args) {
1442
+ System.out.println("===== MULTITHREADING IN JAVA =====");
1443
+ NumberPrinter n = new NumberPrinter();
1444
+ Thread l = new Thread(new LetterPrinter());
1445
+ n.start();
1446
+ l.start();
1447
+ try {
1448
+ n.join();
1449
+ l.join();
1450
+ } catch (InterruptedException e) {}
1451
+ Thread t = Thread.currentThread();
1452
+ System.out.println("Thread Name: " + t.getName());
1453
+ System.out.println("Thread ID: " + t.getId());
1454
+ System.out.println("Priority: " + t.getPriority());
1455
+ System.out.println("State: " + t.getState());
1456
+ Counter c = new Counter();
1457
+ Thread c1 = new CounterThread(c);
1458
+ Thread c2 = new CounterThread(c);
1459
+ Thread c3 = new CounterThread(c);
1460
+ c1.start();
1461
+ c2.start();
1462
+ c3.start();
1463
+ try {
1464
+ c1.join();
1465
+ c2.join();
1466
+ c3.join();
1467
+ } catch (InterruptedException e) {}
1468
+ System.out.println("Count: " + c.getCount());
1469
+ PriorityThread low = new PriorityThread("Low");
1470
+ PriorityThread normal = new PriorityThread("Normal");
1471
+ PriorityThread high = new PriorityThread("High");
1472
+ low.setPriority(1);
1473
+ normal.setPriority(5);
1474
+ high.setPriority(10);
1475
+ low.start();
1476
+ normal.start();
1477
+ high.start();
1478
+ SharedBuffer b = new SharedBuffer();
1479
+ new Producer(b).start();
1480
+ new Consumer(b).start();
1481
+ LambdaThreadDemo.runDemo();
1482
+ Thread sleepy = new Thread(() -> {
1483
+ try {
1484
+ System.out.println("Thread sleeping...");
1485
+ Thread.sleep(3000);
1486
+ System.out.println("Thread woke up");
1487
+ } catch (InterruptedException e) {
1488
+ System.out.println("Thread interrupted");
1489
+ }
1490
+ });
1491
+ sleepy.start();
1492
+ try {
1493
+ Thread.sleep(1000);
1494
+ sleepy.interrupt();
1495
+ sleepy.join();
1496
+ } catch (InterruptedException e) {}
1497
+ Thread daemon = new Thread(() -> {
1498
+ while (true) {
1499
+ System.out.println("Daemon running...");
1500
+ try {
1501
+ Thread.sleep(500);
1502
+ } catch (InterruptedException e) {
1503
+ break;
1504
+ }
1505
+ }
1506
+ });
1507
+ daemon.setDaemon(true);
1508
+ daemon.start();
1509
+ try {
1510
+ Thread.sleep(1500);
1511
+ } catch (InterruptedException e) {}
1512
+ System.out.println("===== PROGRAM COMPLETED =====");
1513
+ }
1514
+ }
1515
+ class NumberPrinter extends Thread {
1516
+ public void run() {
1517
+ for (int i = 1; i <= 5; i++) {
1518
+ System.out.println("Number: " + i);
1519
+ try {
1520
+ Thread.sleep(300);
1521
+ } catch (InterruptedException e) {}
1522
+ }
1523
+ }
1524
+ }
1525
+ class LetterPrinter implements Runnable {
1526
+ public void run() {
1527
+ for (char c = 'A'; c <= 'E'; c++) {
1528
+ System.out.println("Letter: " + c);
1529
+ try {
1530
+ Thread.sleep(300);
1531
+ } catch (InterruptedException e) {}
1532
+ }
1533
+ }
1534
+ }
1535
+ class Counter {
1536
+ private int count;
1537
+ public synchronized void increment() {
1538
+ count++;
1539
+ }
1540
+ public int getCount() {
1541
+ return count;
1542
+ }
1543
+ }
1544
+ class CounterThread extends Thread {
1545
+ Counter c;
1546
+ CounterThread(Counter c) {
1547
+ this.c = c;
1548
+ }
1549
+ public void run() {
1550
+ for (int i = 0; i < 1000; i++)
1551
+ c.increment();
1552
+ }
1553
+ }
1554
+ class PriorityThread extends Thread {
1555
+ PriorityThread(String name) {
1556
+ super(name);
1557
+ }
1558
+ public void run() {
1559
+ System.out.println(getName() + " Priority: " + getPriority());
1560
+ }
1561
+ }
1562
+ class SharedBuffer {
1563
+ private int data;
1564
+ private boolean available;
1565
+ synchronized void produce(int x) throws InterruptedException {
1566
+ while (available)
1567
+ wait();
1568
+ data = x;
1569
+ available = true;
1570
+ System.out.println("Produced: " + x);
1571
+ notify();
1572
+ }
1573
+ synchronized int consume() throws InterruptedException {
1574
+ while (!available)
1575
+ wait();
1576
+ available = false;
1577
+ System.out.println("Consumed: " + data);
1578
+ notify();
1579
+ return data;
1580
+ }
1581
+ }
1582
+ class Producer extends Thread {
1583
+ SharedBuffer b;
1584
+ Producer(SharedBuffer b) {
1585
+ this.b = b;
1586
+ }
1587
+ public void run() {
1588
+ try {
1589
+ for (int i = 1; i <= 5; i++) {
1590
+ b.produce(i);
1591
+ Thread.sleep(300);
1592
+ }
1593
+ } catch (InterruptedException e) {}
1594
+ }
1595
+ }
1596
+ class Consumer extends Thread {
1597
+ SharedBuffer b;
1598
+ Consumer(SharedBuffer b) {
1599
+ this.b = b;
1600
+ }
1601
+ public void run() {
1602
+ try {
1603
+ for (int i = 1; i <= 5; i++) {
1604
+ b.consume();
1605
+ Thread.sleep(500);
1606
+ }
1607
+ } catch (InterruptedException e) {}
1608
+ }
1609
+ }
1610
+ class LambdaThreadDemo {
1611
+ static void runDemo() {
1612
+ Thread t1 = new Thread(() -> System.out.println("Lambda Thread 1"));
1613
+ Thread t2 = new Thread(() -> System.out.println("Lambda Thread 2"));
1614
+ t1.start();
1615
+ t2.start();
1616
+ }
1617
+ }
1618
+ Experiment 10: File Handling using File Stream Classes
1619
+ import java.io.*;
1620
+ public class Experiment10 {
1621
+ public static void main(String[] args) {
1622
+ String dir="./";
1623
+ String byteFile=dir+"bytes.txt";
1624
+ String charFile=dir+"chars.txt";
1625
+ String bufferFile=dir+"buffer.txt";
1626
+ String printFile=dir+"print.txt";
1627
+ System.out.println("===== FILE HANDLING IN JAVA =====");
1628
+ try {
1629
+ FileOutputStream fos=new FileOutputStream(byteFile);
1630
+ fos.write("Hello Java File Handling\n".getBytes());
1631
+ fos.close();
1632
+ FileInputStream fis=new FileInputStream(byteFile);
1633
+ int b;
1634
+ while((b=fis.read())!=-1)
1635
+ System.out.print((char)b);
1636
+ fis.close();
1637
+ FileWriter fw=new FileWriter(charFile);
1638
+ fw.write("Java FileWriter Example\nCharacter Stream");
1639
+ fw.close();
1640
+ FileReader fr=new FileReader(charFile);
1641
+ int c;
1642
+ while((c=fr.read())!=-1)
1643
+ System.out.print((char)c);
1644
+ fr.close();
1645
+ BufferedWriter bw=new BufferedWriter(new FileWriter(bufferFile));
1646
+ bw.write("BufferedWriter Example");
1647
+ bw.newLine();
1648
+ bw.write("Efficient file writing");
1649
+ bw.close();
1650
+ BufferedReader br=new BufferedReader(new FileReader(bufferFile));
1651
+ String line;
1652
+ while((line=br.readLine())!=null)
1653
+ System.out.println(line);
1654
+ br.close();
1655
+ PrintWriter pw=new PrintWriter(new FileWriter(printFile));
1656
+ pw.println("PrintWriter Example");
1657
+ pw.printf("Integer: %d%n",42);
1658
+ pw.printf("Float: %.2f%n",3.14);
1659
+ pw.close();
1660
+ File file=new File(dir+"test.txt");
1661
+ file.createNewFile();
1662
+ System.out.println("File: "+file.getName());
1663
+ System.out.println("Exists: "+file.exists());
1664
+ System.out.println("Is File: "+file.isFile());
1665
+ System.out.println("Size: "+file.length()+" bytes");
1666
+ File folder=new File(dir+"test_directory");
1667
+ folder.mkdir();
1668
+ for(int i=1;i<=3;i++)
1669
+ new File(folder,"file"+i+".txt").createNewFile();
1670
+ System.out.println("Directory: "+folder.getName());
1671
+ for(File f:folder.listFiles())
1672
+ System.out.println(f.getName());
1673
+ BufferedReader r=new BufferedReader(new FileReader(charFile));
1674
+ BufferedWriter w=new BufferedWriter(new FileWriter(dir+"copy.txt"));
1675
+ while((line=r.readLine())!=null){
1676
+ w.write(line);
1677
+ w.newLine();
1678
+ }
1679
+ r.close();
1680
+ w.close();
1681
+ System.out.println("File copied successfully");
1682
+ FileWriter aw=new FileWriter(dir+"append.txt");
1683
+ aw.write("Initial content\n");
1684
+ aw.close();
1685
+ aw=new FileWriter(dir+"append.txt",true);
1686
+ aw.write("Appended content\n");
1687
+ aw.close();
1688
+ System.out.println("Content appended successfully");
1689
+ System.out.println("===== FILE HANDLING COMPLETED =====");
1690
+ } catch(IOException e) {
1691
+ System.out.println("Error: "+e.getMessage());
1692
+ }
1693
+ }
1694
+ }
1695
+
1696
+ Experiment 11: ArrayList Insertion and Deletion Operations
1697
+ import java.util.*;
1698
+ public class Experiment11 {
1699
+ static void display(ArrayList<?> list) {
1700
+ System.out.println("Content: " + list);
1701
+ System.out.println("Size: " + list.size());
1702
+ }
1703
+ public static void main(String[] args) {
1704
+ ArrayList<String> fruits = new ArrayList<>();
1705
+ System.out.println("===== ArrayList OPERATIONS =====");
1706
+ fruits.add("Apple");
1707
+ fruits.add("Banana");
1708
+ fruits.add("Cherry");
1709
+ fruits.add(1, "Mango");
1710
+ fruits.add(0, "Grapes");
1711
+ fruits.addAll(Arrays.asList("Orange", "Kiwi", "Papaya"));
1712
+ fruits.addAll(3, Arrays.asList("Strawberry", "Blueberry"));
1713
+ fruits.set(0, "Green Grapes");
1714
+ System.out.println("\nInsertion:");
1715
+ display(fruits);
1716
+ fruits.remove(0);
1717
+ fruits.remove("Kiwi");
1718
+ fruits.removeAll(Arrays.asList("Strawberry", "Blueberry"));
1719
+ fruits.addAll(Arrays.asList("Apricot", "Avocado", "Plum"));
1720
+ fruits.removeIf(f -> f.startsWith("A"));
1721
+ Iterator<String> it = fruits.iterator();
1722
+ while (it.hasNext())
1723
+ if (it.next().startsWith("P"))
1724
+ it.remove();
1725
+ fruits.addAll(Arrays.asList("Apple", "Banana", "Cherry", "Date"));
1726
+ fruits.retainAll(Arrays.asList("Apple", "Banana", "Cherry"));
1727
+ System.out.println("\nDeletion:");
1728
+ display(fruits);
1729
+ fruits.clear();
1730
+ System.out.println("After clear: " + fruits);
1731
+ System.out.println("isEmpty: " + fruits.isEmpty());
1732
+ fruits = new ArrayList<>(Arrays.asList("Apple", "Banana", "Cherry", "Date", "Apple", "Elderberry", "Apple"));
1733
+ System.out.println("\nSearch:");
1734
+ System.out.println("contains Banana: " + fruits.contains("Banana"));
1735
+ System.out.println("indexOf Apple: " + fruits.indexOf("Apple"));
1736
+ System.out.println("lastIndexOf Apple: " + fruits.lastIndexOf("Apple"));
1737
+ System.out.println("get(2): " + fruits.get(2));
1738
+ System.out.println("\ntoArray: " + Arrays.toString(fruits.toArray()));
1739
+ System.out.println("subList(1,4): " + fruits.subList(1, 4));
1740
+ Collections.sort(fruits);
1741
+ System.out.println("Sorted: " + fruits);
1742
+ Collections.sort(fruits, Collections.reverseOrder());
1743
+ System.out.println("Reverse Sorted: " + fruits);
1744
+ System.out.print("\nFor-each: ");
1745
+ for (String f : fruits)
1746
+ System.out.print(f + " ");
1747
+ System.out.print("\nLambda: ");
1748
+ fruits.forEach(f -> System.out.print(f + " | "));
1749
+ ListIterator<String> li = fruits.listIterator();
1750
+ System.out.print("\nForward: ");
1751
+ while (li.hasNext())
1752
+ System.out.print(li.next() + " ");
1753
+ System.out.print("\nBackward: ");
1754
+ while (li.hasPrevious())
1755
+ System.out.print(li.previous() + " ");
1756
+ ArrayList<Integer> numbers = new ArrayList<>(Arrays.asList(5, 2, 8, 1, 9, 3, 7));
1757
+ numbers.add(10);
1758
+ numbers.add(0, 0);
1759
+ numbers.remove(Integer.valueOf(5));
1760
+ numbers.remove(0);
1761
+ Collections.sort(numbers);
1762
+ System.out.println("\n\nInteger ArrayList:");
1763
+ display(numbers);
1764
+ System.out.println("Sum: " + numbers.stream().mapToInt(Integer::intValue).sum());
1765
+ System.out.println("Max: " + Collections.max(numbers));
1766
+ System.out.println("Min: " + Collections.min(numbers));
1767
+ System.out.println("\n===== PROGRAM COMPLETED =====");
1768
+ }
1769
+ }
1770
+ Experiment 12: LinkedList Traversal using ListIterator
1771
+ import java.util.*;
1772
+ public class Experiment12 {
1773
+ static void display(LinkedList<?> list) {
1774
+ System.out.println("Content: " + list);
1775
+ System.out.println("Size: " + list.size());
1776
+ }
1777
+ public static void main(String[] args) {
1778
+ LinkedList<String> countries = new LinkedList<>();
1779
+ countries.addAll(Arrays.asList("India","USA","UK","Canada","Australia","Germany","France"));
1780
+ System.out.println("===== LinkedList TRAVERSAL =====");
1781
+ display(countries);
1782
+ ListIterator<String> it = countries.listIterator();
1783
+ System.out.print("\nForward: ");
1784
+ while (it.hasNext())
1785
+ System.out.print(it.next() + " ");
1786
+ System.out.print("\nBackward: ");
1787
+ while (it.hasPrevious())
1788
+ System.out.print(it.previous() + " ");
1789
+ ListIterator<String> mid = countries.listIterator(3);
1790
+ System.out.print("\n\nFrom index 3: ");
1791
+ while (mid.hasNext())
1792
+ System.out.print(mid.next() + " ");
1793
+ while (mid.hasPrevious())
1794
+ mid.previous();
1795
+ ListIterator<String> modify = countries.listIterator();
1796
+ while (modify.hasNext()) {
1797
+ String s = modify.next();
1798
+ if (s.equals("USA"))
1799
+ modify.set("United States");
1800
+ if (s.equals("UK"))
1801
+ modify.set("United Kingdom");
1802
+ }
1803
+ System.out.println("\n\nAfter set():");
1804
+ display(countries);
1805
+ ListIterator<String> add = countries.listIterator();
1806
+ while (add.hasNext()) {
1807
+ if (add.next().equals("Canada"))
1808
+ add.add("Japan");
1809
+ }
1810
+ add = countries.listIterator();
1811
+ add.add("Brazil");
1812
+ System.out.println("\nAfter add():");
1813
+ display(countries);
1814
+ ListIterator<String> remove = countries.listIterator();
1815
+ while (remove.hasNext()) {
1816
+ String s = remove.next();
1817
+ if (s.equals("Japan") || s.equals("Brazil"))
1818
+ remove.remove();
1819
+ }
1820
+ System.out.println("\nAfter remove():");
1821
+ display(countries);
1822
+ ListIterator<String> index = countries.listIterator(3);
1823
+ System.out.println("\nnextIndex(): " + index.nextIndex());
1824
+ System.out.println("previousIndex(): " + index.previousIndex());
1825
+ Iterator<String> simple = countries.iterator();
1826
+ System.out.print("\nIterator: ");
1827
+ while (simple.hasNext())
1828
+ System.out.print(simple.next() + " ");
1829
+ LinkedList<Integer> numbers = new LinkedList<>();
1830
+ for (int i=1;i<=5;i++)
1831
+ numbers.add(i*10);
1832
+ System.out.println("\n\n===== LinkedList as Deque =====");
1833
+ display(numbers);
1834
+ System.out.println("getFirst(): " + numbers.getFirst());
1835
+ System.out.println("getLast(): " + numbers.getLast());
1836
+ numbers.addFirst(5);
1837
+ numbers.addLast(60);
1838
+ System.out.println("After addFirst/addLast: " + numbers);
1839
+ System.out.println("pollFirst(): " + numbers.pollFirst());
1840
+ System.out.println("pollLast(): " + numbers.pollLast());
1841
+ numbers.push(0);
1842
+ System.out.println("pop(): " + numbers.pop());
1843
+ LinkedList<String> letters = new LinkedList<>(Arrays.asList("A","B","C","D","E"));
1844
+ ListIterator<String> li = letters.listIterator();
1845
+ System.out.print("\nZigzag Forward: ");
1846
+ while (li.hasNext())
1847
+ System.out.print(li.next() + " ");
1848
+ System.out.print("\nZigzag Backward: ");
1849
+ while (li.hasPrevious())
1850
+ System.out.print(li.previous() + " ");
1851
+ System.out.println("\n\n===== PROGRAM COMPLETED =====");
1852
+ }
1853
+ }
1854
+ Experiment 13: GUI Application using Swing Package
1855
+ import javax.swing.*;
1856
+ import javax.swing.border.*;
1857
+ import java.awt.*;
1858
+ public class Experiment9 extends JFrame {
1859
+ JTextField name,email,phone;
1860
+ JPasswordField password;
1861
+ JRadioButton male,female,other;
1862
+ JCheckBox java,python,cpp,js;
1863
+ JComboBox<String> course;
1864
+ JTextArea address,output;
1865
+ JSpinner age;
1866
+ JSlider experience;
1867
+ JButton submit,clear,exit;
1868
+ public Experiment13() {
1869
+ setTitle("Student Registration Form");
1870
+ setSize(800,700);
1871
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
1872
+ setLocationRelativeTo(null);
1873
+ JPanel main=new JPanel(new BorderLayout(10,10));
1874
+ main.setBorder(new EmptyBorder(15,15,15,15));
1875
+ JLabel title=new JLabel("Student Registration Form",JLabel.CENTER);
1876
+ title.setFont(new Font("Arial",Font.BOLD,24));
1877
+ main.add(title,BorderLayout.NORTH);
1878
+ JPanel form=new JPanel(new GridBagLayout());
1879
+ form.setBorder(new TitledBorder("Personal Information"));
1880
+ GridBagConstraints g=new GridBagConstraints();
1881
+ g.insets=new Insets(5,5,5,5);
1882
+ g.fill=GridBagConstraints.HORIZONTAL;
1883
+ name=new JTextField(20);
1884
+ email=new JTextField(20);
1885
+ password=new JPasswordField(20);
1886
+ phone=new JTextField(20);
1887
+ age=new JSpinner(new SpinnerNumberModel(18,15,60,1));
1888
+ add(form,g,0,"Full Name:",name);
1889
+ add(form,g,1,"Email:",email);
1890
+ add(form,g,2,"Password:",password);
1891
+ add(form,g,3,"Phone:",phone);
1892
+ add(form,g,4,"Age:",age);
1893
+ male=new JRadioButton("Male");
1894
+ female=new JRadioButton("Female");
1895
+ other=new JRadioButton("Other");
1896
+ ButtonGroup bg=new ButtonGroup();
1897
+ bg.add(male); bg.add(female); bg.add(other);
1898
+ JPanel gender=new JPanel();
1899
+ gender.add(male); gender.add(female); gender.add(other);
1900
+ add(form,g,5,"Gender:",gender);
1901
+ course=new JComboBox<>(new String[]{"Select Course","Computer Science","IT","Electronics","Mechanical","Civil"});
1902
+ add(form,g,6,"Course:",course);
1903
+ java=new JCheckBox("Java");
1904
+ python=new JCheckBox("Python");
1905
+ cpp=new JCheckBox("C++");
1906
+ js=new JCheckBox("JavaScript");
1907
+ JPanel skills=new JPanel();
1908
+ skills.add(java); skills.add(python); skills.add(cpp); skills.add(js);
1909
+ add(form,g,7,"Skills:",skills);
1910
+ experience=new JSlider(0,10,0);
1911
+ experience.setPaintTicks(true);
1912
+ experience.setPaintLabels(true);
1913
+ experience.setMajorTickSpacing(2);
1914
+ add(form,g,8,"Experience:",experience);
1915
+ address=new JTextArea(3,20);
1916
+ add(form,g,9,"Address:",new JScrollPane(address));
1917
+ main.add(form,BorderLayout.CENTER);
1918
+ submit=new JButton("Submit");
1919
+ clear=new JButton("Clear");
1920
+ exit=new JButton("Exit");
1921
+ JPanel buttons=new JPanel();
1922
+ buttons.add(submit); buttons.add(clear); buttons.add(exit);
1923
+ output=new JTextArea(7,40);
1924
+ output.setEditable(false);
1925
+ JPanel out=new JPanel(new BorderLayout());
1926
+ out.setBorder(new TitledBorder("Output"));
1927
+ out.add(new JScrollPane(output));
1928
+ JPanel south=new JPanel(new BorderLayout());
1929
+ south.add(buttons,BorderLayout.NORTH);
1930
+ south.add(out,BorderLayout.CENTER);
1931
+ main.add(south,BorderLayout.SOUTH);
1932
+ add(main);
1933
+ submit.addActionListener(e->submitForm());
1934
+ clear.addActionListener(e->clearForm());
1935
+ exit.addActionListener(e->System.exit(0));
1936
+ }
1937
+ void add(JPanel p,GridBagConstraints g,int row,String label,Component c) {
1938
+ g.gridx=0; g.gridy=row; g.gridwidth=1;
1939
+ p.add(new JLabel(label),g);
1940
+ g.gridx=1; g.gridwidth=2;
1941
+ p.add(c,g);
1942
+ }
1943
+ void submitForm() {
1944
+ if(name.getText().trim().isEmpty()||email.getText().trim().isEmpty()||course.getSelectedIndex()==0) {
1945
+ JOptionPane.showMessageDialog(this,"Enter Name, Email and Course");
1946
+ return;
1947
+ }
1948
+ String gender=male.isSelected()?"Male":female.isSelected()?"Female":other.isSelected()?"Other":"None";
1949
+ String skills="";
1950
+ if(java.isSelected()) skills+="Java ";
1951
+ if(python.isSelected()) skills+="Python ";
1952
+ if(cpp.isSelected()) skills+="C++ ";
1953
+ if(js.isSelected()) skills+="JavaScript";
1954
+ output.setText("===== REGISTRATION DETAILS =====\n"+
1955
+ "Name: "+name.getText()+"\n"+
1956
+ "Email: "+email.getText()+"\n"+
1957
+ "Phone: "+phone.getText()+"\n"+
1958
+ "Age: "+age.getValue()+"\n"+
1959
+ "Gender: "+gender+"\n"+
1960
+ "Course: "+course.getSelectedItem()+"\n"+
1961
+ "Skills: "+skills+"\n"+
1962
+ "Experience: "+experience.getValue()+" years\n"+
1963
+ "Address: "+address.getText()+"\n"+
1964
+ "Registration submitted successfully!");
1965
+ JOptionPane.showMessageDialog(this,"Registration submitted successfully!");
1966
+ }
1967
+ void clearForm() {
1968
+ name.setText("");
1969
+ email.setText("");
1970
+ password.setText("");
1971
+ phone.setText("");
1972
+ age.setValue(18);
1973
+ male.setSelected(false);
1974
+ female.setSelected(false);
1975
+ other.setSelected(false);
1976
+ course.setSelectedIndex(0);
1977
+ java.setSelected(false);
1978
+ python.setSelected(false);
1979
+ cpp.setSelected(false);
1980
+ js.setSelected(false);
1981
+ experience.setValue(0);
1982
+ address.setText("");
1983
+ output.setText("");
1984
+ }
1985
+ public static void main(String[] args) {
1986
+ SwingUtilities.invokeLater(()->new Experiment13().setVisible(true));
1987
+ }
1988
+ }
1989
+ Experiment 14: Event Handling using Anonymous Inner Classes
1990
+ import javax.swing.*;
1991
+ import javax.swing.border.*;
1992
+ import java.awt.*;
1993
+ import java.awt.event.*;
1994
+ public class Experiment14 extends JFrame {
1995
+ JTextArea logArea;
1996
+ int count=0;
1997
+ public Experiment14() {
1998
+ setTitle("Event Handling using Anonymous Inner Classes");
1999
+ setSize(800,650);
2000
+ setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
2001
+ setLocationRelativeTo(null);
2002
+ JPanel main=new JPanel(new BorderLayout(10,10));
2003
+ main.setBorder(new EmptyBorder(10,10,10,10));
2004
+ JLabel head=new JLabel("Event Handling Demonstration",JLabel.CENTER);
2005
+ head.setFont(new Font("Arial",Font.BOLD,20));
2006
+ main.add(head,BorderLayout.NORTH);
2007
+ JPanel center=new JPanel(new GridLayout(3,2,10,10));
2008
+ JPanel p1=panel("1. ActionListener");
2009
+ JButton b=new JButton("Click Me");
2010
+ b.addActionListener(new ActionListener(){
2011
+ public void actionPerformed(ActionEvent e){
2012
+ count++;
2013
+ log("ActionEvent: Button clicked - "+count);
2014
+ }
2015
+ });
2016
+ p1.add(b);
2017
+ center.add(p1);
2018
+ JPanel p2=panel("2. MouseListener");
2019
+ JLabel mouse=new JLabel("Click / Hover",JLabel.CENTER);
2020
+ mouse.setPreferredSize(new Dimension(150,70));
2021
+ mouse.addMouseListener(new MouseListener(){
2022
+ public void mouseClicked(MouseEvent e){log("MouseEvent: CLICKED");}
2023
+ public void mousePressed(MouseEvent e){log("MouseEvent: PRESSED");}
2024
+ public void mouseReleased(MouseEvent e){log("MouseEvent: RELEASED");}
2025
+ public void mouseEntered(MouseEvent e){log("MouseEvent: ENTERED");}
2026
+ public void mouseExited(MouseEvent e){log("MouseEvent: EXITED");}
2027
+ });
2028
+ p2.add(mouse);
2029
+ center.add(p2);
2030
+ JPanel p3=panel("3. KeyListener");
2031
+ JTextField key=new JTextField("Type here",15);
2032
+ key.addKeyListener(new KeyListener(){
2033
+ public void keyTyped(KeyEvent e){log("KeyEvent: TYPED - "+e.getKeyChar());}
2034
+ public void keyPressed(KeyEvent e){log("KeyEvent: PRESSED - "+KeyEvent.getKeyText(e.getKeyCode()));}
2035
+ public void keyReleased(KeyEvent e){log("KeyEvent: RELEASED");}
2036
+ });
2037
+ p3.add(key);
2038
+ center.add(p3);
2039
+ JPanel p4=panel("4. ItemListener");
2040
+ JCheckBox c1=new JCheckBox("Option 1");
2041
+ JCheckBox c2=new JCheckBox("Option 2");
2042
+ JComboBox<String> combo=new JComboBox<>(new String[]{"Select","Java","Python","C++"});
2043
+ ItemListener il=new ItemListener(){
2044
+ public void itemStateChanged(ItemEvent e){
2045
+ if(e.getStateChange()==ItemEvent.SELECTED)
2046
+ log("ItemEvent: "+e.getItem());
2047
+ }
2048
+ };
2049
+ c1.addItemListener(il);
2050
+ c2.addItemListener(il);
2051
+ combo.addItemListener(il);
2052
+ p4.add(c1); p4.add(c2); p4.add(combo);
2053
+ center.add(p4);
2054
+ JPanel p5=panel("5. FocusListener");
2055
+ JTextField f1=new JTextField("Field 1",10);
2056
+ JTextField f2=new JTextField("Field 2",10);
2057
+ FocusListener fl=new FocusListener(){
2058
+ public void focusGained(FocusEvent e){log("FocusEvent: GAINED");}
2059
+ public void focusLost(FocusEvent e){log("FocusEvent: LOST");}
2060
+ };
2061
+ f1.addFocusListener(fl);
2062
+ f2.addFocusListener(fl);
2063
+ p5.add(f1); p5.add(f2);
2064
+ center.add(p5);
2065
+ JPanel p6=panel("6. MouseMotionListener");
2066
+ JLabel motion=new JLabel("Move mouse here",JLabel.CENTER);
2067
+ motion.setPreferredSize(new Dimension(150,70));
2068
+ motion.addMouseMotionListener(new MouseMotionListener(){
2069
+ public void mouseMoved(MouseEvent e){motion.setText("Position: "+e.getX()+","+e.getY());}
2070
+ public void mouseDragged(MouseEvent e){motion.setText("Dragging: "+e.getX()+","+e.getY());}
2071
+ });
2072
+ p6.add(motion);
2073
+ center.add(p6);
2074
+ main.add(center,BorderLayout.CENTER);
2075
+ logArea=new JTextArea(8,50);
2076
+ logArea.setEditable(false);
2077
+ JButton clear=new JButton("Clear Log");
2078
+ clear.addActionListener(new ActionListener(){
2079
+ public void actionPerformed(ActionEvent e){
2080
+ logArea.setText("");
2081
+ count=0;
2082
+ }
2083
+ });
2084
+ JPanel log=new JPanel(new BorderLayout());
2085
+ log.setBorder(new TitledBorder("Event Log"));
2086
+ log.add(new JScrollPane(logArea),BorderLayout.CENTER);
2087
+ log.add(clear,BorderLayout.SOUTH);
2088
+ main.add(log,BorderLayout.SOUTH);
2089
+ add(main);
2090
+ addWindowListener(new WindowListener(){
2091
+ public void windowOpened(WindowEvent e){log("WindowEvent: OPENED");}
2092
+ public void windowClosing(WindowEvent e){
2093
+ int x=JOptionPane.showConfirmDialog(Experiment14.this,"Exit?","Confirm",JOptionPane.YES_NO_OPTION);
2094
+ if(x==JOptionPane.YES_OPTION) System.exit(0);
2095
+ }
2096
+ public void windowClosed(WindowEvent e){log("WindowEvent: CLOSED");}
2097
+ public void windowIconified(WindowEvent e){log("WindowEvent: ICONIFIED");}
2098
+ public void windowDeiconified(WindowEvent e){log("WindowEvent: DEICONIFIED");}
2099
+ public void windowActivated(WindowEvent e){log("WindowEvent: ACTIVATED");}
2100
+ public void windowDeactivated(WindowEvent e){log("WindowEvent: DEACTIVATED");}
2101
+ });
2102
+ log("Application started.");
2103
+ }
2104
+ JPanel panel(String title){
2105
+ JPanel p=new JPanel(new FlowLayout());
2106
+ p.setBorder(new TitledBorder(title));
2107
+ return p;
2108
+ }
2109
+ void log(String s){
2110
+ if(logArea!=null) logArea.append(s+"\n");
2111
+ }
2112
+ public static void main(String[] args){
2113
+ SwingUtilities.invokeLater(new Runnable(){
2114
+ public void run(){
2115
+ new Experiment14().setVisible(true);
2116
+ }
2117
+ });
2118
+ }
2119
+ }
2120
+ Experiment 15: Database Connectivity using JDBC for CRUD Operations
2121
+ import java.sql.*;
2122
+ import java.util.Scanner;
2123
+ public class ex15{
2124
+ static final String URL="jdbc:mysql://sql.freedb.tech/freedb_bsVOiTyJ";
2125
+ static final String USER="u_2c76qE";
2126
+ static final String PASSWORD="UKxEJVaF0FY8";
2127
+ public static void main(String[] args){
2128
+ Scanner sc=new Scanner(System.in);
2129
+ try{
2130
+ Connection con=DriverManager.getConnection(URL,USER,PASSWORD);
2131
+ System.out.println("================================");
2132
+ System.out.println(" JDBC DATABASE CONNECTED");
2133
+ System.out.println("================================");
2134
+ int choice;
2135
+ do{
2136
+ System.out.println("\n===== STUDENT DATABASE =====");
2137
+ System.out.println("1. Insert Student");
2138
+ System.out.println("2. Display Students");
2139
+ System.out.println("3. Update Student");
2140
+ System.out.println("4. Delete Student");
2141
+ System.out.println("5. Exit");
2142
+ System.out.print("Enter your choice: ");
2143
+ choice=sc.nextInt();
2144
+ switch(choice){
2145
+ case 1:
2146
+ System.out.print("Enter Student ID: ");
2147
+ int id=sc.nextInt();
2148
+ sc.nextLine();
2149
+ System.out.print("Enter Student Name: ");
2150
+ String name=sc.nextLine();
2151
+ System.out.print("Enter Marks: ");
2152
+ int marks=sc.nextInt();
2153
+ String insertQuery="INSERT INTO student VALUES (?, ?, ?)";
2154
+ PreparedStatement insertStmt=con.prepareStatement(insertQuery);
2155
+ insertStmt.setInt(1,id);
2156
+ insertStmt.setString(2,name);
2157
+ insertStmt.setInt(3,marks);
2158
+ int inserted=insertStmt.executeUpdate();
2159
+ if(inserted>0) System.out.println("Student inserted successfully!");
2160
+ insertStmt.close();
2161
+ break;
2162
+ case 2:
2163
+ String selectQuery="SELECT * FROM student";
2164
+ Statement stmt=con.createStatement();
2165
+ ResultSet rs=stmt.executeQuery(selectQuery);
2166
+ System.out.println("\n--------------------------------");
2167
+ System.out.println("ID\tName\tMarks");
2168
+ System.out.println("--------------------------------");
2169
+ while(rs.next()){
2170
+ int sid=rs.getInt("id");
2171
+ String sname=rs.getString("name");
2172
+ int smarks=rs.getInt("marks");
2173
+ System.out.println(sid+"\t"+sname+"\t"+smarks);
2174
+ }
2175
+ rs.close();
2176
+ stmt.close();
2177
+ break;
2178
+ case 3:
2179
+ System.out.print("Enter Student ID to update: ");
2180
+ int updateId=sc.nextInt();
2181
+ System.out.print("Enter new marks: ");
2182
+ int newMarks=sc.nextInt();
2183
+ String updateQuery="UPDATE student SET marks = ? WHERE id = ?";
2184
+ PreparedStatement updateStmt=con.prepareStatement(updateQuery);
2185
+ updateStmt.setInt(1,newMarks);
2186
+ updateStmt.setInt(2,updateId);
2187
+ int updated=updateStmt.executeUpdate();
2188
+ if(updated>0) System.out.println("Student updated successfully!");
2189
+ else System.out.println("Student ID not found.");
2190
+ updateStmt.close();
2191
+ break;
2192
+ case 4:
2193
+ System.out.print("Enter Student ID to delete: ");
2194
+ int deleteId=sc.nextInt();
2195
+ String deleteQuery="DELETE FROM student WHERE id = ?";
2196
+ PreparedStatement deleteStmt=con.prepareStatement(deleteQuery);
2197
+ deleteStmt.setInt(1,deleteId);
2198
+ int deleted=deleteStmt.executeUpdate();
2199
+ if(deleted>0) System.out.println("Student deleted successfully!");
2200
+ else System.out.println("Student ID not found.");
2201
+ deleteStmt.close();
2202
+ break;
2203
+ case 5:
2204
+ System.out.println("Exiting program...");
2205
+ break;
2206
+ default:
2207
+ System.out.println("Invalid choice! Try again.");
2208
+ }
2209
+ }while(choice!=5);
2210
+ con.close();
2211
+ System.out.println("Database connection closed.");
2212
+ }catch(SQLException e){
2213
+ System.out.println("Database Error: "+e.getMessage());
2214
+ }
2215
+ sc.close();
2216
+ }
2217
+ }
2218
+ CREATE DATABASE studentdb;
2219
+ USE studentdb;
2220
+ CREATE TABLE student(
2221
+ id INT PRIMARY KEY,
2222
+ name VARCHAR(50),
2223
+ marks INT
2224
+ );
2225
+ INSERT INTO student VALUES
2226
+ (101,'Sanjay',85),
2227
+ (102,'Arun',90),
2228
+ (103,'Kumar',78);
2229
+ SELECT * FROM student;
2230
+
2231
+
2232
+
2233
+
2234
+
2235
+
2236
+ """)