exam modal dev aout 2023
This commit is contained in:
32
bac2/modalDev/e23/question1/app/.classpath
Normal file
32
bac2/modalDev/e23/question1/app/.classpath
Normal file
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/test" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="test"/>
|
||||
<attribute name="gradle_used_by_scope" value="test"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/test" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="test"/>
|
||||
<attribute name="gradle_used_by_scope" value="test"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21/"/>
|
||||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
|
||||
<classpathentry kind="output" path="bin/default"/>
|
||||
</classpath>
|
34
bac2/modalDev/e23/question1/app/.project
Normal file
34
bac2/modalDev/e23/question1/app/.project
Normal file
@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>app</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
</natures>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1705162039553</id>
|
||||
<name></name>
|
||||
<type>30</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
@ -0,0 +1,13 @@
|
||||
arguments=
|
||||
auto.sync=false
|
||||
build.scans.enabled=false
|
||||
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
|
||||
connection.project.dir=..
|
||||
eclipse.preferences.version=1
|
||||
gradle.user.home=
|
||||
java.home=
|
||||
jvm.arguments=
|
||||
offline.mode=false
|
||||
override.workspace.settings=false
|
||||
show.console.view=false
|
||||
show.executions.view=false
|
@ -0,0 +1,11 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=21
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=21
|
44
bac2/modalDev/e23/question1/app/build.gradle.kts
Normal file
44
bac2/modalDev/e23/question1/app/build.gradle.kts
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*
|
||||
* This generated file contains a sample Java application project to get you started.
|
||||
* For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.5/userguide/building_java_projects.html in the Gradle documentation.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
// Apply the application plugin to add support for building a CLI application in Java.
|
||||
application
|
||||
eclipse
|
||||
}
|
||||
|
||||
repositories {
|
||||
// Use Maven Central for resolving dependencies.
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Use JUnit Jupiter for testing.
|
||||
testImplementation(libs.junit.jupiter)
|
||||
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
|
||||
// This dependency is used by the application.
|
||||
implementation(libs.guava)
|
||||
}
|
||||
|
||||
// Apply a specific Java toolchain to ease working on different environments.
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(21))
|
||||
}
|
||||
}
|
||||
|
||||
application {
|
||||
// Define the main class for the application.
|
||||
mainClass.set("question1.App")
|
||||
}
|
||||
|
||||
tasks.named<Test>("test") {
|
||||
// Use JUnit Platform for unit tests.
|
||||
useJUnitPlatform()
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* This Java source file was generated by the Gradle 'init' task.
|
||||
*/
|
||||
package question1;
|
||||
|
||||
public class App {
|
||||
public String getGreeting() {
|
||||
return "Hello World!";
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(new App().getGreeting());
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package question1;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class InventoryManagement {
|
||||
|
||||
// cnt[zone][product] = quantity
|
||||
HashMap<Integer, HashMap<Integer, Integer>> cnt = new HashMap<>();
|
||||
|
||||
// ajoute dans une zone du stock une quantité donnée d’un produit donné
|
||||
void replenish(int product, int quantity, int destination_zone) throws ZoneFullException{
|
||||
cnt.putIfAbsent(destination_zone, new HashMap<>());
|
||||
cnt.get(destination_zone).putIfAbsent(product, 0);
|
||||
Integer q = cnt.get(destination_zone).get(product) + quantity;
|
||||
if(q > 100)
|
||||
throw new ZoneFullException();
|
||||
cnt.get(destination_zone).put(product, q);
|
||||
}
|
||||
|
||||
// retire d’une zone spécifique du stock une quantité donnée d’un produit donné pour l’envoyer vers le réseau de distribution
|
||||
void distribute(int product, int source_zone, int quantity) throws StockOutException{
|
||||
cnt.putIfAbsent(source_zone, new HashMap<>());
|
||||
cnt.get(source_zone).putIfAbsent(product, 0);
|
||||
Integer q = cnt.get(source_zone).get(product) - quantity;
|
||||
if(q < 0)
|
||||
throw new StockOutException();
|
||||
cnt.get(source_zone).put(product, q);
|
||||
}
|
||||
|
||||
// déplace une quantité donnée d’un produit vers une autre zone
|
||||
void move(int product, int quantity, int source_zone, int destination_zone) throws StockOutException, ZoneFullException {
|
||||
distribute(product, source_zone, quantity);
|
||||
try {
|
||||
replenish(product, quantity, destination_zone);
|
||||
}catch(ZoneFullException e){
|
||||
replenish(product, quantity, source_zone);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// retourne la quantité disponible d’un produit donné dans le stock, toutes zones confondues
|
||||
int quantity(int product){
|
||||
int sum[] = {0};
|
||||
cnt.forEach((key, value) -> {
|
||||
sum[0] += value.getOrDefault(product, 0);
|
||||
});
|
||||
return sum[0];
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package question1;
|
||||
|
||||
public class StockOutException extends Exception{
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,4 @@
|
||||
package question1;
|
||||
|
||||
public class ZoneFullException extends Exception {}
|
||||
|
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* This Java source file was generated by the Gradle 'init' task.
|
||||
*/
|
||||
package question1;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class AppTest {
|
||||
@Test void appHasAGreeting() {
|
||||
App classUnderTest = new App();
|
||||
assertNotNull(classUnderTest.getGreeting(), "app should have a greeting");
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package question1;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class InventoryManagementTest {
|
||||
|
||||
@Test
|
||||
public void testExceptions() throws Exception {
|
||||
InventoryManagement iv = new InventoryManagement();
|
||||
iv.replenish(0, 10, 0);
|
||||
assertThrows(ZoneFullException.class, () -> iv.replenish(0, 96, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExceptions2() throws Exception {
|
||||
InventoryManagement iv = new InventoryManagement();
|
||||
assertThrows(StockOutException.class, () -> iv.distribute(0, 0, 92));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuantity() throws Exception {
|
||||
InventoryManagement iv = new InventoryManagement();
|
||||
iv.replenish(2, 42, 0);
|
||||
iv.replenish(2, 21, 1);
|
||||
iv.replenish(2, 0, 3);
|
||||
assertEquals(63, iv.quantity(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMove() throws Exception {
|
||||
InventoryManagement iv = new InventoryManagement();
|
||||
iv.replenish(42, 50, 1);
|
||||
iv.move(42, 21, 1, 2);
|
||||
assertEquals(50, iv.quantity(42));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure() throws Exception {
|
||||
InventoryManagement iv = new InventoryManagement();
|
||||
iv.replenish(42, 50, 1);
|
||||
iv.replenish(42, 50, 2);
|
||||
assertEquals(5050, iv.quantity(42)); // Should return a Failure
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testError() throws Exception {
|
||||
InventoryManagement iv = new InventoryManagement();
|
||||
iv.replenish(42, 100, 1);
|
||||
iv.replenish(42, 1, 1); // Should create an error
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user