Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
G4-SoftEng
Group4-SoftEng
Commits
71d9c904
Commit
71d9c904
authored
Jun 19, 2021
by
saddamonpc
Browse files
Change public modifiers to private and add reset() function in Main.java
parent
dedb7e8f
Pipeline
#82657
passed with stage
in 1 minute and 2 seconds
Changes
7
Pipelines
1
Show whitespace changes
Inline
Side-by-side
src/main/java/softeng/g4/Main.java
View file @
71d9c904
package
softeng.g4
;
package
softeng.g4
;
import
jdk.swing.interop.SwingInterOpUtils
;
import
softeng.g4.appointment.Appointment
;
import
softeng.g4.cli.AdminCLI
;
import
softeng.g4.cli.AdminCLI
;
import
softeng.g4.cli.ListIO
;
import
softeng.g4.cli.ListIO
;
import
softeng.g4.cli.StudentCLI
;
import
softeng.g4.cli.StudentCLI
;
...
@@ -10,45 +8,10 @@ import softeng.g4.course.Course;
...
@@ -10,45 +8,10 @@ import softeng.g4.course.Course;
import
softeng.g4.course.CourseList
;
import
softeng.g4.course.CourseList
;
import
softeng.g4.user.*
;
import
softeng.g4.user.*
;
import
java.io.*
;
import
java.util.*
;
import
java.util.*
;
public
class
Main
{
public
class
Main
{
/**
* TODOS for something general
* TODO: Needs refactoring and exception handling!!!! (especially the latter one)
* TODO: Create a class / method(s) for handling storage. Maybe something like ListIO?
* TODO: Create classes for different user types (TACLI, STUDENTCLI, ADMINCLI), and use them in the Main class
* It should be possible to make login of each user types to different classes,
* rather than using switch cases like a madman.
*/
/**
* TODOs for "LOG IN" FEATURE
* IT's DONE. You can login by using their username.
* Ex: S akuStudent
* Ex: T akuTA
* Ex: A akuAdmin
*
* If you want to register a new user,
* you'll have to run a constructor of Student / TeachingAssistant / Admin
* Ex: New Student("exampleUsername", "Example Fullname", Long.valueOf("exampleNPM"), userList);
*/
/**
* TODOs for "APPOINTMENT" FEATURE
* TODO: Implement the methods and attributes in the Appointment.java
* TODO: Implement the methods and attributes in the RequestAppointment.java
* TODO: Edit Main.java's intro methods, switch cases, Student.java, TeachingAssistant.java, Admin.java,
* Appointment.java, RequestAppointment.java, and maybe more, such that:
* - Student can add appointments
* - TeachingAssistant can accept / reject appointment by changing the appointment status
* - Both Student and TeachingAssistant can see the appointment details
* - Admin can ask permission to see the appointment details, which then they're able to see the appointment
* TODO: After all this TODOs are done, change Main.java such that it doesn't use the hardcoded version again
*/
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
Scanner
sc
=
new
Scanner
(
System
.
in
);
Scanner
sc
=
new
Scanner
(
System
.
in
);
String
q
=
""
;
String
q
=
""
;
...
@@ -56,44 +19,8 @@ public class Main {
...
@@ -56,44 +19,8 @@ public class Main {
CourseList
courseList
;
CourseList
courseList
;
UserList
userList
;
UserList
userList
;
// // --------Uncomment all of this for the "hardcoded" version.
// --------Uncomment this for the "hardcoded" version.
// // Uncomment to add a new fresh userList and courseList
// reset();
// courseList = new CourseList();
// userList = new UserList();
//
// // Uncomment here to add a new TA or Admin
// // This will add false users, for checking users in the arraylist. (NECESSARY)
// new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList);
// new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList);
// new Admin("falseAdmin", "False Admin", userList);
//
// // Add testStudent
// new Student("akuStudent", "Aku Student", Long.valueOf("123456789"), userList);
//
// // Add testTa with a mock calendar and schedule
// TeachingAssistant testTa = new TeachingAssistant("akuTA", "Aku Asdos", Long.valueOf("123456789"), userList);
// testTa.setSchedule("monday", "Free", "12:00", "17:00");
// testTa.setSchedule("tuesday", "Free", "08:00", "11:00");
// testTa.setSchedule("tuesday", "Free", "12:00", "15:00");
// testTa.setSchedule("saturday", "Busy", "07:00", "21:00");
// testTa.setSchedule("sunday", "Free", "12:00", "17:00");
// new TeachingAssistant("anotherTA", "Another TA", Long.valueOf("1"), userList);
//
// // Add testAdmin
// new Admin("akuAdmin", "Aku Admin", userList);
//
// // Add false course
// new Course("False Course", "FALSECOURSE", "False Professor", 0, courseList);
//
// // Add mock courses
// new Course("Mata Kuliah", "MATKUL420", "Aku Dosen", 4, courseList);
// new Course("Software Engineering", "SOFTENG2021", "Aku Professor", 3, courseList);
// new Course("Fisika", "PHYS101", "Aku Dosen Fisika", 4, courseList);
//
// // Save the course
// ListIO.saveList(courseList, userList);
//
// // ---------------- END OF "HARDCODED" VERSION
while
(
true
)
{
while
(
true
)
{
...
@@ -111,7 +38,6 @@ public class Main {
...
@@ -111,7 +38,6 @@ public class Main {
break
;
break
;
}
}
// TODO: Maybe it is better to move this whole if block into a different class
String
[]
splited
=
{
" "
,
" "
};
String
[]
splited
=
{
" "
,
" "
};
splited
=
q
.
split
(
"\\s+"
);
// Split by space
splited
=
q
.
split
(
"\\s+"
);
// Split by space
String
searchUsername
;
String
searchUsername
;
...
@@ -224,4 +150,42 @@ public class Main {
...
@@ -224,4 +150,42 @@ public class Main {
System
.
out
.
println
();
System
.
out
.
println
();
}
}
// Function to reset the list to its factory new state
public
static
void
reset
()
{
CourseList
courseList
=
new
CourseList
();
UserList
userList
=
new
UserList
();
// Uncomment here to add a new TA or Admin
// This will add false users, for checking users in the arraylist. (NECESSARY)
new
Student
(
"falseStudent"
,
"False Student"
,
Long
.
valueOf
(
"123456789"
),
userList
);
new
TeachingAssistant
(
"falseTA"
,
"False TA"
,
Long
.
valueOf
(
"123456789"
),
userList
);
new
Admin
(
"falseAdmin"
,
"False Admin"
,
userList
);
// Add testStudent
new
Student
(
"akuStudent"
,
"Aku Student"
,
Long
.
valueOf
(
"123456789"
),
userList
);
// Add testTa with a mock calendar and schedule
TeachingAssistant
testTa
=
new
TeachingAssistant
(
"akuTA"
,
"Aku Asdos"
,
Long
.
valueOf
(
"123456789"
),
userList
);
testTa
.
setSchedule
(
"monday"
,
"Free"
,
"12:00"
,
"17:00"
);
testTa
.
setSchedule
(
"tuesday"
,
"Free"
,
"08:00"
,
"11:00"
);
testTa
.
setSchedule
(
"tuesday"
,
"Free"
,
"12:00"
,
"15:00"
);
testTa
.
setSchedule
(
"saturday"
,
"Busy"
,
"07:00"
,
"21:00"
);
testTa
.
setSchedule
(
"sunday"
,
"Free"
,
"12:00"
,
"17:00"
);
new
TeachingAssistant
(
"anotherTA"
,
"Another TA"
,
Long
.
valueOf
(
"1"
),
userList
);
// Add testAdmin
new
Admin
(
"akuAdmin"
,
"Aku Admin"
,
userList
);
// Add false course
new
Course
(
"False Course"
,
"FALSECOURSE"
,
"False Professor"
,
0
,
courseList
);
// Add mock courses
new
Course
(
"Mata Kuliah"
,
"MATKUL420"
,
"Aku Dosen"
,
4
,
courseList
);
new
Course
(
"Software Engineering"
,
"SOFTENG2021"
,
"Aku Professor"
,
3
,
courseList
);
new
Course
(
"Fisika"
,
"PHYS101"
,
"Aku Dosen Fisika"
,
4
,
courseList
);
// Save the course
ListIO
.
saveList
(
courseList
,
userList
);
}
}
}
src/main/java/softeng/g4/cli/StudentCLI.java
View file @
71d9c904
...
@@ -44,7 +44,7 @@ public class StudentCLI extends CLI {
...
@@ -44,7 +44,7 @@ public class StudentCLI extends CLI {
break
;
break
;
case
"APPOINTMENTS"
:
case
"APPOINTMENTS"
:
for
(
Appointment
appointment
:
currentStudent
.
a
ppointmentList
)
{
for
(
Appointment
appointment
:
currentStudent
.
getA
ppointmentList
()
)
{
System
.
out
.
println
(
appointment
);
System
.
out
.
println
(
appointment
);
System
.
out
.
println
();
System
.
out
.
println
();
}
}
...
...
src/main/java/softeng/g4/cli/TACLI.java
View file @
71d9c904
...
@@ -40,7 +40,6 @@ public class TACLI extends CLI {
...
@@ -40,7 +40,6 @@ public class TACLI extends CLI {
break
;
break
;
case
"ADD SCHEDULE"
:
case
"ADD SCHEDULE"
:
//TODO: Move this to a different function
System
.
out
.
println
(
"Choose day (Monday, Tuesday, etc.): "
);
System
.
out
.
println
(
"Choose day (Monday, Tuesday, etc.): "
);
String
day
=
sc
.
nextLine
().
toLowerCase
();
String
day
=
sc
.
nextLine
().
toLowerCase
();
System
.
out
.
println
(
"Schedule name: "
);
System
.
out
.
println
(
"Schedule name: "
);
...
@@ -53,7 +52,7 @@ public class TACLI extends CLI {
...
@@ -53,7 +52,7 @@ public class TACLI extends CLI {
System
.
out
.
println
(
"Sucessfully added a new schedule!"
);
System
.
out
.
println
(
"Sucessfully added a new schedule!"
);
case
"APPOINTMENTS"
:
case
"APPOINTMENTS"
:
for
(
Appointment
appointment
:
currentTA
.
a
ppointmentList
)
{
for
(
Appointment
appointment
:
currentTA
.
getA
ppointmentList
()
)
{
System
.
out
.
println
(
appointment
);
System
.
out
.
println
(
appointment
);
System
.
out
.
println
();
System
.
out
.
println
();
}
}
...
...
src/main/java/softeng/g4/user/Student.java
View file @
71d9c904
...
@@ -11,7 +11,7 @@ public class Student extends UserStudent {
...
@@ -11,7 +11,7 @@ public class Student extends UserStudent {
private
String
fullname
;
private
String
fullname
;
private
String
role
;
private
String
role
;
private
long
npm
;
private
long
npm
;
p
ublic
ArrayList
<
Appointment
>
appointmentList
=
new
ArrayList
<
Appointment
>();
p
rivate
ArrayList
<
Appointment
>
appointmentList
=
new
ArrayList
<
Appointment
>();
// Constructor
// Constructor
...
@@ -25,7 +25,7 @@ public class Student extends UserStudent {
...
@@ -25,7 +25,7 @@ public class Student extends UserStudent {
userList
.
userList
.
add
(
this
);
userList
.
userList
.
add
(
this
);
}
}
//
TODO:
Adds appointment with the corresponding TeachingAssistant
// Adds appointment with the corresponding TeachingAssistant
public
void
setAppointment
(
String
date
,
String
TAusername
,
String
startTime
,
String
endTime
,
String
description
,
UserList
userList
)
{
public
void
setAppointment
(
String
date
,
String
TAusername
,
String
startTime
,
String
endTime
,
String
description
,
UserList
userList
)
{
TeachingAssistant
ta
=
userList
.
searchTA
(
TAusername
);
TeachingAssistant
ta
=
userList
.
searchTA
(
TAusername
);
if
(
ta
.
getUsername
().
equals
(
"falseTA"
)){
if
(
ta
.
getUsername
().
equals
(
"falseTA"
)){
...
@@ -34,13 +34,11 @@ public class Student extends UserStudent {
...
@@ -34,13 +34,11 @@ public class Student extends UserStudent {
Appointment
newAppointment
=
new
Appointment
(
date
,
this
,
ta
,
startTime
,
endTime
,
description
);
Appointment
newAppointment
=
new
Appointment
(
date
,
this
,
ta
,
startTime
,
endTime
,
description
);
//this.calendar.addAppointment(day, newAppointment);
//this.calendar.addAppointment(day, newAppointment);
this
.
appointmentList
.
add
(
newAppointment
);
this
.
appointmentList
.
add
(
newAppointment
);
ta
.
a
ppointmentList
.
add
(
newAppointment
);
ta
.
getA
ppointmentList
()
.
add
(
newAppointment
);
}
}
}
}
// See this Student's calendar
// See Teaching Assistant's calendar
// temporary calendar
// TODO: Change this method such that it returns the TA's calendar by searching for their username
public
void
seeCalendar
(
String
TAusername
,
UserList
userList
)
{
public
void
seeCalendar
(
String
TAusername
,
UserList
userList
)
{
TeachingAssistant
ta
=
userList
.
searchTA
(
TAusername
);
TeachingAssistant
ta
=
userList
.
searchTA
(
TAusername
);
ta
.
seeCalendar
();
ta
.
seeCalendar
();
...
@@ -59,4 +57,8 @@ public class Student extends UserStudent {
...
@@ -59,4 +57,8 @@ public class Student extends UserStudent {
return
username
+
" - "
+
fullname
;
return
username
+
" - "
+
fullname
;
}
}
public
ArrayList
<
Appointment
>
getAppointmentList
()
{
return
this
.
appointmentList
;
}
}
}
src/main/java/softeng/g4/user/TeachingAssistant.java
View file @
71d9c904
...
@@ -14,7 +14,7 @@ public class TeachingAssistant extends UserStudent {
...
@@ -14,7 +14,7 @@ public class TeachingAssistant extends UserStudent {
private
long
npm
;
private
long
npm
;
private
Admin
askPermissionAdmin
=
null
;
private
Admin
askPermissionAdmin
=
null
;
private
Calendar
calendar
=
new
Calendar
();
private
Calendar
calendar
=
new
Calendar
();
p
ublic
ArrayList
<
Appointment
>
appointmentList
=
new
ArrayList
<
Appointment
>();
p
rivate
ArrayList
<
Appointment
>
appointmentList
=
new
ArrayList
<
Appointment
>();
// Constructor
// Constructor
public
TeachingAssistant
(
String
username
,
String
fullname
,
long
npm
,
UserList
userList
)
{
public
TeachingAssistant
(
String
username
,
String
fullname
,
long
npm
,
UserList
userList
)
{
...
@@ -43,7 +43,7 @@ public class TeachingAssistant extends UserStudent {
...
@@ -43,7 +43,7 @@ public class TeachingAssistant extends UserStudent {
this
.
calendar
.
showCalendar
();
this
.
calendar
.
showCalendar
();
}
}
//
TODO: Implement these 2 methods such that they can change the status of the appointment to accepted or rejected
//
Accept appointment
public
void
acceptAppointment
(
String
id
,
UserList
userList
)
{
public
void
acceptAppointment
(
String
id
,
UserList
userList
)
{
boolean
found
=
false
;
boolean
found
=
false
;
for
(
Appointment
appointment
:
appointmentList
)
{
for
(
Appointment
appointment
:
appointmentList
)
{
...
@@ -51,7 +51,7 @@ public class TeachingAssistant extends UserStudent {
...
@@ -51,7 +51,7 @@ public class TeachingAssistant extends UserStudent {
found
=
true
;
found
=
true
;
appointment
.
setStatus
(
"Accepted"
);
appointment
.
setStatus
(
"Accepted"
);
Student
student
=
userList
.
searchStudent
(
appointment
.
getStudent
().
getUsername
());
Student
student
=
userList
.
searchStudent
(
appointment
.
getStudent
().
getUsername
());
for
(
Appointment
studentappointment
:
student
.
a
ppointmentList
)
{
for
(
Appointment
studentappointment
:
student
.
getA
ppointmentList
()
)
{
if
(
studentappointment
.
getId
().
equals
(
id
))
{
if
(
studentappointment
.
getId
().
equals
(
id
))
{
studentappointment
.
setStatus
(
"Accepted"
);
studentappointment
.
setStatus
(
"Accepted"
);
}
}
...
@@ -65,6 +65,7 @@ public class TeachingAssistant extends UserStudent {
...
@@ -65,6 +65,7 @@ public class TeachingAssistant extends UserStudent {
}
}
}
}
// Reject appointment
public
void
rejectAppointment
(
String
id
,
UserList
userList
)
{
public
void
rejectAppointment
(
String
id
,
UserList
userList
)
{
boolean
found
=
false
;
boolean
found
=
false
;
for
(
Appointment
appointment
:
appointmentList
)
{
for
(
Appointment
appointment
:
appointmentList
)
{
...
@@ -72,7 +73,7 @@ public class TeachingAssistant extends UserStudent {
...
@@ -72,7 +73,7 @@ public class TeachingAssistant extends UserStudent {
found
=
true
;
found
=
true
;
appointment
.
setStatus
(
"Rejected"
);
appointment
.
setStatus
(
"Rejected"
);
Student
student
=
userList
.
searchStudent
(
appointment
.
getStudent
().
getUsername
());
Student
student
=
userList
.
searchStudent
(
appointment
.
getStudent
().
getUsername
());
for
(
Appointment
studentappointment
:
student
.
a
ppointmentList
)
{
for
(
Appointment
studentappointment
:
student
.
getA
ppointmentList
()
)
{
if
(
studentappointment
.
getId
().
equals
(
id
))
{
if
(
studentappointment
.
getId
().
equals
(
id
))
{
studentappointment
.
setStatus
(
"Rejected"
);
studentappointment
.
setStatus
(
"Rejected"
);
}
}
...
@@ -121,4 +122,8 @@ public class TeachingAssistant extends UserStudent {
...
@@ -121,4 +122,8 @@ public class TeachingAssistant extends UserStudent {
public
Calendar
getCalendar
()
{
public
Calendar
getCalendar
()
{
return
calendar
;
return
calendar
;
}
}
public
ArrayList
<
Appointment
>
getAppointmentList
()
{
return
this
.
appointmentList
;
}
}
}
src/main/java/softeng/g4/userlist.txt
View file @
71d9c904
No preview for this file type
src/test/java/softeng/g4/user/TeachingAssistantTest.java
View file @
71d9c904
...
@@ -98,18 +98,18 @@ class TeachingAssistantTest {
...
@@ -98,18 +98,18 @@ class TeachingAssistantTest {
void
acceptAppointment
()
{
void
acceptAppointment
()
{
testStudent
.
setAppointment
(
testStudent
.
setAppointment
(
"31/12"
,
"testTa"
,
"08:00"
,
"09:40"
,
"testDesc"
,
userList
);
"31/12"
,
"testTa"
,
"08:00"
,
"09:40"
,
"testDesc"
,
userList
);
testTa
.
acceptAppointment
(
testTa
.
a
ppointmentList
.
get
(
0
).
getId
(),
userList
);
testTa
.
acceptAppointment
(
testTa
.
getA
ppointmentList
()
.
get
(
0
).
getId
(),
userList
);
assertEquals
(
testTa
.
a
ppointmentList
.
get
(
0
).
getStatus
(),
"Accepted"
);
assertEquals
(
testTa
.
getA
ppointmentList
()
.
get
(
0
).
getStatus
(),
"Accepted"
);
assertEquals
(
testStudent
.
a
ppointmentList
.
get
(
0
).
getStatus
(),
"Accepted"
);
assertEquals
(
testStudent
.
getA
ppointmentList
()
.
get
(
0
).
getStatus
(),
"Accepted"
);
}
}
@Test
@Test
void
rejectAppointment
()
{
void
rejectAppointment
()
{
testStudent
.
setAppointment
(
testStudent
.
setAppointment
(
"31/12"
,
"testTa"
,
"08:00"
,
"09:40"
,
"testDesc"
,
userList
);
"31/12"
,
"testTa"
,
"08:00"
,
"09:40"
,
"testDesc"
,
userList
);
testTa
.
rejectAppointment
(
testTa
.
a
ppointmentList
.
get
(
0
).
getId
(),
userList
);
testTa
.
rejectAppointment
(
testTa
.
getA
ppointmentList
()
.
get
(
0
).
getId
(),
userList
);
assertEquals
(
testTa
.
a
ppointmentList
.
get
(
0
).
getStatus
(),
"Rejected"
);
assertEquals
(
testTa
.
getA
ppointmentList
()
.
get
(
0
).
getStatus
(),
"Rejected"
);
assertEquals
(
testStudent
.
a
ppointmentList
.
get
(
0
).
getStatus
(),
"Rejected"
);
assertEquals
(
testStudent
.
getA
ppointmentList
()
.
get
(
0
).
getStatus
(),
"Rejected"
);
}
}
@AfterEach
@AfterEach
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment