Commit 94e5a735 authored by aliasad's avatar aliasad

HW2

parent cd6d252e
<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_1_8" default="true" project-jdk-name="1.8" 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$/HW2_factulity.iml" filepath="$PROJECT_DIR$/HW2_factulity.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="ChangeListManager">
<list default="true" id="f4f34552-d0b4-4a28-a610-ef0f0940abf4" name="Default Changelist" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="ProjectId" id="1YZAuJjUCfMwOemCFOHfqoxpe95" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showExcludedFiles" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" />
</component>
<component name="RunManager">
<configuration name="Main" type="Application" factoryName="Application" temporary="true">
<option name="MAIN_CLASS_NAME" value="Main" />
<module name="HW2_factulity" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
<RunnerSettings RunnerId="Run" />
<ConfigurationWrapper RunnerId="Run" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.Main" />
</list>
</recent_temporary>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="f4f34552-d0b4-4a28-a610-ef0f0940abf4" name="Default Changelist" comment="" />
<created>1583139964764</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1583139964764</updated>
<workItem from="1583139971110" duration="4027000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="WindowStateProjectService">
<state width="1237" height="486" key="GridCell.Tab.0.bottom" timestamp="1583148095452">
<screen x="0" y="0" width="1280" height="680" />
</state>
<state width="1237" height="486" key="GridCell.Tab.0.bottom/0.0.1280.680@0.0.1280.680" timestamp="1583148095452" />
<state width="1237" height="486" key="GridCell.Tab.0.center" timestamp="1583148095452">
<screen x="0" y="0" width="1280" height="680" />
</state>
<state width="1237" height="486" key="GridCell.Tab.0.center/0.0.1280.680@0.0.1280.680" timestamp="1583148095452" />
<state width="1237" height="486" key="GridCell.Tab.0.left" timestamp="1583148095452">
<screen x="0" y="0" width="1280" height="680" />
</state>
<state width="1237" height="486" key="GridCell.Tab.0.left/0.0.1280.680@0.0.1280.680" timestamp="1583148095452" />
<state width="1237" height="486" key="GridCell.Tab.0.right" timestamp="1583148095452">
<screen x="0" y="0" width="1280" height="680" />
</state>
<state width="1237" height="486" key="GridCell.Tab.0.right/0.0.1280.680@0.0.1280.680" timestamp="1583148095452" />
<state x="337" y="166" key="com.intellij.ide.util.TipDialog" timestamp="1583139971121">
<screen x="0" y="0" width="1280" height="680" />
</state>
<state x="337" y="166" key="com.intellij.ide.util.TipDialog/0.0.1280.680@0.0.1280.680" timestamp="1583139971121" />
</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>
import java.util.function.DoubleToIntFunction;
/**
* it provides information of students of an indivisual Class
* @author AliAsad
* @version 1.0
*/
public class Class {
// each student is an object these objects are stored here
private Student[] students;
// average of students grades
private double avg;
// day of Class
private String day;
// capacity of Class
private int capacity;
// the filled capacity of Class
private int currentSize ;
private String master ;
private String className;
/**
* @param cap the capacity of Class
* @param d the day of Class
*/
public Class(int cap, String d,String master,String className) {
capacity = cap;
day = d;
students = new Student[capacity];
this.master = master ;
this.className = className;
currentSize = 0 ;
}
/**
* gives student and adds to students array
* @param std the student that will be added
*/
public void enrollStudent(Student std) {
if (currentSize < capacity) {
students[currentSize] = std;
currentSize++;
} else {
System.out.println("Lab is full!!!");
}
}
/**
* prints the Class information
*/
public void print() {
calculateAvg();
System.out.println("Information of class "+getClassName());
System.out.println("Master : "+ getMaster()+"\n"+"Students :");
for (int i = 0 ; i < currentSize ;i++)
System.out.println(students[i].getFirstName() +" "+ students[i].getLastName()+", student ID: "
+ students[i].getId() + ", grade: " + students[i].getGrade());
System.out.println("avg :" + avg);
}
/**
* get the students array
* @return students array
*/
public Student[] getStudents() {
return students;
}
/**
* set the students
* @param students the new students that will be added
*/
public void setStudents(Student[] students) {
this.students = students;
}
/**
* get the avg
* @return avg
*/
public double getAvg() {
return avg;
}
/**
* calculate the avg of students grades
*/
public void calculateAvg() {
int sum = 0 ;
for (int i = 0 ; i < currentSize ; i++ )
sum += students[i].getGrade();
avg = sum / currentSize;
}
/**
* get the name of Class
* @return className
*/
public String getClassName() {
return className;
}
/**
* set the name of Class
* @param className
*/
public void setClassName(String className) {
this.className = className;
}
/**
* get the master of Class
* @return master
*/
public String getMaster() {
return master;
}
/**
* set the master of Class
* @param master new master
*/
public void setMaster(String master) {
this.master = master;
}
/**
* get the day of Class
* @return day
*/
public String getDay() {
return day;
}
/**
* set the day of Class
* @param day new day
*/
public void setDay(String day) {
this.day = day;
}
/**
* get the capacity of Class
* @return capacity
*/
public int getCapacity() {
return capacity;
}
/**
* set the Class capacity
* @param capacity the new capacity
*/
public void setCapacity(int capacity) {
this.capacity = capacity;
}
}
\ No newline at end of file
public class Main {
public static void main(String[] args) {
Master master1 = new Master("Roya","Khajesalehi","1234567");
Master master2 = new Master("Mehran","Fallah","7654321");
Master master3 = new Master("Ali","Asad","9831004");
master1.setRoomNum(120);
master2.setRoomNum(220);
master3.setRoomNum(20);
System.out.println("Masters info :");
master1.print();
master2.print();
master3.print();
System.out.println("\n\n");
Student std1 = new Student("Ehsan","Edalat", "9031066");
Student std2 = new Student("Seyed", "Ahmadpanah", "9031806");
Student std3 = new Student("Ahmad", "Asadi", "9031054");
Student std4 = new Student("Ehsan","Ahmadpanah", "9031001");
Student std5 = new Student("Ahmad", "Edalat", "9031804");
Student std6 = new Student("Seyed", "Asadi", "9031004");
Student std7 = new Student("Ehsan","Asadi", "9031009");
Student std8 = new Student("Ahmad", "Ahmadpanah", "9031810");
Student std9 = new Student("Ehsan", "Asadi", "9031034");
std1.setGrade(15);
std2.setGrade(20);
std3.setGrade(17);
std4.setGrade(16);
std5.setGrade(12);
std6.setGrade(13);
std7.setGrade(18);
std8.setGrade(19);
std9.setGrade(20);
Class lab1 = new Class( 20 , "Saturday","Khajesalehi","AP lab1");
Class DM1 = new Class( 50 , "Sunday","Fallah","DM 1");
Class OS1 = new Class( 30 , "Wednesday","Asad","OS 1");
lab1.enrollStudent(std1);
lab1.enrollStudent(std2);
lab1.enrollStudent(std3);
lab1.enrollStudent(std4);
lab1.enrollStudent(std5);
DM1.enrollStudent(std1);
DM1.enrollStudent(std4);
DM1.enrollStudent(std7);
DM1.enrollStudent(std9);
DM1.enrollStudent(std8);
OS1.enrollStudent(std6);
OS1.enrollStudent(std8);
OS1.enrollStudent(std4);
OS1.enrollStudent(std1);
OS1.enrollStudent(std2);
lab1.print();
System.out.println("\n\n");
OS1.print();
System.out.println("\n\n");
DM1.print();
}
}
import java.util.*;
/**
* The Master class represents a Master in a Master
administration system.
* It holds the Master details relevant in our context.
*
* @author AliAsad
* @version 1.0
*/
public class Master {
// the Master’s first name
private String firstName;
// the Master’s last name
private String lastName;
// the Master ID
private String id;
//the room number of the Master
private int roomNum;
/**
* Create a new Master with a given name and ID number.
*
* @param fName first name of Master
* @param lname last name of Master
* @param mID Master ID
*/
public Master(String fName, String lname, String mID){
firstName = fName;
lastName = lname;
id = mID;
}
/**
* set the roomNum of Master
* @param newRoomNum new roomNum of the Master
*/
public void setRoomNum(int newRoomNum){
if(newRoomNum <= 500 && newRoomNum >= 0 )
roomNum = newRoomNum;
}
/**
* get the RoomNum of Master
* @return RoomNum field
*/
public int getRoomNum(){
return roomNum;
}
/**
* set the id of Master
* @param newId new id of Master
*/
public void setId(String newId){
id = newId;
}
/**
* get the ID of Master
* @return id field
*/
public String getId(){
return id;
}
/**
* get the firstName of Master
* @return firstName field
*/
public String getFirstName() {
return firstName;
}
/**
* get the lastName of Master
* @return lastName field
*/
public String getLastName() {
return lastName;
}
/**
* set the firstName of Master
* @param fName first name of Master
*/
public void setFirstName(String fName) {
firstName = fName;
}
/**
* prints the information of each Master
*/
public void print() {
System.out.println(lastName + ", Master ID: "
+ id + ", RoomNumber: " + roomNum);
}
}
\ No newline at end of file
import java.util.*;
/**
* The Student class represents a student in a student
administration system.
* It holds the student details relevant in our context.
*
* @author AliAsad
* @version 1.0
*/
public class Student {
// the student’s first name
private String firstName;
// the student’s last name
private String lastName;
// the student ID
private String id;
//the grade
private int grade;
/**
* Create a new student with a given name and ID number.
*
* @param fName first name of student
* @param lname last name of student
* @param sID student ID
*/
public Student(String fName, String lname, String sID){
firstName = fName;
lastName = lname;
id = sID;
}
/**
* set the grade of student
* @param newGrade new grade of the student
*/
public void setGrade(int newGrade){
if(newGrade <= 20 && newGrade >= 0 )
grade = newGrade;
}
/**
* get the grade of student
* @return grade field
*/
public int getGrade(){
return grade;
}
/**
* set the id of student
* @param newId new id of student
*/
public void setId(String newId){
id = newId;
}
/**
* get the ID of student
* @return id field
*/
public String getId(){
return id;
}
/**
* get the firstName of student
* @return firstName field
*/
public String getFirstName() {
return firstName;
}
/**
* get the lastName of student
* @return lastName field
*/
public String getLastName() {
return lastName;
}
/**
* set the firstName of student
* @param fName first name of student
*/
public void setFirstName(String fName) {
firstName = fName;
}
/**
* prints the information of each student
*/
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