Created
December 23, 2021 13:08
-
-
Save Ranjana-Kambhammettu/60aeee22669c5de8a08e4380369a3bb3 to your computer and use it in GitHub Desktop.
Student Management System in Kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner | |
class Admin { | |
private val password: String = "123456" | |
private var markList: HashMap<String, Marks> = HashMap() | |
fun passwordCheck(check: String): Boolean{ | |
if (check==password) | |
return true | |
return false | |
} | |
private fun addStudentMark() { | |
println("Enter student name:") | |
val name= readLine().toString() | |
val read = Scanner(System.`in`) | |
println("Enter the Math mark") | |
val mathMark = read.nextDouble() | |
println("Enter the English mark") | |
val englishMark = read.nextDouble() | |
println("Enter the Science mark") | |
val scienceMark = read.nextDouble() | |
markList[name] = Marks(mathMark, englishMark, scienceMark) | |
} | |
private fun modifyStudentMark() { | |
val read = Scanner(System.`in`) | |
println("Enter student name:") | |
val nTemp= readLine().toString() | |
println("The menu: ") | |
println("1. Math mark") | |
println("2. English mark") | |
println("3. Science mark") | |
when(Integer.valueOf(readLine())){ | |
1 -> { println("Enter the new mark") | |
val mathMark = read.nextDouble() | |
val mTemp = markList[nTemp]?.let { it1 -> | |
Marks(mathMark, | |
it1.english, it1.science ) } | |
if (mTemp != null) { | |
markList[nTemp] = mTemp | |
} | |
} | |
2 -> {println("Enter the new mark") | |
val englishMark = read.nextDouble() | |
val mTemp = markList[nTemp]?.let { it1 -> | |
Marks(it1.math, | |
englishMark , it1.science ) } | |
if (mTemp != null) { | |
markList[nTemp] = mTemp | |
}} | |
3 -> {println("Enter the new mark") | |
val scienceMark = read.nextDouble() | |
val mTemp = markList[nTemp]?.let { it1 -> | |
Marks(it1.math, | |
it1.english, scienceMark ) } | |
if (mTemp != null) { | |
markList[nTemp] = mTemp | |
}} | |
else -> { | |
print("Wrong choice entered!") | |
} | |
} | |
} | |
fun searchStudentMark(nTemp: String): Marks { | |
return markList[nTemp]!! | |
} | |
fun admin() { | |
var ch='Y' | |
do | |
{ | |
println("The menu: ") | |
println("1. Add a student and their marks") | |
println("2. Modify student's marks") | |
println("3. Search student's marks") | |
println("Enter your choice: ") | |
val i = Integer.valueOf(readLine()) | |
when (i) { | |
1 -> { | |
addStudentMark() | |
} | |
2 -> { | |
modifyStudentMark() | |
} | |
3 -> {println("Enter student name:") | |
val nTemp= readLine().toString() | |
println(searchStudentMark(nTemp).toString())} | |
else -> { | |
print("Wrong choice entered!") | |
} | |
} | |
println("Do you want to continue? Enter Y if yes else press any key: ") | |
ch = (readLine()!![0]) | |
} while (ch=='Y') | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Important: I have used 3 files of Kotlin for this program, in case there is an issue, use this: https://github.com/Ranjana-Kambhammettu/student-management | |
import kotlin.text.*; | |
fun main() | |
{ | |
println("Hello World!") | |
var ch = 'Y' | |
val a = Admin() | |
do | |
{ | |
println("The menu: ") | |
println("1. Login as admin") | |
println("2. Login as student") | |
println("3. Exit") | |
println("Enter your choice: ") | |
val i = Integer.valueOf(readLine()) | |
when (i) { | |
1 -> { println("1. Enter password") | |
val check = readLine() | |
if (check?.let { a.passwordCheck(it) } ==true) | |
{ | |
a.admin() | |
} | |
else{ | |
println("You entered the wrong password!") | |
}} | |
2 -> { | |
println("Enter name: ") | |
val names = readLine() | |
if (names != null) { | |
println(a.searchStudentMark(names)) | |
} | |
} | |
3 -> {ch='N'} | |
else -> { | |
print("Wrong choice entered!") | |
} | |
} | |
println("Do you want to continue? Enter Y if yes else press any key: ") | |
ch = (readLine()!![0]) | |
} while (ch=='Y') | |
} | |
/* | |
Create a student management program with Kotlin, wherein a user can login as an admin(with appropriate credentials) | |
or as a student. | |
Let there be 3 subjects - (Math, English, Science). | |
The admin has the power to look at all the students' marks(Math,English,Science - Overall %) | |
and to modify those marks. | |
The students can just view their individual subject marks. | |
If admin modifies a particular subject marks for a given student, the overall percentage of the | |
student should change accordingly. */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Marks(var math: Double, var english: Double, var science: Double) { | |
private var percentage: Double = ( math + english + science ) / 3 | |
public override fun toString(): String { | |
return ("Math mark: "+math+" \nEnglish mark: "+english+" " + | |
"\nScience mark: "+science+" \nPercentage: "+percentage) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment