Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .gradle/7.5.1/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/7.5.1/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/7.5.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/7.5.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/7.5.1/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file modified .gradle/file-system.probe
Binary file not shown.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 114 additions & 0 deletions build/reports/tests/test/classes/sbu.cs.FindMultiplesTest.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="x-ua-compatible" content="IE=edge"/>
<title>Test results - FindMultiplesTest</title>
<link href="../css/base-style.css" rel="stylesheet" type="text/css"/>
<link href="../css/style.css" rel="stylesheet" type="text/css"/>
<script src="../js/report.js" type="text/javascript"></script>
</head>
<body>
<div id="content">
<h1>FindMultiplesTest</h1>
<div class="breadcrumbs">
<a href="../index.html">all</a> &gt;
<a href="../packages/sbu.cs.html">sbu.cs</a> &gt; FindMultiplesTest</div>
<div id="summary">
<table>
<tr>
<td>
<div class="summaryGroup">
<table>
<tr>
<td>
<div class="infoBox" id="tests">
<div class="counter">1</div>
<p>tests</p>
</div>
</td>
<td>
<div class="infoBox" id="failures">
<div class="counter">0</div>
<p>failures</p>
</div>
</td>
<td>
<div class="infoBox" id="ignored">
<div class="counter">0</div>
<p>ignored</p>
</div>
</td>
<td>
<div class="infoBox" id="duration">
<div class="counter">0.080s</div>
<p>duration</p>
</div>
</td>
</tr>
</table>
</div>
</td>
<td>
<div class="infoBox success" id="successRate">
<div class="percent">100%</div>
<p>successful</p>
</div>
</td>
</tr>
</table>
</div>
<div id="tabs">
<ul class="tabLinks">
<li>
<a href="#tab0">Tests</a>
</li>
<li>
<a href="#tab1">Standard output</a>
</li>
</ul>
<div id="tab0" class="tab">
<h2>Tests</h2>
<table>
<thead>
<tr>
<th>Test</th>
<th>Duration</th>
<th>Result</th>
</tr>
</thead>
<tr>
<td class="success">testTwo()</td>
<td class="success">0.080s</td>
<td class="success">passed</td>
</tr>
</table>
</div>
<div id="tab1" class="tab">
<h2>Standard output</h2>
<span class="code">
<pre>3
6
9
12
15
5
10
7
14
</pre>
</span>
</div>
</div>
<div id="footer">
<p>
<div>
<label class="hidden" id="label-for-line-wrapping-toggle" for="line-wrapping-toggle">Wrap lines
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
</label>
</div>Generated by
<a href="http://www.gradle.org">Gradle 7.5.1</a> at May 12, 2023, 1:49:03 PM</p>
</div>
</div>
</body>
</html>
16 changes: 16 additions & 0 deletions build/test-results/test/TEST-sbu.cs.FindMultiplesTest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="sbu.cs.FindMultiplesTest" tests="1" skipped="0" failures="0" errors="0" timestamp="2023-05-12T09:19:02" hostname="HAMIDSURFACE" time="0.08">
<properties/>
<testcase name="testTwo()" classname="sbu.cs.FindMultiplesTest" time="0.08"/>
<system-out><![CDATA[3
6
9
12
15
5
10
7
14
]]></system-out>
<system-err><![CDATA[]]></system-err>
</testsuite>
Binary file added report6.pdf
Binary file not shown.
53 changes: 50 additions & 3 deletions src/main/java/sbu/cs/CPU_Simulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

/*
Expand All @@ -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);

}
}
}

Expand All @@ -43,12 +64,38 @@ Here the CPU selects the next shortest task to run (also known as the
*/
public ArrayList<String> startSimulation(ArrayList<Task> tasks) {
ArrayList<String> executedTasks = new ArrayList<>();
ArrayList<Long> processingTimes=new ArrayList<>();
ArrayList<Task> 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) {
}
}
128 changes: 127 additions & 1 deletion src/main/java/sbu/cs/FindMultiples.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
ArrayList<Integer>total=new ArrayList<>();
ArrayList<Integer> counter3 = new ArrayList<>();
ArrayList<Integer> counter5 = new ArrayList<>();
ArrayList<Integer> 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.

Expand All @@ -30,13 +106,63 @@ 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

return sum;
}

public static void main(String[] args) {



}
}