Commit d675003e authored by Roholla's avatar Roholla

initial commit

parents
Pipeline #2056 canceled with stages
public class Main {
/**
* The Student class represents a student in a student administration system.
* It holds the student details relevant in our context.
*
* @author Roholla
* @version 0.0
*/
public static class Student {
/**
* student’s first name
*/
private String firstName;
/**
* student’s last name
*/
private String lastName;
/**
* student's ID
*/
private String id;
/**
* student's grade
*/
private int grade;
/**
* Create a new student with a given name and ID number.
*
* @param fName student's first name
* @param lName student's last name
* @param sID student's ID
*/
public Student(String fName, String lName, String sID) {
firstName = fName;
lastName = lName;
id = sID;
grade = 0;
}
/**
* @return student's first name
*/
public String getFirstName() {
return firstName;
}
/**
* @return student's last name
*/
public String getLastName() {
return lastName;
}
/**
* @return student's id
*/
public String getId() {
return id;
}
/**
* @return student's grade
*/
public int getGrade() {
return grade;
}
/**
* @param firstName student's first name to be set
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
* @param lastName student's last name to be set
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}
/**
* @param id student's id to be set
*/
public void setId(String id) {
this.id = id;
}
/**
* @param grade student's grade to be set
*/
public void setGrade(int grade) {
this.grade = grade;
}
/**
* Print the student’s last name and ID number to the output terminal.
*/
public void print() {
System.out.println(lastName + ", student ID: " + id + ", grade: " + grade);
}
}
public static class Lab {
private Student[] students;
private int avg;
private String day;
private int capacity;
private int currentSize;
public Lab(int capacity, String day) {
students = new Student[capacity];
this.capacity = capacity;
this.day = day;
currentSize = 0;
avg = 0;
}
public void enrollStudent(Student std) {
if (currentSize < capacity)
students[currentSize++] = std;
else
System.out.println("Lab is full!!!");
}
public void print() {
for (int i = 0; i < currentSize; i++) {
System.out.print((i + 1) + ". ");
students[i].print();
}
}
public Student[] getStudents() {
return students;
}
public void setStudents(Student[] students) {
for(Student si: students)
enrollStudent(si);
}
public int getAvg() {
return avg;
}
public void calculateAvg() {
int sum = 0;
for(int i = 0; i < currentSize; i++)
sum += students[i].getGrade();
avg = sum / currentSize;
}
public String getDay() {
return day;
}
public void setDay(String day) {
this.day = day;
}
public int getCapacity() {
return capacity;
}
public void setCapacity(int capacity) {
this.capacity = capacity;
}
}
}
public class Run {
public static void main(String[] args) {
Main.Student std1 = new Main.Student("Ehsan","Edalat", "9031066");
Main.Student std2 = new Main.Student("Seyed", "Ahmadpanah", "9031806");
Main.Student std3 = new Main.Student("Ahmad", "Asadi", "9031054");
std1.setGrade(15);
std2.setGrade(11);
std3.setFirstName("HamidReza");
Main.Student[] students = {std1, std2, std3};
Main.Lab lab = new Main.Lab(3, "MON");
lab.setStudents(students);
lab.print();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment