Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions src/main/kotlin/Courses.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class Courses constructor(var CourseName: String, var number_of_lectures: String,
var students: List<String>,var professor: String) {


fun numberOfStudents(): Int{

return students.size
}

fun assignProfessor(prof: Professors): Boolean{
prof.courses.forEach{
return it == CourseName
}

return false
}

fun professorName(): String{

return professor
}

fun enroll(student: Students): Boolean{
student.courses.forEach{
return it == CourseName
}

return false
}

fun courseInfo(): String{
return "\ncourse name: $CourseName\nNumber of lectures: $number_of_lectures\n" +
"Professor: $professor\nStudents: $students"
}

}
84 changes: 83 additions & 1 deletion src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,88 @@
import kotlin.random.Random

fun main(args: Array<String>) {

// write your code here
// initialize the students, professors and courses

val professor = Professors("Mohammed","Ahmed", listOf("Algorithms"),"055555555") // add professor
val student1 = Students("Ibrahim", "Alfaifi", listOf("Algorithms")) // add student
val course = Courses( "Algorithms", "12", listOf("Ibrahim Alfaifi","Ahmed Alfaifi"), "Mohammed Ahmed") // add professor
val student2 = Students("Ahmed", "Alfaifi", listOf("Data Structure")) // add another student





//---------------------------------------------------------------------------------//
// using the course class //

//check if this course has a teacher
if (!course.assignProfessor(professor)){
println("This professor is not teacher to this course")
course.professor = professor.fullName()
}else{
println("This course has already a professor")
}



//check if this student has enrolled in this course
if (!course.enroll(student1)){
println("This student has not enrolled in this course")
course.students = listOf(student1.fullName())
}else{
println("This student has already enrolled in this course")
}




//check if this student has enrolled in this course
if (!course.enroll(student2)){
println("This student has not enrolled in this course")
course.students = listOf(student2.fullName())
}else{
println("This student has already enrolled in this course")
}




// print the number of students in a course
println("Number of students in this course: ${course.numberOfStudents()}")

// print the professor name for a course
println("the professor for this course: ${course.professorName()}")

// print the course info
println("the course information: ${course.courseInfo()}")

println("-------------------------------------------------------------")




//-----------------------------------------------------------------------------------//
// using student class //


// print all students in this collage
println("All students in this collage:\n 1- ${student1.fullName()} \n 2- ${student2.fullName()}")

println("-------------------------------------------------------------")





//-----------------------------------------------------------------------------------//
// using professor class //


// print all professors in this collage
println("All professors in this collage:\n 1- ${professor.fullName()}")




}
10 changes: 10 additions & 0 deletions src/main/kotlin/Professors.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Professors (var firstName: String, var lastName: String,
var courses: List<String>, var telephone: String){


fun fullName(): String{

return "$firstName $lastName"
}

}
9 changes: 9 additions & 0 deletions src/main/kotlin/Students.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Students(var firstName: String, var lastName: String, var courses: List<String>) {

fun fullName(): String{

return "$firstName $lastName"
}


}