Commit 8c848e4a authored by Lenovo's avatar Lenovo

second step

parent eed9bea9
......@@ -4,15 +4,27 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="2698c064-0a25-4fa9-b373-a085833ed750" name="Changes" comment="" />
<list default="true" id="2698c064-0a25-4fa9-b373-a085833ed750" name="Changes" comment="first step">
<change afterPath="$PROJECT_DIR$/src/main/java/org/example/summers/Summer.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2YDqGbLJfns60iFSnvDoXlK7JEf" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
......@@ -22,7 +34,8 @@
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true"
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true"
}
}]]></component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
......@@ -34,6 +47,29 @@
<option name="presentableId" value="Default" />
<updated>1700070404526</updated>
</task>
<task id="LOCAL-00001" summary="first step">
<created>1700070627028</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1700070627028</updated>
</task>
<option name="localTasksCounter" value="2" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="first step" />
<option name="LAST_COMMIT_MESSAGE" value="first step" />
</component>
</project>
\ No newline at end of file
package org.example.summers;
import org.example.worker.Worker;
import org.example.worker.WorkPartitioner.Part;
import java.util.ArrayList;
import java.util.List;
/*
The Summer class is where the primary functions are established.
These functions will be utilized in the future.
*/
public class Summer extends Worker {
protected long sum;
public List<Integer> getPrimes() {
return primes;
}
private List<Integer> primes = new ArrayList<>();
public Summer(int[] data, Part part) {
super(data, part);
}
public long getSum() {
return sum;
}
}
package org.example.summers;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import org.example.worker.Worker;
import org.example.worker.WorkPartitioner.Part;
/*
The SummerCallable class is a child of the Summer class and implements the Callable interface.
This class includes a call function that computes the count of prime numbers.
*/
public class SummerCallable extends Summer implements Callable<Long> {
public SummerCallable(int[] data, Part part) {
super(data, part);
}
@Override
public Long call() throws Exception {
this.sum = 0;
List<Integer> primes = new ArrayList<>();
for (int i = start; i < finish; i++) {
if (isPrime(data[i])) {
primes.add(data[i]);
sum ++;
}
}
return sum;
}
private static 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
package org.example.summers;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import org.example.worker.WorkPartitioner.Part;
/*
The SummerRunnable class is a child of the Summer class and implements the Runnable interface.
This class includes a run function that computes the count of prime numbers.
*/
public class SummerRunnable extends Summer implements Runnable{
private Thread thread;
private List<Integer> primes = new ArrayList<>();
public SummerRunnable(int[] data, Part part) {
super(data, part);
}
@Override
public void run() {
sum = 0;
for (int i = start; i < finish; i++) {
if (isPrime(data[i])) {
primes.add(data[i]);
sum++;
}
}
}
public void startThread() {
thread = new Thread(this);
thread.start();
}
public void joinThread() throws InterruptedException {
thread.join();
}
private static 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;
}
@Override
public List<Integer> getPrimes() {
return primes;
}
public long getSum() {
return sum;
}
}
\ No newline at end of file
package org.example.summers;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.example.worker.WorkPartitioner.Part;
/*
The SummerThread class is a child of the Thread class.
This class includes a run function that computes the count of prime numbers.
*/
public class SummerThread extends Thread{
private int start;
private int finish;
private int[] data;
private long sum;
private List<Integer> primes = new ArrayList<>();
public SummerThread(int[] data, int start, int finish) {
this.start = start;
this.finish = finish;
this.data = data;
}
public SummerThread(int[] data, Part part) {
this(data, part.getStart(), part.getFinish());
}
@Override
public void run() {
sum = 0;
for (int i = start; i < finish; i++) {
if (isPrime(data[i])) {
primes.add(data[i]);
sum++;
}
}
}
public long getSum() {
return sum;
}
public List<Integer> getPrimes() {
return primes;
}
private static 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
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