Skip to content

Commit 9f61866

Browse files
Code
1 parent a15f220 commit 9f61866

30 files changed

+980
-0
lines changed

Diff for: BCA-V JAVA Practicle File Questions.pdf

22.8 KB
Binary file not shown.

Diff for: Calc/Add.java

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package Calc;
2+
3+
import java.util.Scanner;
4+
5+
public class Add {
6+
int sum;
7+
public void sum()
8+
{
9+
System.out.print("Enter the first number: ");
10+
Scanner sc = new Scanner(System.in);
11+
int firstNum = sc.nextInt();
12+
System.out.print("Enter the second number: ");
13+
int secondNum = sc.nextInt();
14+
sum = firstNum+secondNum;
15+
System.out.println("Sum=" + sum);
16+
}
17+
}

Diff for: Calc/Subtract.java

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package Calc;
2+
3+
import java.util.Scanner;
4+
5+
public class Subtract {
6+
int difference;
7+
public void subtract()
8+
{
9+
System.out.print("Enter the first number: ");
10+
Scanner sc = new Scanner(System.in);
11+
int firstNum = sc.nextInt();
12+
System.out.print("Enter the second number: ");
13+
int secondNum = sc.nextInt();
14+
difference = firstNum-secondNum;
15+
System.out.println("Difference=" + difference);
16+
}
17+
}

Diff for: Q10_Overload_Area_fun.java

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//Q10. WAP to show the overloading of area function.
2+
package JAVA_Lab_File;
3+
4+
import java.util.Scanner;
5+
6+
public class Q10_Overload_Area_fun {
7+
static void area(double radius){
8+
double area = Math.PI * radius * radius;
9+
System.out.print("Area of Circle is: " + String.format("%.5f", area) + " sq. units");
10+
}
11+
static void area(double base, double height){
12+
double area = 0.5*base*height;
13+
System.out.print("Area of Triangle is: " + String.format("%.5f", area) + " sq. units");
14+
}
15+
public static void main(String[] args) {
16+
Scanner sc = new Scanner(System.in);
17+
System.out.println("Calculate Area: \n1.Circle\n2.Triangle\nChoice: ");
18+
int choice = sc.nextInt();
19+
if(choice == 1){
20+
System.out.print("Enter the radius of the circle: ");
21+
double radius = sc.nextDouble();
22+
area(radius);
23+
} else if (choice == 2) {
24+
System.out.print("Enter the base and height of the triangle: ");
25+
double base = sc.nextDouble();
26+
double height = sc.nextDouble();
27+
area(base, height);
28+
}else {
29+
System.out.println("Invalid choice");
30+
}
31+
}
32+
}

Diff for: Q11_isArmstrong.java

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//Q11. WAP to check whether a given number is Armstrong or not.
2+
package JAVA_Lab_File;
3+
4+
public class Q11_isArmstrong {
5+
public static void main(String[] args) {
6+
7+
int number = 153, originalNumber, remainder, result = 0;
8+
originalNumber = number;
9+
10+
while (originalNumber != 0)
11+
{
12+
remainder = originalNumber % 10;
13+
result += Math.pow(remainder, 3);
14+
originalNumber /= 10;
15+
}
16+
if(result == number) {
17+
System.out.println(number + " is an Armstrong number.");
18+
} else {
19+
System.out.println(number + " is not an Armstrong number.");
20+
}
21+
}
22+
}

Diff for: Q12_Implement_interface.java

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//Q12. WAP to check whether a given number is Armstrong or not.
2+
package JAVA_Lab_File;
3+
4+
interface Animal {
5+
public void animalSound();
6+
public void sleep();
7+
}
8+
class Siyaar implements Animal {
9+
public void animalSound() {
10+
System.out.println("The Siyaar howls: Aaooo Aaooo");
11+
}
12+
public void sleep() {
13+
System.out.println("Zzz");
14+
}
15+
}
16+
public class Q12_Implement_interface {
17+
18+
public static void main(String[] args) {
19+
Siyaar S_Siyaar = new Siyaar();
20+
S_Siyaar.animalSound();
21+
S_Siyaar.sleep();
22+
}
23+
}

Diff for: Q13_SumAndSub_Pack.java

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//Q13. WAP to create a package Calc with methods Sum() & Sub() and show the Implementation in a class.
2+
package JAVA_Lab_File;
3+
4+
import Calc.Add;
5+
import Calc.Subtract;
6+
7+
import java.util.Scanner;
8+
9+
public class Q13_SumAndSub_Pack {
10+
public static void main(String[] args)
11+
{
12+
System.out.println("Sum ");
13+
System.out.println("Subtract ");
14+
15+
System.out.print("Enter your choice: ");
16+
Scanner sc = new Scanner(System.in);
17+
int t = sc.nextInt();
18+
switch (t) {
19+
case 1 -> {
20+
Add a = new Add();
21+
a.sum();
22+
}
23+
case 2 -> {
24+
Subtract s = new Subtract();
25+
s.subtract();
26+
}
27+
default -> System.out.println("invalid choice");
28+
}
29+
}
30+
}

Diff for: Q14_Reverse_Num.java

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//Q14. WAP to print reverse of a given number.
2+
package JAVA_Lab_File;
3+
4+
import java.util.Scanner;
5+
6+
public class Q14_Reverse_Num {
7+
public static void main(String[] args) {
8+
Scanner sc = new Scanner(System.in);
9+
System.out.println("Enter a no. to reverse it: ");
10+
int num = sc.nextInt();
11+
int r_num=0;
12+
while(num>0)
13+
{
14+
r_num=(r_num*10)+(num%10);
15+
num=num/10;
16+
}
17+
System.out.println("Reversed: "+ r_num);
18+
}
19+
}

Diff for: Q15_Single_catch.java

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//Q15. WAP to show the working of a single Catch block.
2+
package JAVA_Lab_File;
3+
4+
public class Q15_Single_catch {
5+
public static void main(String[] args) {
6+
try{
7+
int a = 10;
8+
int b = 0;
9+
int c = a/b; // exception
10+
}catch(ArithmeticException e){
11+
System.out.println(e);
12+
}
13+
}
14+
}

Diff for: Q16_Throw_and_Throws.java

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//Q16. WAP to show working of throw and throws for handling exceptions
2+
package JAVA_Lab_File;
3+
4+
import java.io.IOException;
5+
6+
public class Q16_Throw_and_Throws {
7+
8+
public static void main(String[] args) throws IOException {
9+
//declare exception
10+
Test.method();
11+
System.out.println("The Normal flow...");
12+
}
13+
}
14+
class Test {
15+
static void method()throws IOException
16+
{
17+
throw new IOException("Zaphkiel error");//checked exception
18+
}
19+
}
20+

Diff for: Q17_Table_of_a_no.java

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//Q17. WAP to print table of a given number.
2+
package JAVA_Lab_File;
3+
4+
public class Q17_Table_of_a_no {
5+
6+
public static void main(String[] args) {
7+
int n = 5;
8+
for (int i = 1; i <= 10; i++) {
9+
System.out.println(n + " * " + i + " = " + n * i);
10+
}
11+
}
12+
}
13+

Diff for: Q19_Vector_Class.java

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//Q19. WAP to show working of Vector class in java.
2+
package JAVA_Lab_File;
3+
4+
import java.util.Iterator;
5+
import java.util.Vector;
6+
7+
public class Q19_Vector_Class {
8+
public static void main(String args[]) {
9+
//Create a vector
10+
Vector<String> waifus = new Vector<String>();
11+
//Adding elements using add() method of List
12+
waifus.add("Kurumi");
13+
waifus.add("Rias");
14+
waifus.add("ZeroTwo");
15+
waifus.add("Yorha 2B");
16+
17+
//Adding elements using addElement() method of Vector
18+
waifus.addElement("Akeno");
19+
waifus.addElement("Rindou");
20+
waifus.addElement("Momo");
21+
22+
System.out.println("Elements are: "+waifus);
23+
}
24+
}

Diff for: Q1_CLI_Argument.java

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//Q1. WAP to enter two numbers using command line argument and calculate their sum and multiplication.
2+
package JAVA_Lab_File;
3+
4+
public class Q1_CLI_Argument {
5+
public static void main(String[] args) {
6+
int sum = Integer.parseInt(args[0]) + Integer.parseInt(args[1]);
7+
int multiplication = Integer.parseInt(args[0]) * Integer.parseInt(args[1]);
8+
9+
System.out.println("Sum of two CLI Arguments: " + (sum));
10+
System.out.println("Multiplication of two CLI Arguments: " + (multiplication));
11+
}
12+
}

Diff for: Q20_Border_Layout.java

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//Q20. WAP to arrange components using border layout.
2+
package JAVA_Lab_File;
3+
4+
import javax.swing.*;
5+
import java.awt.BorderLayout;
6+
import java.awt.Button;
7+
import java.awt.Color;
8+
9+
public class Q20_Border_Layout {
10+
// Main Method
11+
public static void main(String[] args) {
12+
BorderDemo obj = new BorderDemo();
13+
}
14+
}
15+
class BorderDemo extends JFrame{
16+
public BorderDemo()
17+
{
18+
setLayout(new BorderLayout());
19+
20+
setBackground(Color.red);
21+
22+
Button btn1 = new Button("Zaphkiel's");
23+
24+
Button btn2 = new Button("Kurumi");
25+
26+
Button btn3 = new Button("Tokisaki");
27+
28+
Button btn4 = new Button("Nightmare");
29+
30+
Button btn5 = new Button("Darling");
31+
32+
add(btn1, "North");
33+
34+
add(btn2, "South");
35+
36+
add(btn3, "East");
37+
38+
add(btn4, "West");
39+
40+
add(btn5, "Center");
41+
42+
setTitle("Zaphkiel's Border Layout");
43+
44+
setSize(350, 300);
45+
46+
setVisible(true);
47+
}
48+
49+
}

Diff for: Q21_Progress_bar.java

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//Q21. WAP to show working of a progress bar.
2+
package JAVA_Lab_File;
3+
4+
import javax.swing.*;
5+
6+
public class Q21_Progress_bar extends JFrame {
7+
static JFrame f;
8+
static JProgressBar b;
9+
10+
public static void main(String[] args) {
11+
f = new JFrame("Zaphkiel's Progress Bar");
12+
b = new JProgressBar(0, 2000);
13+
b.setBounds(40, 40, 160, 30);
14+
b.setValue(0);
15+
b.setStringPainted(true);
16+
f.add(b);
17+
f.setSize(250, 150);
18+
f.setLayout(null);
19+
f.setVisible(true);
20+
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
21+
fill();
22+
}
23+
public static void fill()
24+
{
25+
int i = 0;
26+
try {
27+
while (i <= 100) {
28+
b.setValue(i + 10);
29+
30+
Thread.sleep(1000);
31+
i += 20;
32+
}
33+
}
34+
catch (Exception e) {
35+
}
36+
}
37+
}

Diff for: Q22_Thread_by_Runnable.java

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//Q22. WAP to create threads by using Runnable interface
2+
package JAVA_Lab_File;
3+
4+
public class Q22_Thread_by_Runnable implements Runnable {
5+
public void run() {
6+
System.out.println("Thread Implemented by Runnable interface is running...");
7+
}
8+
9+
public static void main(String[] args) {
10+
Q22_Thread_by_Runnable obj = new Q22_Thread_by_Runnable();
11+
Thread t1 = new Thread(obj);
12+
t1.start();
13+
}
14+
}

0 commit comments

Comments
 (0)