Professional Documents
Culture Documents
Project1
Project1
java
import java.util.Scanner;
if (choose == 2) {
System.out.println("Enter name:");
sc.nextLine();
String enterName = sc.nextLine();
}
else if (choose == 1)
{
System.out.println("Enter name : ");
sc.nextLine();
String enterName = sc.nextLine();
System.out.println("Enter password:");
String enterPassword = sc.next();
UserInfo.loginCheck(enterName, enterPassword);
while (UserInfo.key)
{
Page 1 of 3
File - S:\Java\Student Managment System\src\Main.java
StudentInfo s1 = new StudentInfo();
s1.name = sc.nextLine();
System.out.println("ID");
s1.ID = sc.next();
System.out.println("Batch");
s1.batch = sc.nextInt();
System.out.println("Program");
s1.program = sc.next();
System.out.println("CGPA");
s1.cgpa = sc.nextDouble();
System.out.println("Password");
s1.setPassword(sc.next());
String info = s1.ID + " " + s1.name + " " + s1.batch + " " + s1.program + " "
+ s1.cgpa + " " + s1.getPassword();
new StudentInfo(info);
} else if (no == 2) {
System.out.println("Enter Student ID for Information-");
StudentInfo.searchInfo(sc.next());
} else if (no == 3) {
System.out.println("Enter ID : ");
AdvisedCourse a1 = new AdvisedCourse();
a1.ID = sc.next();
System.out.println("Assign courses:");
sc.nextLine();
a1.course = sc.nextLine();
String course = a1.ID + " " + a1.course;
new AdvisedCourse(course);
}
else if(no == 4)
{
System.out.println("Enter ID for viewing Assgined course:");
AdvisedCourse.viewAssignedCourse(sc.next());
}
else if(no == 5)
{
return;
}
else
{
System.out.println("Invalid Entry");
}
}
if(!UserInfo.key)
{
Page 2 of 3
File - S:\Java\Student Managment System\src\Main.java
System.out.println("Login failed");
}
}
else if (choose == 3)
{
exit = true;
System.out.println("Exiting program");
}
else
{
System.out.println("Invalid Input");
}
}
}
}
Page 3 of 3
File - S:\Java\Student Managment System\src\UserInfo.java
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
UserInfo(String data)
{
try
{
RandomAccessFile raf = new RandomAccessFile("UserInfo.txt", "rw");
raf.seek(raf.length());
raf.writeBytes(data+"\n");
raf.close();
}
catch (FileNotFoundException ex)
{
ex.printStackTrace();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
public static boolean loginCheck(String name, String password)
{
String givenData = name+ " " + password;
try
{
RandomAccessFile raf = new RandomAccessFile("UserInfo.txt" , "r");
String text ;
while((text= raf.readLine())!= null)
{
if(givenData.equals(text))
{
System.out.println("Login Successfully ");
return key = true;
}
else {
}
}
Page 1 of 2
File - S:\Java\Student Managment System\src\UserInfo.java
catch (FileNotFoundException ex)
{
ex.printStackTrace();
}
catch (IOException ex)
{
ex.printStackTrace();
}
return false;
}
Page 2 of 2
File - S:\Java\Student Managment System\src\StudentInfo.java
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
StudentInfo(){}
StudentInfo(String info)
{
try
{
RandomAccessFile raf = new RandomAccessFile("StudentInfo.txt", "rw");
raf.seek(raf.length());
raf.writeBytes(info + "\n");
raf.close();
}
catch (FileNotFoundException ex) {
ex.printStackTrace();
}
catch (IOException ex) {
ex.printStackTrace();
}
if(search.equals(part[0]))
{
System.out.println("\n" + "Name: " + part[1] + " \n " +" ID: " + part[0]+ " \n
" + " Batch: "+ part[2]+ " \n " + " Program: " + part[3] + " \n " + " CGPA: " + part[4] + "
Page 1 of 2
File - S:\Java\Student Managment System\src\StudentInfo.java
\n" );
status = true;
break;
}
}
if(!status)
{
System.out.println("Invalid Input");
}
}
catch (FileNotFoundException ex)
{
ex.printStackTrace();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
public String getPassword()
{
return password;
}
Page 2 of 2
File - S:\Java\Student Managment System\src\AdvisedCourse.java
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
}
AdvisedCourse(String course)
{
try
{
RandomAccessFile raf = new RandomAccessFile("AdvisedCourse.txt", "rw");
raf.seek(raf.length());
raf.writeBytes(course + "\n");
raf.close();
}
catch (FileNotFoundException ex) {
ex.printStackTrace();
}
catch (IOException ex) {
ex.printStackTrace();
}
}
public static void searchInfo(String search)
{
try {
RandomAccessFile raf = new RandomAccessFile("StudentInfo.txt", "r");
String line ;
boolean status = false;
while( (line = raf.readLine()) !=null)
{
String[] part= line.split(" ");
if(search.equals(part[0]))
{
System.out.println(line);
status = true;
break;
}
}
if(false)
Page 1 of 2
File - S:\Java\Student Managment System\src\AdvisedCourse.java
{
System.out.println("invalid input");
}
}
catch (FileNotFoundException ex)
{
ex.printStackTrace();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
public static void viewAssignedCourse(String search)
{
try {
RandomAccessFile raf = new RandomAccessFile("AdvisedCourse.txt", "r");
String line ;
boolean status = false;
while( (line = raf.readLine()) !=null)
{
String[] part= line.split(" ");
if(search.equals(part[0]))
{
System.out.println(line);
status = true;
break;
}
}
if(false)
{
System.out.println("invalid input");
}
}
catch (FileNotFoundException ex)
{
ex.printStackTrace();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
}
Page 2 of 2