From 2a97c1f104b8770b2d829679fccf0264204d01e9 Mon Sep 17 00:00:00 2001 From: Aadit Agrawal Date: Sat, 14 Sep 2024 01:53:30 +0530 Subject: [PATCH] Add OOP/Java/Lab/Week6/Student/StudentProgram.java --- .../Lab/Week6/Student/StudentProgram.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 OOP/Java/Lab/Week6/Student/StudentProgram.java diff --git a/OOP/Java/Lab/Week6/Student/StudentProgram.java b/OOP/Java/Lab/Week6/Student/StudentProgram.java new file mode 100644 index 0000000..23558d6 --- /dev/null +++ b/OOP/Java/Lab/Week6/Student/StudentProgram.java @@ -0,0 +1,66 @@ +class Student { + + int regNo; + String name; + int age; + + public Student(int regNo, String name, int age) { + this.regNo = regNo; + this.name = name; + this.age = age; + } + + public void displayDetails() { + System.out.println( + "Reg No: " + regNo + ", Name: " + name + ", Age: " + age + ); + } +} + +class UG extends Student { + + int semester; + double fees; + + public UG(int regNo, String name, int age, int semester, double fees) { + super(regNo, name, age); + this.semester = semester; + this.fees = fees; + } + + public void displayDetails() { + super.displayDetails(); + System.out.println("Semester: " + semester + ", Fees: " + fees); + } +} + +class PG extends Student { + + int semester; + double fees; + + public PG(int regNo, String name, int age, int semester, double fees) { + super(regNo, name, age); + this.semester = semester; + this.fees = fees; + } + + public void displayDetails() { + super.displayDetails(); + System.out.println("Semester: " + semester + ", Fees: " + fees); + } +} + +public class StudentProgram { + + public static void main(String[] args) { + UG ugStudent = new UG(230901010, "Saarthak Singhal", 20, 3, 500000.0); + PG pgStudent = new PG(230920020, "Aarav Chirag Shah", 25, 2, 350000.0); + + System.out.println("UG Student Details:"); + ugStudent.displayDetails(); + + System.out.println("\nPG Student Details:"); + pgStudent.displayDetails(); + } +}