Programmation Java @ Et3
Polytech Paris-Saclay | 2020-21
Veggie Pet
Trees π² are now Pets π±
About
A console simulation program of a tree organization.
This is a school project made for the Java & OOP course.
Developed with Java SE 16.
Dependencies
- OpenCSV : Parse CSV files for Trees data
- Apache Commons Packages : Different Data Structures used to optimize the complexity of certain algorithms.
- SQLite v3.34.0 : Store data in a locally created database.
Some Implementation Details π
β
Certain Data Structure such as Queues
and Hash Maps
were used to improve
the Visits and Voting algorithms time complexity.
β
SQLite πΎ was used to create and manage local DBs. All Queries are under src/com/sys/OrganisationDB.java
public static String connect(String name) {
Connection conn = null;
// db parameters
name = name.replaceAll("\\s+","");
String fileName = new File("src/com/entity/org").getAbsolutePath() + "\\";
String url = "jdbc:sqlite:" + fileName + name + ".db";
try {
// create a connection to the database
conn = DriverManager.getConnection(url);
System.out.println("Connection to SQLite has been established.");
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
try {
if (conn != null) {
conn.close();
}
} catch (SQLException ex) {
System.err.println(ex.getMessage());
url = null;
}
}
return url;
}
β
The Municipality can push notification at a random time within the year's period.
This is achieved by creating a thread and scheduling β³ its execution for later.
// The Notification can be sent later
Timer timer = new Timer(); // creating timer
TimerTask task = this.classifyTree(tree, LocalDateTime.now()); // creating timer task
timer.schedule(task, new Date()); // scheduling the task
β
An AES 256bit Encryption algorithm is used to secure π members' data.
Code is under src/com/system/EncryptionDecryptionUtil.java
public static String encrypt(final String secret, final String data) {
byte[] decodedKey = Base64.getDecoder().decode(secret);
try {
Cipher cipher = Cipher.getInstance("AES");
// rebuild key using SecretKeySpec
SecretKey originalKey = new SecretKeySpec(Arrays.copyOf(decodedKey, 16), "AES");
cipher.init(Cipher.ENCRYPT_MODE, originalKey);
byte[] cipherText = cipher.doFinal(data.getBytes("UTF-8"));
return Base64.getEncoder().encodeToString(cipherText);
} catch (Exception e) {
throw new RuntimeException(
"Error occured while encrypting data", e);
}
}
Test Run π―
Credits Β©
Name | GitHub | Group |
---|---|---|
Mahmoud Houssem | @OopsOverflow | GR2 |
Neraudau Esteban | @s-posito | GR2 |