0% found this document useful (0 votes)
11 views9 pages

Project 1

Uploaded by

montyroy718
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views9 pages

Project 1

Uploaded by

montyroy718
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

File - S:\Java\Student Managment System\src\Main.

java
import java.util.Scanner;

public class Main {


public static boolean exit = false;

public static void main(String[] args) {


while (! exit)
{
System.out.println("Select any one option \n1.Login \n2.Register \n3.Exit");
Scanner sc = new Scanner(System.in);

int choose = sc.nextInt();

if (choose == 2) {
System.out.println("Enter name:");
sc.nextLine();
String enterName = sc.nextLine();

System.out.println("Set your password for login: ");


String createPassword = sc.next();

String data = enterName + " " + createPassword;


new UserInfo(data);

}
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)
{

System.out.println("1.Add Student info \n2.View Student info \n3.Assign


course \n4.View Assigned course \n5.Exit" );
int no = sc.nextInt();
if (no == 1)
{
System.out.println("Enter Student info:");
System.out.println("Name:");
sc.nextLine();

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;

public class UserInfo {


public String name;
private String password;
public static boolean key = false;

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;
}

public static boolean isKey() {


return key;
}

public static void setKey(boolean key) {


UserInfo.key = key;
}
}

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;

public class StudentInfo {

public String name;


public static String ID;
public String program;
public int batch;
public double cgpa;
private String password;

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();
}

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("\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;
}

public void setPassword(String password)


{
this.password = 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;

public class AdvisedCourse


{
String ID;
String course;
AdvisedCourse()
{

}
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

You might also like