Commit c749b907 authored by saba-ramezani's avatar saba-ramezani

final commit

parents
Pipeline #2028 failed with stages
# Default ignored files
/workspace.xml
\ No newline at end of file
<html>Simple <b>Java</b> application that includes a class with <code>main()</code> method</html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectKey">
<option name="state" value="project://e2804f05-5315-4fc6-a121-c522a6c26470" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/sesion2.iml" filepath="$PROJECT_DIR$/sesion2.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<template>
<input-field default="com.company">IJ_BASE_PACKAGE</input-field>
</template>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
package com.company;
public class Lab{
private Student[] students;
private int avg;
private int capacity;
private int currentSize;
private String day;
public Lab(int cap,String d){
students = new Student[cap];
avg = 0;
capacity = cap;
day = d;
currentSize = 0;
}
public void enrollStudent(Student std){
if (currentSize < capacity){
students[currentSize] = std ;
currentSize++;
}
else
System.out.println("lab is full!");
}
public Student[] getStudents(){
return students;
}
public void setStudents(Student[] stds){
students = stds;
}
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 d){
day = d;
}
public int getCapacity(){
return capacity;
}
public void setCapacity(int cap){
capacity = cap;
}
public void print(){
for (int i=0 ; i<currentSize ; i++){
System.out.println("std fname: " + students[i].getFirstName()+ " std id:" + students[i].getId() + " std grade:"+ students[i].getGrade());
}
System.out.println("lab avg: " + avg);
}
}
package com.company;
public class Main{
public static void main(String[] args){
Student std1 = new Student("ehsan","edalat","9031066");
std1.setGrade(16);
Student std2 = new Student("seyed","ahmadpanah","9031806");
std2.setGrade(12);
Student std3 = new Student("saba","ramezani","9831030");
std3.setGrade(14);
Lab l = new Lab(5,"s");
l.enrollStudent(std1);
l.enrollStudent(std2);
l.enrollStudent(std3);
l.calculateAvg();
l.print();
}
}
package com.company;
public class Student{
private String firstName;
private String lastName;
private String id;
private int grade;
public Student(String fName,String lName,String sID){
firstName = fName;
lastName = lName;
id = sID;
grade = 0;
}
public String getFirstName(){
return firstName;
}
public void setFirstName(String fName){
firstName = fName;
}
public String getLastName(){
return lastName;
}
public void setLastName(String lName){
lastName = lName;
}
public String getId(){
return id;
}
public void setId(String sID){
id = sID;
}
public int getGrade(){
return grade;
}
public void setGrade(int stdgrade){
grade = stdgrade;
}
public void print(){
System.out.println(lastName + ", student id: " + id + ", grade: " + grade);
}
}
\ No newline at end of file
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