Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package studentdb;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Scanner;
- public class MainStudentdb
- {
- static List<Studentdb> st = new ArrayList<Studentdb>();
- public static void main(String[] args)
- {
- Scanner sc = new Scanner(System.in);
- System.out.println("1.Admin login");
- System.out.println("2.User login");
- System.out.println("Exit");
- System.out.println("Enter your choice:");
- int choice = sc.nextInt();
- while(choice !=0)
- {
- switch(choice)
- {
- case 1:
- System.out.println("Admin login");
- Adminlogin();
- showDetails();
- break;
- case 2:
- System.out.println("User login");
- userlogin();
- break;
- case 3:
- System.out.println("Exit");
- System.exit(0);
- break;
- }
- System.out.println("1.Admin login");
- System.out.println("2.User login");
- System.out.println("Exit");
- System.out.println("Enter your choice:");
- choice = sc.nextInt();
- }
- }
- public static void Adminlogin()
- {
- String username, password, name, regd_no, Branch, Semester;
- double CGPA;
- Scanner sc = new Scanner(System.in);
- System.out.println("------------------------------------");
- System.out.println("Enter username:");
- username = sc.nextLine();
- System.out.println("Enter password:");
- password = sc.nextLine();
- System.out.println("Enter name:");
- name = sc.nextLine();
- System.out.println("Enter regd_no:");
- regd_no = sc.nextLine();
- System.out.println("Enter branch:");
- Branch = sc.nextLine();
- System.out.println("Enter semester:");
- Semester = sc.nextLine();
- System.out.println("Enter CGPA:");
- CGPA = sc.nextDouble();
- System.out.println("------------------------------------");
- Studentdb db = new Studentdb();
- db.setUsername(username);
- db.setPassword(password);
- db.setName(name);
- db.setRegd_no(regd_no);
- db.setBranch(Branch);
- db.setSemester(Semester);
- db.setCGPA(CGPA);
- st.add(db);
- }
- static void showDetails()
- {
- Iterator<Studentdb> i = st.iterator();
- while(i.hasNext())
- {
- Studentdb p= i.next();
- System.out.println("-------------------------------");
- System.out.println(p.getUsername());
- System.out.println(p.getPassword());
- System.out.println(p.getName());
- System.out.println(p.getRegd_no());
- System.out.println(p.getBranch());
- System.out.println(p.getCGPA());
- System.out.println("-------------------------------");
- }
- }
- public static void userlogin()
- {
- String username, password, name, regd_no, Branch, Semester;
- double CGPA;
- Scanner sc = new Scanner(System.in);
- System.out.println("Enter username:");
- username = sc.nextLine();
- System.out.println("Enter password:");
- password = sc.nextLine();
- Iterator<Studentdb> i = st.iterator();
- boolean flag=false;
- while(i.hasNext())
- {
- Studentdb p= i.next();
- if(username.equals(p.getUsername()) && password.equals(p.getPassword()))
- {
- System.out.println("-------------------------------");
- System.out.println(p.getUsername());
- System.out.println(p.getPassword());
- System.out.println(p.getName());
- System.out.println(p.getRegd_no());
- System.out.println(p.getBranch());
- System.out.println(p.getCGPA());
- System.out.println("-------------------------------");
- flag=true;
- }
- }
- if(!flag){
- System.out.println("Wrong username or password");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement