Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Ex2;
- import java.io.*;
- import java.util.Scanner;
- public class Driver {
- public static void main(String[] args)
- {
- System.out.println("Are yor admin or user? Enter 1 if admin or 2 if user");
- Scanner in=new Scanner(System.in);
- String username, password;
- int userOrAdmin=in.nextInt();
- if(userOrAdmin==1) {
- System.out.println("Enter your username and password");
- username=in.next();
- password=in.next();
- try {
- BufferedReader br = new BufferedReader(new FileReader("admin.txt"));
- /*BufferedWriter bw = new BufferedWriter(new FileWriter("admin.txt"));
- System.out.println("Do you want to registrate?(1 Yes, 2 No)");
- if(in.nextInt()==1) {
- System.out.println("Enter username and password");
- bw.write("Username: "+in.next()+'\n');
- bw.write("Password: "+in.next().hashCode());
- }*/
- String line = br.readLine();
- if(username.equals(line.substring(10))) {
- line=br.readLine();
- if(password.equals(line.substring(10))){
- BufferedReader console=new BufferedReader(new InputStreamReader(System.in));
- System.out.println("Enter course title");
- String course=console.readLine();
- System.out.println("Enter book, namely isbn, title and author");
- TextBook newbook=new TextBook(console.readLine(), console.readLine(), console.readLine());
- System.out.println("Enter instructor (name, surname, department and email)");
- Instructor newinstr=new Instructor(console.readLine(), console.readLine(), console.readLine(), console.readLine());
- Course newcourse=new Course(course, newbook, newinstr);
- FileOutputStream courses=new FileOutputStream("course.txt");
- ObjectOutputStream obj=new ObjectOutputStream(courses);
- obj.writeObject(newcourse);
- obj.flush();
- obj.close();
- }
- }
- br.close();
- }
- catch (FileNotFoundException fe){
- System.out.println("File not found");
- }
- catch(IOException ioe) {
- System.out.println("Can’t read/write from file");
- }
- //if()
- }
- else if(userOrAdmin==2) {
- }
- else System.out.println("Wrong input!!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement