Commit ef49f3a2 authored by 9731001's avatar 9731001

lab-2

parents
Pipeline #605 failed with stages
package com.company;
public class Lab {
private int dayOfTheWeek;
private int currenCapacity = 0 ;
private int capacity;
Student [] students;
public Lab(int capacity , int dayOfTheWeek){
this.capacity = capacity;
students = new Student[capacity];
}
public void enrollStudent(Student std){
if(currenCapacity<capacity){
students[currenCapacity] = std;
currenCapacity++;
}
}
public float getAverage(){
int i;
float sum = 0;
for(i=0;i<capacity;i++){
sum = sum + students[i].getGrade();
}
float m = sum/capacity;
return m;
}
}
package com.company;
public class Main {
public static void main(String[] args) {
Student s1 = new Student("Fatemeh" , "Ahmadzadeh" , "9731001");
s1.setGrade(17);
if(s1.getFirstName()=="Fatemeh");
System.out.println("true");
Student s2 = new Student("Zahra" , "Ahmadzadeh" , "9731010");
s2.setGrade(18);
Lab test1 = new Lab(2, 1);
test1.enrollStudent(s1);
test1.enrollStudent(s2);
float miangin = test1.getAverage();
System.out.println(miangin);
}
}
package com.company;
public class Student {
private String firstName;
private String lastName;
private String studentNo;
private float grade;
public void setFirstName(String firstName){
this.firstName = firstName;
}
public void setLastName(String lastName){
this.lastName = lastName;
}
public void setStudentNO(String studentNo){
this.studentNo = studentNo;
}
public void setGrade(float grade){
this.grade = grade;
}
public Student(String firstName,String lastName,String studentNo){}
public String getFirstName(){
return "";
}
public float getGrade(){
return grade;
}
}
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