diff --git a/.gradle/7.5.1/executionHistory/executionHistory.bin b/.gradle/7.5.1/executionHistory/executionHistory.bin
index 69d19e6..ac41db8 100644
Binary files a/.gradle/7.5.1/executionHistory/executionHistory.bin and b/.gradle/7.5.1/executionHistory/executionHistory.bin differ
diff --git a/.gradle/7.5.1/executionHistory/executionHistory.lock b/.gradle/7.5.1/executionHistory/executionHistory.lock
index 74fe4a6..2d93a39 100644
Binary files a/.gradle/7.5.1/executionHistory/executionHistory.lock and b/.gradle/7.5.1/executionHistory/executionHistory.lock differ
diff --git a/.gradle/7.5.1/fileHashes/fileHashes.bin b/.gradle/7.5.1/fileHashes/fileHashes.bin
index b8a9c92..429d109 100644
Binary files a/.gradle/7.5.1/fileHashes/fileHashes.bin and b/.gradle/7.5.1/fileHashes/fileHashes.bin differ
diff --git a/.gradle/7.5.1/fileHashes/fileHashes.lock b/.gradle/7.5.1/fileHashes/fileHashes.lock
index be289e7..397fea3 100644
Binary files a/.gradle/7.5.1/fileHashes/fileHashes.lock and b/.gradle/7.5.1/fileHashes/fileHashes.lock differ
diff --git a/.gradle/7.5.1/fileHashes/resourceHashesCache.bin b/.gradle/7.5.1/fileHashes/resourceHashesCache.bin
index ae66883..c8f5d4f 100644
Binary files a/.gradle/7.5.1/fileHashes/resourceHashesCache.bin and b/.gradle/7.5.1/fileHashes/resourceHashesCache.bin differ
diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock
index 42a5cb6..0dd62a7 100644
Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ
diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin
index 813a093..0f840cb 100644
Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and b/.gradle/buildOutputCleanup/outputFiles.bin differ
diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe
index d6b6958..381c93e 100644
Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/build/reports/tests/test/classes/sbu.cs.FindMultiplesTest.html b/build/reports/tests/test/classes/sbu.cs.FindMultiplesTest.html
new file mode 100644
index 0000000..19dd951
--- /dev/null
+++ b/build/reports/tests/test/classes/sbu.cs.FindMultiplesTest.html
@@ -0,0 +1,114 @@
+
+
+
+
+
+Test results - FindMultiplesTest
+
+
+
+
+
+
+
FindMultiplesTest
+
+
+
+
+
+
+
+
+|
+
+ |
+
+
+ |
+
+
+ |
+
+
+ |
+
+
+
+ |
+
+
+ |
+
+
+
+
+
+
+
Tests
+
+
+
+| Test |
+Duration |
+Result |
+
+
+
+| testTwo() |
+0.080s |
+passed |
+
+
+
+
+
Standard output
+
+3
+6
+9
+12
+15
+5
+10
+7
+14
+
+
+
+
+
+
+
+
diff --git a/build/test-results/test/TEST-sbu.cs.FindMultiplesTest.xml b/build/test-results/test/TEST-sbu.cs.FindMultiplesTest.xml
new file mode 100644
index 0000000..d5b6d01
--- /dev/null
+++ b/build/test-results/test/TEST-sbu.cs.FindMultiplesTest.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
diff --git a/report6.pdf b/report6.pdf
new file mode 100644
index 0000000..2aad5e1
Binary files /dev/null and b/report6.pdf differ
diff --git a/src/main/java/sbu/cs/CPU_Simulator.java b/src/main/java/sbu/cs/CPU_Simulator.java
index 6be88c3..bb11fac 100644
--- a/src/main/java/sbu/cs/CPU_Simulator.java
+++ b/src/main/java/sbu/cs/CPU_Simulator.java
@@ -2,8 +2,11 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
+import static java.util.Arrays.sort;
+
/*
For this exercise, you must simulate a CPU with a single core.
You will receive an arraylist of tasks as input. Each task has a processing
@@ -22,8 +25,18 @@ public class CPU_Simulator
public static class Task implements Runnable {
long processingTime;
String ID;
+
+ public long getProcessingTime() {
+ return processingTime;
+ }
+
+ public String getID() {
+ return ID;
+ }
+
public Task(String ID, long processingTime) {
- // TODO
+ this.processingTime = processingTime;
+ this.ID = ID;
}
/*
@@ -32,7 +45,15 @@ public Task(String ID, long processingTime) {
*/
@Override
public void run() {
- // TODO
+ try {
+
+ Thread.sleep(300);
+
+ } catch (InterruptedException e) {
+
+ throw new RuntimeException(e);
+
+ }
}
}
@@ -43,12 +64,38 @@ Here the CPU selects the next shortest task to run (also known as the
*/
public ArrayList startSimulation(ArrayList tasks) {
ArrayList executedTasks = new ArrayList<>();
+ ArrayList processingTimes=new ArrayList<>();
+ ArrayList sortedTasks=new ArrayList<>();
+ for(Task task:tasks){
+ processingTimes.add(task.getProcessingTime());
+ }
+ Collections.sort(processingTimes);
+ for(Long long1:processingTimes) {
+ for(Task task:tasks){
+ if(long1==task.getProcessingTime()){
+ sortedTasks.add(task);
+ }
+ }
- // TODO
+ }
+ for(Task task:sortedTasks){
+ Thread thread=new Thread(task);
+ thread.start();
+ try {
+ thread.join();
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ executedTasks.add(task.getID());
+ }
return executedTasks;
}
+
+
+
+
public static void main(String[] args) {
}
}
diff --git a/src/main/java/sbu/cs/FindMultiples.java b/src/main/java/sbu/cs/FindMultiples.java
index 5467003..9d96a32 100644
--- a/src/main/java/sbu/cs/FindMultiples.java
+++ b/src/main/java/sbu/cs/FindMultiples.java
@@ -19,8 +19,84 @@
Use the tests provided in the test folder to ensure your code works correctly.
*/
+import java.util.ArrayList;
+
public class FindMultiples
{
+ int sum ;
+ boolean workDone3=false;
+ boolean workDone5=false;
+ boolean workDone7=false;
+ ArrayListtotal=new ArrayList<>();
+ ArrayList counter3 = new ArrayList<>();
+ ArrayList counter5 = new ArrayList<>();
+ ArrayList counter7 = new ArrayList<>();
+public class Group3 implements Runnable {
+
+ public int n;
+ public Group3(int n){
+ this.n=n;
+
+ }
+
+ @Override
+ public void run(){
+
+ for(int i=1;i<=this.n;i++){
+ if(i%3==0){
+ counter3.add(i);
+
+ }
+
+ }
+ workDone3=true;
+
+
+ }
+}
+ public class Group5 implements Runnable {
+ public int n;
+ public Group5(int n){
+ this.n=n;
+ }
+
+ @Override
+ public void run(){
+
+ for(int i=1;i<=n;i++){
+ if(i%5==0&&i%3!=0){
+ counter5.add(i);
+
+ }
+
+ }
+ workDone5=true;
+
+
+ }
+ }
+ public class Group7 implements Runnable {
+ public int n;
+ public Group7(int n){
+ this.n=n;
+ }
+
+ @Override
+ public void run(){
+
+ for(int i=1;i<=n;i++){
+ if(i%7==0&&i%5!=0&&i%3!=0){
+ counter7.add(i);
+
+ }
+
+ }
+ workDone7=true;
+
+
+ }
+ }
+
// TODO create the required multithreading class/classes using your preferred method.
@@ -30,7 +106,54 @@ public class FindMultiples
New Threads and tasks should be created here.
*/
public int getSum(int n) {
- int sum = 0;
+
+ Thread thread1=new Thread(new Group3(n));
+ Thread thread2=new Thread(new Group5(n));
+ Thread thread3=new Thread(new Group7(n));
+ //Thread thread4=new Thread(new LastThread());
+ thread1.start();
+ thread2.start();
+ thread3.start();
+ try {
+ thread1.join();
+ thread2.join();
+ thread3.join();
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);}
+ if(workDone3 && workDone5 && workDone7){
+ for (int int1:counter3){
+ total.add(int1);
+ sum+=int1;
+ }
+ for(int int1:counter5){
+ boolean unique=true;
+ for (int int2:total){
+ if(int1==int2){
+ unique=false;
+ }
+ }
+ if(unique){
+ total.add(int1);
+ sum+=int1;
+ }
+ }
+ for(int int1:counter7){
+ boolean unique=true;
+ for (int int2:total){
+ if(int1==int2){
+ unique=false;
+ }
+ }
+ if(unique){
+ total.add(int1);
+ sum+=int1;
+ }
+ }
+
+ }
+ for (int i:total){
+ System.out.println(i);
+ }
// TODO
@@ -38,5 +161,8 @@ public int getSum(int n) {
}
public static void main(String[] args) {
+
+
+
}
}