Skip to content

Commit 073032f

Browse files
committed
lab_5 functional
1 parent 0d4fa3d commit 073032f

File tree

22 files changed

+178
-271
lines changed

22 files changed

+178
-271
lines changed

build/java_labs/Main.class

67 Bytes
Binary file not shown.

build/java_labs/lab_5/Lab.class

1.33 KB
Binary file not shown.
1.78 KB
Binary file not shown.
1.2 KB
Binary file not shown.
Binary file not shown.
2 KB
Binary file not shown.
399 Bytes
Binary file not shown.
Binary file not shown.
551 Bytes
Binary file not shown.

src/java_labs/Main.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public static void start() {
1818
System.out.println("[01] : LAB 1");
1919
System.out.println("[02] : LAB 2");
2020
System.out.println("[03] : LAB 3");
21-
System.out.println("[04] : LAB 4\n");
21+
System.out.println("[04] : LAB 4");
22+
System.out.println("[05] : LAB 5\n");
2223
System.out.println("[-1] : Exit\n");
2324
System.out.println("---------------------------\n");
2425
System.out.println("Enter your choice :\n");
@@ -43,7 +44,7 @@ public static void start() {
4344
java_labs.lab_4.Lab.start();
4445
break;
4546
case 5:
46-
//java_labs.lab_5.Lab.start();
47+
java_labs.lab_5.Lab.start();
4748
break;
4849
default:
4950
System.out.println("\nInvalid Choice");

src/java_labs/lab_4/problem_4/Divide.java

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ else if (divisor == 0)
2222
for (int i : arr)
2323
System.out.print(i + " ");
2424
System.out.println("\n");
25+
return;
2526
}
2627
}
2728
/*

src/java_labs/lab_4/problem_4/Sort.java

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ static void sort(int[] arr) throws Exception {
1818
for (int i : arr)
1919
System.out.print(i + " ");
2020
System.out.println("\n");
21+
return;
2122
}
2223
}
2324
/*

src/java_labs/lab_5/Lab.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
--||author : codechaser||--
44
~~~~~~~~~~~~~~~~~~~~~~~~~~~
55
*/
6-
package java_labs.lab_4;
6+
package java_labs.lab_5;
77

88
import java.util.*;
99
import java.io.*;
@@ -32,19 +32,19 @@ public static void start() {
3232
}
3333
switch (choice) {
3434
case 1:
35-
java_labs.lab_4.problem_1.Problem1.start();
35+
java_labs.lab_5.problem_1.Problem1.start();
3636
break;
3737
case 2:
38-
java_labs.lab_4.problem_2.Problem2.start();
38+
java_labs.lab_5.problem_2.Problem2.start();
3939
break;
4040
case 3:
41-
java_labs.lab_4.problem_3.Problem3.start();
41+
// java_labs.lab_5.problem_3.Problem3.start();
4242
break;
4343
case 4:
44-
java_labs.lab_4.problem_4.Problem4.start();
44+
// java_labs.lab_5.problem_4.Problem4.start();
4545
break;
4646
case 5:
47-
java_labs.lab_4.problem_5.Problem5.start();
47+
// java_labs.lab_5.problem_5.Problem5.start();
4848
break;
4949
default:
5050
System.out.println("\nInvalid Choice");

src/java_labs/lab_5/problem_1/Problem1.java

+22-120
Original file line numberDiff line numberDiff line change
@@ -3,133 +3,35 @@
33
--||author : codechaser||--
44
~~~~~~~~~~~~~~~~~~~~~~~~~~~
55
*/
6-
package java_labs.lab_4.problem_1;
6+
package java_labs.lab_5.problem_1;
77

88
import java.util.*;
99
import java.io.*;
10-
import java_labs.lab_4.problem_1.MCA.Student;
1110

1211
public class Problem1 {
1312
public static void start() {
14-
int students = 0;
15-
Vector<Student> studentsList = new Vector<Student>(1);
16-
while (true) {
17-
Scanner input = new Scanner(System.in);
18-
System.out.println("\n\n---------------------------");
19-
System.out.println(" S C H O O L");
20-
System.out.println("---------------------------\n");
21-
System.out.println("[01] : Add a new student");
22-
System.out.println("[02] : Update a students' marks");
23-
System.out.println("[03] : Print a student's details");
24-
System.out.println("[04] : Print all students' details\n");
25-
System.out.println("[-1] : Exit\n");
26-
System.out.println("---------------------------\n");
27-
System.out.println("Enter your choice :\n");
28-
int choice = input.nextInt();
29-
String temp = input.nextLine();
30-
System.out.println("\n---------------------------\n");
31-
if (choice == -1) {
32-
System.out.println("Exiting...\n");
33-
System.out.println("---------------------------\n");
34-
return;
35-
}
36-
String name;
37-
int roll, standard;
38-
double totalMarks, percentage, marksA, marksB, marksC, marksD, marksE;
39-
switch (choice) {
40-
case 1:
41-
System.out.println("\nEnter Student's Name: ");
42-
name = input.nextLine();
43-
System.out.println("\nEnter Student's Standard: ");
44-
standard = input.nextInt();
45-
temp = input.nextLine();
46-
System.out.println("\nNOTE: Enter all marks out of 100");
47-
System.out.println("\nEnter Student's marks in Computer Science: ");
48-
marksA = input.nextDouble();
49-
temp = input.nextLine();
50-
System.out.println("\nEnter Student's marks in Mathematics: ");
51-
marksB = input.nextDouble();
52-
temp = input.nextLine();
53-
System.out.println("\nEnter Student's marks in Physics: ");
54-
marksC = input.nextDouble();
55-
temp = input.nextLine();
56-
System.out.println("\nEnter Student's marks in Chemistry: ");
57-
marksD = input.nextDouble();
58-
temp = input.nextLine();
59-
System.out.println("\nEnter Student's marks in English: ");
60-
marksE = input.nextDouble();
61-
temp = input.nextLine();
62-
students++;
63-
Student S = new Student(name, students, standard, marksA, marksB, marksC, marksD, marksE);
64-
studentsList.add(S);
65-
System.out.println("\n" + name + " successfully added, their Roll Number is " + students + ".");
66-
System.out.println("\n---------------------------\n");
67-
break;
68-
case 2:
69-
System.out.println("\nEnter Student's Roll Number: ");
70-
roll = input.nextInt();
71-
temp = input.nextLine();
72-
if (roll < 1 || roll > students) {
73-
System.out.println("\nInvalid Roll Number!");
74-
System.out.println("\n---------------------------\n");
75-
break;
76-
}
77-
System.out.println("\nNOTE: Enter all marks out of 100");
78-
System.out.println("\nEnter Student's marks in Computer Science: ");
79-
marksA = input.nextDouble();
80-
temp = input.nextLine();
81-
System.out.println("\nEnter Student's marks in Mathematics: ");
82-
marksB = input.nextDouble();
83-
temp = input.nextLine();
84-
System.out.println("\nEnter Student's marks in Physics: ");
85-
marksC = input.nextDouble();
86-
temp = input.nextLine();
87-
System.out.println("\nEnter Student's marks in Chemistry: ");
88-
marksD = input.nextDouble();
89-
temp = input.nextLine();
90-
System.out.println("\nEnter Student's marks in English: ");
91-
marksE = input.nextDouble();
92-
temp = input.nextLine();
93-
studentsList.get(roll - 1).updateMarks(marksA, marksB, marksC, marksD, marksE);
94-
System.out.println("\nMarks updated successfully!");
95-
System.out.println("\n---------------------------\n");
96-
break;
97-
case 3:
98-
System.out.println("\nEnter Student's Roll Number: ");
99-
roll = input.nextInt();
100-
temp = input.nextLine();
101-
if (roll < 1 || roll > students) {
102-
System.out.println("\nInvalid Roll Number!");
103-
System.out.println("\n---------------------------\n");
104-
break;
105-
}
106-
System.out.println("\nDetails: \n");
107-
studentsList.get(roll - 1).display();
108-
totalMarks = studentsList.get(roll - 1).marksA + studentsList.get(roll - 1).marksB
109-
+ studentsList.get(roll - 1).marksC + studentsList.get(roll - 1).marksD
110-
+ studentsList.get(roll - 1).marksE;
111-
percentage = totalMarks / 5;
112-
System.out.print("\nTotal Marks: " + totalMarks);
113-
System.out.print("\nPercentage: " + percentage + "\n");
114-
System.out.println("\n---------------------------\n");
115-
break;
116-
case 4:
117-
System.out.println("\nDetails: \n");
118-
for (int i = 0; i < students; i++) {
119-
studentsList.get(i).display();
120-
totalMarks = studentsList.get(i).marksA + studentsList.get(i).marksB
121-
+ studentsList.get(i).marksC + studentsList.get(i).marksD + studentsList.get(i).marksE;
122-
percentage = totalMarks / 5;
123-
System.out.print("\nTotal Marks: " + totalMarks);
124-
System.out.print("\nPercentage: " + percentage + "\n");
125-
}
126-
System.out.println("\n--------------------------\n");
127-
break;
128-
default:
129-
System.out.println("\nInvalid Choice");
130-
System.out.println("\n---------------------------\n");
131-
}
13+
Scanner input = new Scanner(System.in);
14+
System.out.println("\n\n---------------------------");
15+
System.out.println(" V A C C I N A T I O N");
16+
System.out.println("---------------------------\n");
17+
System.out.println("Enter citizen's details :\n");
18+
System.out.println("Name :\n");
19+
String name = input.nextLine();
20+
System.out.println("\nAadhar Number :\n");
21+
String aadharNum = input.nextLine();
22+
System.out.println("\nPhone :\n");
23+
String phone = input.nextLine();
24+
System.out.println("\nAge :\n");
25+
int age = input.nextInt();
26+
String temp = input.nextLine();
27+
Vaccine v = new Vaccine(name,aadharNum,phone,age);
28+
try {
29+
v.verifyAge();
30+
} catch (Exception e) {
31+
System.out.print("\n" + e);
13232
}
33+
System.out.println("\n---------------------------\n");
34+
return;
13335
}
13436

13537
public static void main(String[] Args) {
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
--||author : codechaser||--
4+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
5+
*/
6+
package java_labs.lab_5.problem_1;
7+
8+
import java.util.*;
9+
import java.io.*;
10+
import java_labs.lab_5.problem_1.citizen.Citizen;
11+
12+
public class Vaccine extends Citizen {
13+
public Vaccine(String name, String aadharNum, String phone, int age) {
14+
super(name, aadharNum, phone, age);
15+
}
16+
17+
public void verifyAge() throws Exception {
18+
if (this.age < 18) {
19+
throw new Exception("Citizen must be at least 18 years old to be elligible for vaccination.\n");
20+
} else {
21+
System.out.println("\n" + name + " is elligible for vaccination!");
22+
}
23+
return;
24+
}
25+
}
26+
/*
27+
|---------------------------------------------------|
28+
||| https://codeforces.com/profile/codechaser |||
29+
||| https://www.codechef.com/users/codechaser |||
30+
||| https://github.com/code-chaser |||
31+
|---------------------------------------------------|
32+
*/

src/java_labs/lab_5/problem_1/citizen/Citizen.java

+8-33
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,18 @@
88
import java.util.*;
99
import java.io.*;
1010

11-
public class Student {
12-
private String name = "";
13-
private int roll, standard;
14-
public double marksA, marksB, marksC, marksD, marksE;
11+
public abstract class Citizen {
12+
protected String name, aadharNum, phone;
13+
protected int age;
1514

16-
public Student(String name, int roll, int standard, double marksA, double marksB, double marksC, double marksD,
17-
double marksE) {
15+
public Citizen(String name, String aadharNum, String phone, int age) {
1816
this.name = name;
19-
this.roll = roll;
20-
this.standard = standard;
21-
this.marksA = marksA;
22-
this.marksB = marksB;
23-
this.marksC = marksC;
24-
this.marksD = marksD;
25-
this.marksE = marksE;
17+
this.aadharNum = aadharNum;
18+
this.phone = phone;
19+
this.age = age;
2620
}
2721

28-
public void updateMarks(double marksA, double marksB, double marksC, double marksD, double marksE) {
29-
this.marksA = marksA;
30-
this.marksB = marksB;
31-
this.marksC = marksC;
32-
this.marksD = marksD;
33-
this.marksE = marksE;
34-
return;
35-
}
36-
37-
public void display() {
38-
System.out.print("\n\nName: " + this.name);
39-
System.out.print("\nRoll Number: " + this.roll);
40-
System.out.print("\nStandard: " + this.standard);
41-
System.out.print("\nMarks in Computer Science: " + this.marksA);
42-
System.out.print("\nMarks in Mathematics: " + this.marksB);
43-
System.out.print("\nMarks in Physics: " + this.marksC);
44-
System.out.print("\nMarks in Chemistry: " + this.marksD);
45-
System.out.print("\nMarks in English: " + this.marksE + "\n\n");
46-
return;
47-
}
22+
public abstract void verifyAge() throws Exception;
4823
}
4924
/*
5025
|---------------------------------------------------|
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
--||author : codechaser||--
4+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
5+
*/
6+
package java_labs.lab_5.problem_2;
7+
8+
import java.util.*;
9+
import java.io.*;
10+
import java_labs.lab_5.problem_2.package1.*;
11+
12+
public class Main {
13+
public static void start() {
14+
Scanner input = new Scanner(System.in);
15+
System.out.println("\n\n---------------------------");
16+
System.out.println(" P R O B L E M 2");
17+
System.out.println("---------------------------\n");
18+
System.out.println("Enter the size of the list :\n");
19+
int size = input.nextInt();
20+
System.out.println("\nEnter the elements of the list :\n");
21+
Vector<Integer> list = new Vector<Integer>(size);
22+
for(int i = 0; i < size; i++) {
23+
int inp = input.nextInt();
24+
list.add(inp);
25+
}
26+
System.out.println("\n---------------------------\n");
27+
double ans = Sum.sum(list);
28+
int k;
29+
try {
30+
k = Minimum.minimum(list);
31+
if(k == 0) throw new Exception("Cannot divide by zero. Minimum element of the list cannot be zero.\n");
32+
} catch (Exception e) {
33+
System.out.println(e);
34+
System.out.println("\n---------------------------\n");
35+
return;
36+
}
37+
ans /= k;
38+
System.out.println("The required answer is : " + ans);
39+
System.out.println("\n---------------------------\n");
40+
}
41+
42+
public static void main(String[] Args) {
43+
start();
44+
return;
45+
}
46+
}
47+
/*
48+
|---------------------------------------------------|
49+
||| https://codeforces.com/profile/codechaser |||
50+
||| https://www.codechef.com/users/codechaser |||
51+
||| https://github.com/code-chaser |||
52+
|---------------------------------------------------|
53+
*/

0 commit comments

Comments
 (0)