-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.java
More file actions
152 lines (126 loc) · 4.63 KB
/
Copy pathproject.java
File metadata and controls
152 lines (126 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import java.util.*;
class User {
private String username;
private String password;
private String role; // "Student" or "Instructor"
public User(String username, String password, String role) {
this.username = username;
this.password = password;
this.role = role;
}
public boolean login(String password) {
return this.password.equals(password);
}
public String getProfileDetails() {
return username + " (" + role + ")";
}
}
class Student extends User {
private List<Course> enrolledCourses;
public Student(String username, String password) {
super(username, password, "Student");
enrolledCourses = new ArrayList<>();
}
public void enrollCourse(Course course) {
enrolledCourses.add(course);
}
public void viewCourses() {
for (Course course : enrolledCourses) {
System.out.println(course.getCourseDetails());
}
}
}
class Instructor extends User {
private List<Course> createdCourses;
public Instructor(String username, String password) {
super(username, password, "Instructor");
createdCourses = new ArrayList<>();
}
public void createCourse(Course course) {
createdCourses.add(course);
}
}
class Course {
private String courseId;
private String title;
private String description;
private List<Assignment> assignments;
private List<Student> enrolledStudents;
public Course(String courseId, String title, String description) {
this.courseId = courseId;
this.title = title;
this.description = description;
assignments = new ArrayList<>();
enrolledStudents = new ArrayList<>();
}
public void addAssignment(Assignment assignment) {
assignments.add(assignment);
}
public String getCourseDetails() {
return title + ": " + description;
}
}
class Assignment {
private String assignmentId;
private String title;
private String description;
public Assignment(String assignmentId, String title, String description) {
this.assignmentId = assignmentId;
this.title = title;
this.description = description;
}
public String getAssignmentDetails() {
return title + ": " + description;
}
}
public class Main {
private static List<User> users = new ArrayList<>();
private static List<Course> courses = new ArrayList<>();
private static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
// Sample data for quick testing
Instructor instructor1 = new Instructor("dhruv_agg", "dhruvagg");
Student student1 = new Student("dhruv_student_id", "dhruv_student_pass");
users.add(instructor1);
users.add(student1);
// Adding a sample course
Course javaCourse = new Course("C101", "Java Programming", "Learn the basics of Java.");
courses.add(javaCourse);
instructor1.createCourse(javaCourse);
// Simple login flow
System.out.print("Enter username: ");
String username = scanner.nextLine();
System.out.print("Enter password: ");
String password = scanner.nextLine();
User loggedInUser = authenticate(username, password);
if (loggedInUser != null) {
System.out.println("Login successful! Welcome, " + loggedInUser.getProfileDetails());
if (loggedInUser instanceof Student) {
studentMenu((Student) loggedInUser);
} else if (loggedInUser instanceof Instructor) {
instructorMenu((Instructor) loggedInUser);
}
} else {
System.out.println("Invalid credentials.");
}
}
private static User authenticate(String username, String password) {
for (User user : users) {
if (user.getProfileDetails().contains(username) && user.login(password)) {
return user;
}
}
return null;
}
private static void studentMenu(Student student) {
System.out.println("You are a student. Enrolling in the Java course...");
student.enrollCourse(courses.get(0)); // Automatically enroll in the first course for simplicity
System.out.println("Courses enrolled:");
student.viewCourses();
}
private static void instructorMenu(Instructor instructor) {
System.out.println("You are an instructor. Viewing your created courses...");
instructor.createCourse(courses.get(0)); // Simple: view or re-create the first course
System.out.println("Course created: " + courses.get(0).getCourseDetails());
}
}