aboutsummaryrefslogtreecommitdiff
path: root/src/com.example.portfolio2/com/example/portfolio2/Model.java
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2025-04-28 19:16:17 +0200
committerJonas Smedegaard <dr@jones.dk>2025-04-28 19:16:17 +0200
commit34e38a3e79a21f78ec18d228a881505131af49f0 (patch)
tree951f4735b00ff39827a0eeb2da03eb2ad8a564b4 /src/com.example.portfolio2/com/example/portfolio2/Model.java
parentb3627749041ce2ace1fc34d7b1c225feb46ae9bf (diff)
add and improve javadoc
Diffstat (limited to 'src/com.example.portfolio2/com/example/portfolio2/Model.java')
-rw-r--r--src/com.example.portfolio2/com/example/portfolio2/Model.java42
1 files changed, 33 insertions, 9 deletions
diff --git a/src/com.example.portfolio2/com/example/portfolio2/Model.java b/src/com.example.portfolio2/com/example/portfolio2/Model.java
index bafa3fc..8216ccc 100644
--- a/src/com.example.portfolio2/com/example/portfolio2/Model.java
+++ b/src/com.example.portfolio2/com/example/portfolio2/Model.java
@@ -7,18 +7,27 @@ package com.example.portfolio2;
import java.util.ArrayList;
-// The model handles all interactions with the database
+/// Bachelorizer - database model
+///
+/// This model handles all interaction with the database.
class Model{
- MyDB db=new MyDB();
+ /// database singleton
+ MyDB db = new MyDB();
+
+ /// default constructor
+ // (declared explicitly only to silence javadoc)
Model(){}
- // When running the program, it clears the participation database
+ /// clear the participation database at program launch
void initialize() {
clearParticipation();
}
- // Returns the integer value of the activity's index
+ /// resolve activity index from name
+ ///
+ /// @param name activity name
+ /// @return index of activity as integer
int getActivityIndeks(String name) {
if(name ==null) return -1;
ArrayList<String> result = db.query("select indeks from activity a where name is '"+name+"';", "indeks");
@@ -26,33 +35,48 @@ class Model{
}
- // Inserts the given activity into participation using the activity's index
+ /// insert activity into participation
+ ///
+ /// @param activityIndex index of activity
void addParticipation(int activityIndex) {
db.cmd("insert into participation values(123, "+activityIndex+");");
}
- // Returns all activity names from activities currently in participation
+ /// list currently participating activities
+ ///
+ /// @param program programme name
+ /// @return names of participating activities
ArrayList<String> getParticipation(String program) {
return db.query("select name from participation p inner join activity a on p.indeks = a.indeks where program is '" + program + "';", "name");
}
- // Removes all entries in the participation database
+ /// purge participation database
void clearParticipation() {
db.cmd("delete from participation");
}
- // Returns an arraylist of activities within the given program
+ /// list activities within a program
+ ///
+ /// @param program programme name
+ /// @return names of contained activities
ArrayList<String> selectProgram(String program) {
return db.query("select name from activity where program is '" + program + "';", "name");
}
- // Returns the sum of ECTS points under the given category from the student as a string
+ /// sum of ECTS points under the given category
+ ///
+ /// @param program programme name
+ /// @return ECTS points as String
String getSumEcts(String program){
if(program==null)return "0";
ArrayList<String> result = db.query("select sum(activity.ects) as total_ects,student.name from student left outer join participation on student.studid = participation.studid inner join activity on participation.indeks = activity.indeks where program is '"+program+"' group by student.studid ;", "total_ects");
if (result.isEmpty()) return "0";
return result.getFirst();
}
+
+ /// sum of ECTS points under the given category
+ ///
+ /// @return names of all activities as list of String
ArrayList<String> getAllActivities() {
return db.query("select name from activity;", "name");
}