0% found this document useful (0 votes)
8 views2 pages

Oop 5 Code

The document is a Java program that manages student admissions for undergraduate and postgraduate courses. It collects student information, calculates fees based on course type and marks, applies scholarships or discounts, and displays the final payment along with the payment method. The program uses classes to structure data and functionality, allowing for multiple student entries and generating a report of their details.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Oop 5 Code

The document is a Java program that manages student admissions for undergraduate and postgraduate courses. It collects student information, calculates fees based on course type and marks, applies scholarships or discounts, and displays the final payment along with the payment method. The program uses classes to structure data and functionality, allowing for multiple student entries and generating a report of their details.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

Scanner;
import java.util.Vector;

class Course {
String course_1 = "UNDERGRADUATE";
String course_2 = "POSTGRADUATE";
double total_pay = 0.0;

String course;
int marks;
double scholarship;
int discount;
double fees;
double finalPayment;

Scanner sc = new Scanner(System.in);

void getdata() {
System.out.println("Enter course: ");
course = sc.nextLine().toUpperCase();

System.out.println("Enter marks: ");


marks = sc.nextInt();
sc.nextLine(); // Consume newline

if (course.equals(course_1)) {
fees = 5000.0;
discount = 0; // No discount for UG
scholarship = (marks > 85) ? 500.0 : 300.0;
finalPayment = fee_cal(fees, scholarship);
} else if (course.equals(course_2)) {
fees = 10000.0;
scholarship = 0.0; // No scholarship for PG....Dont use NULL
discount = (marks > 92) ? 1000 : 0;
finalPayment = fee_cal(fees, discount);
} else {
System.out.println("Invalid course!");
}
}

double fee_cal(double fees, double scholarship) {


return fees - scholarship;
}

double fee_cal(double fees, int discount) {


return fees - discount;
}
}

class Student extends Course {


String name;
String paymentMethod;
Scanner sc = new Scanner(System.in);

void getdata() {
System.out.println("Enter name: ");
name = sc.nextLine();
super.getdata();

System.out.println("Enter payment method (1. Credit Card 2. Bank Transfer 3. Wallet): ");
int choice = sc.nextInt();
switch (choice) {
case 1 -> paymentMethod = "Credit Card";
case 2 -> paymentMethod = "Bank Transfer";
case 3 -> paymentMethod = "Wallet";
default -> paymentMethod = "Unknown";
}
}

void display() {

System.out.println("Name: " + name);


System.out.println("Course Type: " + course);
System.out.println("Marks: " + marks);
System.out.println("Total Fees: $" + fees);

if (course.equals(course_1)) {
System.out.println("Scholarship: $" + scholarship);
} else {
System.out.println("Discount: $" + discount);
}
System.out.println("Final Payment: $" + finalPayment);
System.out.println("Payment Method: " + paymentMethod);
System.out.println("----------------------------");
}
}

public class Student_Management {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Vector<Student> students = new Vector<>(); // it is an vector of student type
Vector<StringBuffer> ID = new Vector<>();

System.out.println("Enter number of students: ");


int n = sc.nextInt();
sc.nextLine();

for (int i = 0; i < n; i++) {


System.out.println("\nEntering details for Student " + (i + 1) + ":");
Student student = new Student(); // This is an student object
StringBuffer id = new StringBuffer(); // Thsi an stringbuffer to store an unique idss
student.getdata();
if(student.course.equals("UNDERGRADUATE")){
id.append("UG_" + student.name + "_" + (i + 1));
}
else{
id.append("PG_" + student.name + "_" + (i + 1));
}
ID.add(id);
students.add(student); // adding an student object in an student vector
}

System.out.println("\nUniversity Admission Report:");


System.out.println("============================");

System.out.println("\nStudent Details:");
System.out.println("----------------------------");

for (int i = 0; i < students.size(); i++) {


System.out.println(ID.get(i));
students.get(i).display(); // hree the get used to acces each object stored in it
}

}
}

You might also like