0% found this document useful (0 votes)
16 views14 pages

Student

The document outlines a student management system and a vehicle showroom system, each with their respective classes and functionalities. The student management system includes classes for managing students and courses, while the vehicle showroom system includes classes for vehicles, customers, and employees. Both systems provide methods for adding, displaying, and managing data related to their respective domains.

Uploaded by

tam.le2302220
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views14 pages

Student

The document outlines a student management system and a vehicle showroom system, each with their respective classes and functionalities. The student management system includes classes for managing students and courses, while the vehicle showroom system includes classes for vehicles, customers, and employees. Both systems provide methods for adding, displaying, and managing data related to their respective domains.

Uploaded by

tam.le2302220
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Student_Management

 Student.java:
package Student_Management;

import java.util.ArrayList;
import java.util.List;

public class Student {


private String name;
private List<Course> courses;

public Student(String name) {


this.name = name;
this.courses = new ArrayList<>();
}

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}

public List<Course> getCourses() {


return courses;
}

public void addCourse(Course course) {


courses.add(course);
}

public void removeCourse(String courseName) {


courses.removeIf(course -> course.getName().equalsIgnoreCase(courseName));
}

public double calculateAverageGrade() {


if (courses.isEmpty()) return 0.0;
double sum = 0;
for (Course course : courses) {
sum += course.getGrade();
}
return sum / courses.size();
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Student: ").append(name).append("\nCourses:\n");
for (Course course : courses) {
sb.append(course.toString()).append("\n");
}
sb.append("Average Grade: ").append(calculateAverageGrade());
return sb.toString();
}
}
 Course.java:
package Student_Management;

public class Course {


private String name;
private int credit;
private double grade;

public Course(String name, int credit, double grade) {


this.name = name;
this.credit = credit;
this.grade = grade;
}

public String getName() {


return name;
}

public int getCredit() {


return credit;
}

public double getGrade() {


return grade;
}

public void setGrade(double grade) {


this.grade = grade;
}
@Override
public String toString() {
return name + " (" + credit + " credits) - Grade: " + grade;
}
}
 Manager.java:
package Student_Management;

import Student_Management.Student;
import Student_Management.Course;
import java.util.ArrayList;
import java.util.List;

public class Manager {


private List<Student> students;

public Manager() {
students = new ArrayList<>();
}

public void addStudent(String name) {


students.add(new Student(name));
}

public String displayStudents() {


if (students.isEmpty()) {
return "No students available.";
}

StringBuilder sb = new StringBuilder();


for (Student student : students) {
sb.append(student.toString()).append("\n\n");
}
return sb.toString();
}

public void findStudentByName(String name) {


for (Student student : students) {
if (student.getName().equalsIgnoreCase(name)) {
System.out.println(student);
return;
}
}
System.out.println("Student not found.");
}

public double averageAllStudents() {


if (students.isEmpty()) return 0.0;

double totalAverage = 0;
for (Student student : students) {
totalAverage += student.calculateAverageGrade();
}
return totalAverage / students.size();
}
}
 Menu.java:
package Student_Management;
import java.util.Scanner;

public class Menu {


public void menu() {
Manager mng = new Manager();
Scanner input = new Scanner(System.in);

while (true) {
System.out.println("1. Add a student");
System.out.println("2. Display all students");
System.out.println("3. Search by student name");
System.out.println("4. Calculate average grade for all students");
System.out.println("5. Exit");
System.out.print("Choice: ");
String choice = input.next();
input.nextLine();

switch (choice) {
case "1":
System.out.print("Enter student name: ");
String name = input.nextLine();
mng.addStudent(name);
System.out.println("Student added.");
break;
case "2":
System.out.println(mng.displayStudents());
break;
case "3":
System.out.print("Enter student name: ");
String searchname = input.nextLine();
mng.findStudentByName(searchname);
break;
case "4":
System.out.println("Average grade for all students: " + mng.averageAllStudents());
break;
case "5":
System.out.println("Exiting...");
input.close();
return;
default:
System.out.println("Choice must be between 1 and 5.");
break;
}
System.out.println("===========================================");
}
}
}
 Main.java:
import Student_Management.Menu;

public class Main {


public static void main(String[] args) {
Menu menu = new Menu();
menu.menu();
}

SHOWROOM
 Car.java:
package Showroom;

public class Car extends Vehicle {


public static enum CarType {
Van, Sedan, SUV
}

private int seat_number;


private CarType type;

public Car(String manufacturer, double price, int made_year, String color,


int seat_number, CarType type) {
super(manufacturer, price, made_year, color, 10);
this.seat_number = seat_number;
this.type = type;
}

public int getSeat_number() {


return seat_number;
}

public void setSeat_number(int seat_number) {


this.seat_number = seat_number;
}

public CarType getType() {


return type;
}

public void setType(CarType type) {


this.type = type;
}

@Override
public String toString() {
return "Car{" +
super.toString() +
", seat_number=" + seat_number +
", type=" + type +
'}';
}

public String getFuelType() {


// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getFuelType'");
}
}

 Truck.java:
package Showroom;

public class Truck extends Vehicle {


private double weight;
private int valid_year;
public Truck(String manufacturer, double price, int made_year,
String color, double wieght, int valid_year) {
super(manufacturer, price, made_year, color, 5);
this.weight = wieght;
this.valid_year = valid_year;
}

public double getWeight() {


return weight;
}

public void setWeight(double weight) {


this.weight = weight;
}

public int getValid_year() {


return valid_year;
}

public void setValid_year(int valid_year) {


this.valid_year = valid_year;
}

@Override
public String toString() {
return "Truck{" +
super.toString() +
", weight=" + weight +
", valid_year=" + valid_year +
'}';
}

public String getFuelType() {


// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getFuelType'");
}

public String getTonnage() {


// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getTonnage'");
}
public String getWheels() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getWheels'");
}
}
 Vehicle.java:
package Showroom;

public class Vehicle {


private String manufacturer;
private double price;
private int made_year;
private String color;

private int tax;

public Vehicle(String manufacturer, double price, int made_year, String color, int tax) {
this.manufacturer = manufacturer;
this.price = price;
this.made_year = made_year;
this.color = color;
this.tax = tax;
}

public String getManufacturer() {


return manufacturer;
}

public void setManufacturer(String manufacturer) {


this.manufacturer = manufacturer;
}

public double getPrice() {


return price;
}

public void setPrice(double price) {


this.price = price;
}

public int getMade_year() {


return made_year;
}
public void setMade_year(int made_year) {
this.made_year = made_year;
}

public String getColor() {


return color;
}

public void setColor(String color) {


this.color = color;
}

public int getTax() {


return tax;
}

public void setTax(int tax) {


this.tax = tax;
}

@Override
public String toString() {
return "manufacturer='" + manufacturer + "'" +
", price=" + price +
", made_year=" + made_year +
", color='" + color + "'" +
", tax=" + tax;

public Object getObjType() {


// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getObjType'");
}

public Object getBrand() {


// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getBrand'");
}

public Object getYear() {


// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getYear'");
}

public Object getKm() {


// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getKm'");
}

public Object getDoors() {


// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getDoors'");
}

public Object getCarType() {


// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getCarType'");
}
}
 Customer.java:
package Showroom;

public class Customer {


public static enum IdentityType {
CCCD, GPKD, PASSPORT, GPLX
};

private String id;


private IdentityType id_type;

private String name;


private String address;
private String phone;

public Customer(String id, IdentityType id_type, String name, String address, String phone) {
this.id = id;
this.id_type = id_type;
this.name = name;
this.address = address;
this.phone = phone;
}

public Customer(String nextToken, double double1, int int1, String nextToken2, String
nextToken3) {
// TODO Auto-generated constructor stub
}

public String getId() {


return id;
}

public void setId(String id) {


this.id = id;
}

public IdentityType getId_type() {


return id_type;
}

public void setId_type(IdentityType id_type) {


this.id_type = id_type;
}

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}

public String getAddress() {


return address;
}

public void setAddress(String address) {


this.address = address;
}

public String getPhone() {


return phone;
}

public void setPhone(String phone) {


this.phone = phone;
}
@Override
public String toString() {
return "Customer{" +
"id='" + id + '\'' +
", id_type=" + id_type +
", name='" + name + '\'' +
", address='" + address + '\'' +
", phone='" + phone + '\'';
}

public Object getBudget() {


// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getBudget'");
}

public Object getAge() {


// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getAge'");
}

public Object getPhoneNumber() {


// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getPhoneNumber'");
}

public String getSalary() {


// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getSalary'");
}

public String getAssignedSaler() {


// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getAssignedSaler'");
}
}
 Employee.java:

package Showroom;

import java.util.Date;

public class Employee {


private String id;
private String name;
private Date start_date;

private double based_salary;

public Employee(String id, String name, Date start_date, double based_salary) {


this.id = id;
this.name = name;
this.start_date = start_date;
this.based_salary = based_salary;
}

public Employee(String managerName) {


// TODO Auto-generated constructor stub
}

public Employee(String id2, String name2) {


// TODO Auto-generated constructor stub
}

public String getId() {


return id;
}

public void setId(String id) {


this.id = id;
}

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}

public Date getStart_date() {


return start_date;
}

public void setStart_date(Date start_date) {


this.start_date = start_date;
}
public double getBased_salary() {
return based_salary;
}

public void setBased_salary(double based_salary) {


this.based_salary = based_salary;
}

@Override
public String toString() {
return "id='" + id + '\'' +
", name='" + name + '\'' +
", start_date=" + start_date +
", based_salary=" + based_salary;
}
}
 Main.java:
package Showroom;
import java.util.Scanner;
public class ClientProgram {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Nhập đường dẫn thư mục chứa file: ");
String folderPath = scanner.nextLine().trim();

DataManager dataManager = new DataManager();


dataManager.load(folderPath);

scanner.close();
}
}

You might also like