mirror of
https://github.com/Manoj-HV30/OOPS-lab-codes.git
synced 2026-05-16 19:35:25 +00:00
Added Java lab programs
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
class Student {
|
||||
|
||||
private int m1, m2, m3;
|
||||
|
||||
// Static counter to track enrolled students
|
||||
static int studentCount = 0;
|
||||
|
||||
// Static block to display welcome message
|
||||
static {
|
||||
System.out.println("Welcome to University Enrollment System");
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Student(int m1, int m2, int m3) {
|
||||
this.m1 = m1;
|
||||
this.m2 = m2;
|
||||
this.m3 = m3;
|
||||
studentCount++;
|
||||
}
|
||||
|
||||
// Non-static method to compute average of best two marks
|
||||
void displayAverage() {
|
||||
int bestTwoSum = m1 + m2 + m3 - Math.min(m1, Math.min(m2, m3));
|
||||
double average = bestTwoSum / 2.0;
|
||||
System.out.println("Average of best two marks: " + average);
|
||||
}
|
||||
|
||||
// Static method to display total enrolled students
|
||||
static void displayTotalStudents() {
|
||||
System.out.println("Total students enrolled: " + studentCount);
|
||||
}
|
||||
}
|
||||
|
||||
public class UniversityEnrollment {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
System.out.print("Enter number of students to enroll: ");
|
||||
int n = sc.nextInt();
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
System.out.println("\nEnter marks for Student " + i);
|
||||
|
||||
System.out.print("Mark 1: ");
|
||||
int m1 = sc.nextInt();
|
||||
|
||||
System.out.print("Mark 2: ");
|
||||
int m2 = sc.nextInt();
|
||||
|
||||
System.out.print("Mark 3: ");
|
||||
int m3 = sc.nextInt();
|
||||
|
||||
Student s = new Student(m1, m2, m3);
|
||||
s.displayAverage();
|
||||
}
|
||||
|
||||
// Display total enrolled students
|
||||
Student.displayTotalStudents();
|
||||
|
||||
sc.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user