Commit 81eac5b8 authored by rawan's avatar rawan

Final solution: Added TaskPrimeCounter and fixed Dockerfile

parent a8654cd3
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/web-http-socket-server-task-manager-docker.iml" filepath="$PROJECT_DIR$/web-http-socket-server-task-manager-docker.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
FROM openjdk:8-jdk-alpine
FROM eclipse-temurin:8-jdk-alpine
Invoke-WebRequest -Method POST -Body "TaskPrimeCounter&100000" -Uri http://localhost:8000/
LABEL maintainer="Wagner Franchin"
ENV WEBPATH=/webserver/
......
package task;
// 1. يجب أن يكون في نفس الباكج 'task'
// 2. يجب أن يرث من 'TaskImpl'
public class TaskPrimeCounter extends TaskImpl {
// 3. كل ما نحتاجه هو كتابة دالة 'execute'
@Override
public void execute() {
try {
// 4. نقرأ المدخلات من المتغير 'input' (الذي ورثناه)
int n = Integer.parseInt(input);
// 5. نقوم بتشغيل اللوجيك الخاص بنا
int count = countPrimes(n);
// 6. نخزن النتيجة في المتغير 'result' (الذي ورثناه)
this.result = "Found " + count + " prime (s) up to " + n;
} catch (NumberFormatException e) {
this.result = "Error: Input must be a valid number (e.g., 10000)";
}
}
/**
* دالة مساعدة لعد الأعداد الأولية حتى n
*/
private int countPrimes(int n) {
if (n <= 1) {
return 0;
}
int counter = 0;
for (int i = 2; i <= n; i++) {
if (isPrime(i)) {
counter++;
}
}
return counter;
}
/**
* دالة مساعدة لفحص إذا كان الرقم أولي
*/
private boolean isPrime(int num) {
if (num <= 1) return false;
for (int i = 2; i * i <= num; i++) {
if (num % i == 0) {
return false;
}
}
return true;
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment