Created
September 2, 2015 05:53
-
-
Save xXFracXx/54a7f15eed0750fd70c7 to your computer and use it in GitHub Desktop.
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.*; | |
import static java.lang.System.out; | |
class Student { | |
int RegNumber; | |
String FullName; | |
GregorianCalendar Date; | |
short Semester; | |
float GPA, CGPA; | |
public static int count = 1; | |
Student () { | |
RegNumber = 0; | |
FullName = new String(""); | |
Date = new GregorianCalendar(); | |
Semester = 0; | |
GPA = 0.0f; | |
CGPA = 0.0f; | |
} | |
Student (int RN, String FN, GregorianCalendar DT, short SM, float G, float CG) { | |
RegNumber = RN; | |
FullName = new String(FN); | |
Date = DT; | |
Semester = SM; | |
GPA = G; | |
CGPA = CG; | |
} | |
Student (Student tmp) { | |
RegNumber = tmp.RegNumber; | |
FullName = new String(tmp.FullName); | |
Date = tmp.Date; | |
Semester = tmp.Semester; | |
GPA = tmp.GPA; | |
CGPA = tmp.CGPA; | |
} | |
void display(Student tmp) { | |
out.println("Student #" + tmp.RegNumber + " Details: "); | |
out.println(); | |
out.println("Registeration Number - " + tmp.RegNumber); | |
out.println("Full Name - " + tmp.FullName); | |
out.println("Date of Joining - " + tmp.Date); | |
out.println("Semester - " + tmp.Semester); | |
out.println("GPA - " + tmp.GPA); | |
out.println("CGPA - " + tmp.CGPA); | |
out.println(); | |
} | |
void setDateNRegNum(Student tmp) { | |
Calendar calendar = new GregorianCalendar(); | |
int year = calendar.get(Calendar.YEAR); | |
int month = calendar.get(Calendar.MONTH); | |
int day = calendar.get(Calendar.DAY_OF_MONTH); | |
tmp.Date = new GregorianCalendar(day, month, year); | |
tmp.RegNumber = year % 10 * 100; | |
year /= 10; | |
tmp.RegNumber += year % 10 * 1000; | |
tmp.RegNumber += tmp.count; | |
tmp.count++; | |
} | |
static void sortSem(Student[] s) { | |
Student stemp = new Student(); | |
for(int i = 0; i < 5; i++) { | |
int index = i; | |
for (int j = i + 1; j < 5; j++) | |
if (s[j].Semester < s[index].Semester) | |
index = j; | |
stemp = s[index]; | |
s[index] = s[i]; | |
s[i] = stemp; | |
} | |
} | |
static void sortCgpa(Student[] s) { | |
Student stemp = new Student(); | |
for(int i = 0; i < 5; i++) { | |
int index = i; | |
for (int j = i + 1; j < 5; j++) | |
if (s[j].CGPA < s[index].CGPA) | |
index = j; | |
stemp = s[index]; | |
s[index] = s[i]; | |
s[i] = stemp; | |
} | |
} | |
static void sortName(Student[] s) { | |
Student stemp = new Student(); | |
for(int i = 0; i < 5; i++) { | |
int index = i; | |
for (int j = i + 1; j < 5; j++) | |
if (((s[j].FullName).compareTo(s[index].FullName)) < 0) | |
index = j; | |
stemp = s[index]; | |
s[index] = s[i]; | |
s[i] = stemp; | |
} | |
} | |
} | |
class StudentDemo { | |
public static void main (String args[]) { | |
clrScr(); | |
Scanner in = new Scanner(System.in); | |
int opt, N, i; | |
String b = "\033[1m", ub = "\033[0m"; | |
out.print("Enter number of students: "); | |
N = in.nextInt(); | |
out.println(); | |
Student []stud = new Student[N]; | |
do { | |
out.println(b + " --- STUDENT DATABASE --- " + ub); | |
out.println(); | |
out.println("1. Input Student Data"); | |
out.println("2. Display Student Data"); | |
out.println("3. Sort [Semester]"); | |
out.println("4. Sort [CGPA]"); | |
out.println("5. Sort [Name]"); | |
out.println("6. Search [Character]"); | |
out.println("7. Search [Sub String]"); | |
out.println("8. Convert to Initials"); | |
out.println("9. Exit"); | |
out.println(); | |
out.print("Option : "); | |
opt = in.nextInt(); | |
out.println(); | |
switch (opt) { | |
case 1: clrScr(); | |
for(i = 0; i < N; i++) { | |
out.println(b + "Enter Student #" + (i+1) + " Data: " + ub); | |
out.println(); | |
stud[i] = new Student(); | |
stud[i].setDateNRegNum(stud[i]); | |
out.println("Registeration Number - " + stud[i].RegNumber); | |
out.print("Full Name - "); | |
stud[i].FullName = in.next(); | |
out.println("Date of Joining - " + stud[i].Date.get(Calendar.DAY_OF_MONTH) + "/" + stud[i].Date.get(Calendar.MONTH) + "/" + stud[i].Date.get(Calendar.YEAR)); | |
out.print("Semester - "); | |
stud[i].Semester = in.nextShort(); | |
out.print("GPA - "); | |
stud[i].GPA = in.nextInt(); | |
out.print("CGPA - "); | |
stud[i].CGPA = in.nextInt(); | |
clrScr(); | |
} | |
out.println(); | |
out.println(b + "All data entered!" + ub); | |
pressAnyKeyToContinue(); | |
clrScr(); | |
break; | |
case 2: clrScr(); | |
out.println(b + "All Student Data: " + ub); | |
out.println(); | |
for(i = 0; i < N; i++) { | |
out.println(b + "Student #" + (i+1) + " Data: " + ub); | |
out.println(); | |
out.println("Registeration Number - " + stud[i].RegNumber); | |
out.println("Full Name - " + stud[i].FullName); | |
out.println("Date of Joining - " + stud[i].Date.get(Calendar.DAY_OF_MONTH) + "/" + stud[i].Date.get(Calendar.MONTH) + "/" + stud[i].Date.get(Calendar.YEAR)); | |
out.println("Semester - " + stud[i].Semester); | |
out.println("GPA - " + stud[i].GPA); | |
out.println("CGPA - " + stud[i].CGPA); | |
out.println(); | |
} | |
out.println(); | |
out.println(b + "All data displayed!" + ub); | |
pressAnyKeyToContinue(); | |
clrScr(); | |
break; | |
case 3: clrScr(); | |
Student.sortSem(stud); | |
out.println(); | |
out.println(b + "All Student Data: " + ub); | |
out.println(); | |
for(i = 0; i < N; i++) { | |
out.println(b + "Student #" + (i+1) + " Data: " + ub); | |
out.println(); | |
out.println("Registeration Number - " + stud[i].RegNumber); | |
out.println("Full Name - " + stud[i].FullName); | |
out.println("Date of Joining - " + stud[i].Date.get(Calendar.DAY_OF_MONTH) + "/" + stud[i].Date.get(Calendar.MONTH) + "/" + stud[i].Date.get(Calendar.YEAR)); | |
out.println("Semester - " + stud[i].Semester); | |
out.println("GPA - " + stud[i].GPA); | |
out.println("CGPA - " + stud[i].CGPA); | |
out.println(); | |
} | |
out.println(); | |
out.println(b + "All sorted and data displayed!" + ub); | |
pressAnyKeyToContinue(); | |
clrScr(); | |
break; | |
case 4: clrScr(); | |
Student.sortCgpa(stud); | |
out.println(); | |
out.println(b + "All Student Data: " + ub); | |
out.println(); | |
for(i = 0; i < N; i++) { | |
out.println(b + "Student #" + (i+1) + " Data: " + ub); | |
out.println(); | |
out.println("Registeration Number - " + stud[i].RegNumber); | |
out.println("Full Name - " + stud[i].FullName); | |
out.println("Date of Joining - " + stud[i].Date.get(Calendar.DAY_OF_MONTH) + "/" + stud[i].Date.get(Calendar.MONTH) + "/" + stud[i].Date.get(Calendar.YEAR)); | |
out.println("Semester - " + stud[i].Semester); | |
out.println("GPA - " + stud[i].GPA); | |
out.println("CGPA - " + stud[i].CGPA); | |
out.println(); | |
} | |
out.println(); | |
out.println(b + "All sorted and data displayed!" + ub); | |
pressAnyKeyToContinue(); | |
clrScr(); | |
break; | |
case 5: clrScr(); | |
Student.sortName(stud); | |
out.println(); | |
out.println(b + "All Student Data: " + ub); | |
out.println(); | |
for(i = 0; i < N; i++) { | |
out.println(b + "Student #" + (i+1) + " Data: " + ub); | |
out.println(); | |
out.println("Registeration Number - " + stud[i].RegNumber); | |
out.println("Full Name - " + stud[i].FullName); | |
out.println("Date of Joining - " + stud[i].Date.get(Calendar.DAY_OF_MONTH) + "/" + stud[i].Date.get(Calendar.MONTH) + "/" + stud[i].Date.get(Calendar.YEAR)); | |
out.println("Semester - " + stud[i].Semester); | |
out.println("GPA - " + stud[i].GPA); | |
out.println("CGPA - " + stud[i].CGPA); | |
out.println(); | |
} | |
out.println(); | |
out.println(b + "All sorted and data displayed!" + ub); | |
pressAnyKeyToContinue(); | |
clrScr(); | |
break; | |
case 6: break; | |
case 7: break; | |
case 8: break; | |
case 9: break; | |
default: break; | |
} | |
}while(opt != 9); | |
} | |
public static void pressAnyKeyToContinue() { | |
out.println("Press any key to continue..."); | |
try { | |
System.in.read(); | |
} | |
catch(Exception e) {} | |
} | |
public static void clrScr() { | |
out.print("\033\143"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment