Commit a699f063 authored by Pouria Shirzad's avatar Pouria Shirzad

commit

parents
Pipeline #5817 canceled with stages
package com.company;
public class Department {
private Lab[] labs;
private String name;
private int amount;
private int currentAmount;
/**
* create department
* @param amount = how many lab can be cerated in 1 Department
* @param name = name of Department
*/
public Department(int amount , String name){
this.amount = amount;
this.name = name;
this.labs = new Lab[amount];
this.currentAmount = 0;
}
public void create(Lab lab1) {
if (currentAmount < amount) {
this.labs[currentAmount] = lab1;
this.currentAmount++;
} else {
System.out.println(" Department is full!!! u cant add more lab : ");
lab1.print();
System.out.println(" Max capacity : "+ amount + "Labs");
}
}
public void print(){
System.out.println(labs[0].getDay() + " : ");
System.out.println("Department " + this.name + " : ");
System.out.println("amount of class today is : " + this.amount);
for (int j=0;j<currentAmount;j++){
labs[j].print();
}
}
/**
*
* @return labs field
*/
public Lab[] getLabs() {return labs;}
/**
*
* @param labss set labs
*/
public void setLabs(Lab[] labss){labs = labss;}
/**
*
* @return name
*/
public String getName(){return name;}
/**
*
* @param name1 set name
*/
public void setName(String name1){name = name1;}
/**
*
* @return amount field
*/
public int getAmount(){return amount;}
/**
*
* @param amount1 set amount
*/
public void setAmount(int amount1){amount = amount1;}
}
package com.company;
/**
* The Student class represents a student in a student administration system.
* @author Mr.GHOST
* @since 1399.12.20
*/
import javax.swing.plaf.basic.BasicTreeUI;
public class Lab {
private Student[] students;
private String nameClass;
private int avg;
private String day;
private int capacity;
private int currentSize;
/**
* create Lab
* @param capacity
* @param day
*/
public Lab(int capacity , String day , String nameClass){
this.capacity = capacity;
this.currentSize = 0;
this.day = day;
this.students = new Student[capacity];
this.nameClass = nameClass;
}
/**
*
* add a new student (if it has enough space)
*/
public void enrollStudent(Student std){
if (currentSize<capacity){
this.students[currentSize] = std;
this.currentSize++;
}
else{
System.out.printf(" Lab is full!!! u cant add : " );
std.print();
System.out.printf(" Max capacity : %d Students",capacity);
System.out.println();
}
}
/**
* print stds details
*/
public void print(){
System.out.println(this.nameClass + " class : ");
for(int i=0;i<currentSize;i++) {
System.out.printf("%d)",i+1);
System.out.println(" std fName :" + students[i].getFirstName() + ", std lName " + students[i].getLastName() + ", std id : " + students[i].getId() + ", std grade : " + students[i].getGrade() );
}
System.out.println("avg is :" + this.getAvg());
}
/**
*
* @return students field
*/
public Student[] getStudents(){
return students;
}
/**
*
* @param std set student
*/
public void setStudents(Student[] std){
students = std;
}
/**
*
* @return avg field
*/
public int getAvg(){
int sum=0;
for (int j=0;j<currentSize;j++){
sum += students[j].getGrade();
}
avg = sum / currentSize;
return avg;
}
/**
*
* @return day field
*/
public String getDay(){
return day;
}
/**
*
* @param day set day
*/
public void setDay(String day) {
this.day = day;
}
/**
*
* @return capacity field
*/
public int getCapacity() {
return capacity;
}
/**
*
* @param capacity set capacity
*/
public void setCapacity(int capacity) {
this.capacity = capacity;
}
/**
*
* @return nameclass
*/
public String getNameClass(){return nameClass;}
/**
*
* @param nameClass set name of class
*/
public void setNameClass(String nameClass){this.nameClass = nameClass;}
}
package com.company;
public class Main {
public static void main(String[] args) {
System.out.println("allo");
// write your code here
}
}
package com.company;
import java.util.Scanner;
public class Run {
public static void main(String[] args) {
Student std1 = new Student("Ali","Karimi","90991330");
Student std2 = new Student("Ashkan","Khorshidi","12345678");
Student std3 = new Student("Amir","Ghalenoi","54545894");
// std1.print();
std1.setGrade(8);
// std1.print();
//
// std2.print();
std2.setGrade(20);
// std2.print();
//
// std3.print();
std3.setGrade(14);
// std3.print();
Student std4 = new Student("Pouria","Shirzad","9931032");
Student std5 = new Student("Mahdi","Taremi","90921330");
Student std6 = new Student("Rostam","Heydari","98365025");
Student std7 = new Student("Omid","Rajabi","95668695");
Student std8 = new Student("Sardar","Azmun","99999999");
std4.setGrade(20);
std5.setGrade(9);
std6.setGrade(15);
std7.setGrade(12);
std8.setGrade(20);
Lab riazi = new Lab(5,"shanbe","rizai");
riazi.enrollStudent(std1);
riazi.enrollStudent(std2);
riazi.enrollStudent(std3);
riazi.enrollStudent(std4);
riazi.enrollStudent(std5);
// System.out.println(riazi.getDay() + " : ");
// riazi.print();
Lab fizik = new Lab(6,"shanbe","fizik");
std2.setGrade(5);
std6.setGrade(18);
std7.setGrade(9);
std4.setGrade(14);
std5.setGrade(16);
fizik.enrollStudent(std2);
fizik.enrollStudent(std6);
fizik.enrollStudent(std7);
fizik.enrollStudent(std4);
fizik.enrollStudent(std5);
// fizik.print();
Department computer = new Department(2,"aut");
computer.create(riazi);
computer.create(fizik);
computer.print();
}
}
package com.company;
import javax.swing.plaf.metal.MetalButtonUI;
public class Student {
// students first name
private String firstName;
// students last name
private String lastName;
// students id
private String id;
// student grade
private int grade;
/**
*create a new students
* @param fName firstName
* @param lName firstName
* @param sID id
*/
public Student(String fName , String lName , String sID){
firstName = fName;
lastName = lName;
id = sID;
grade = 0;
}
/**
* get the first name of student
* @return firstName field
*/
public String getFirstName(){
return firstName;
}
/**
*
* @param fName set first name of student
*/
public void setFirstName(String fName) {
firstName = fName;
}
/**
* get the las name of student
* @return lastName field
*/
public String getLastName(){
return lastName;
}
/**
*
* @param lName set last name of student
*/
public void setLastName(String lName){
lastName = lName;
}
/**
* get the id
* @return id field
*/
public String getId(){
return id;
}
/**
*
* @param sID set id of student
*/
public void setId(String sID){
id = sID;
}
/**
*
* @return grade field
*/
public int getGrade() { return grade; }
/**
*
* @param fGrade set field grade
*/
public void setGrade(int fGrade){
grade = fGrade;
}
/**
* print the student first name + last name + id + grade
*/
public void print(){
System.out.println(firstName + " " + lastName + ", student id : " + id + " , grade :" + grade);
}
}
package com.company;
public class person {
public person(String personName , int howOld){
name = personName;
age = howOld;
}
public static void main(String arg[]){
person ali = new person("Ali" , 18);
System.out.println(ali.name + " is the name and his age is :" + ali.age);
}
private String name;
private int age;
}
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