Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Teemu Auvinen
DTEK1066-ryhmis
Commits
bfbe13ac
Commit
bfbe13ac
authored
Dec 09, 2017
by
Jyrki Moisala
Browse files
Update Answer.java
lisäsin fsummain +1 jutun ja thread sleepin
parent
e222a105
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/fi/utu/dtek1066/Answer.java
View file @
bfbe13ac
...
...
@@ -22,7 +22,11 @@ public class Answer implements Runnable {
public
void
run
()
{
// Vastataan asianomaisesti Y:n tiedusteluun
if
(
this
.
request
==
1
)
{
// Tutkitaan palvelimen pyyntö. Jos 1:
int
fsum
=
0
;
// Määritellään final sum, eli lopullinen summa johon halutaan sums[]-taulukon
try
{
Thread
.
sleep
(
1000
);
}
catch
(
Exception
e
)
{
}
int
fsum
=
0
;
// Määritellään final sum, eli lopullinen summa johon halutaan sums[]-taulukon
// alkioiden summa
for
(
int
i
=
0
;
i
<
this
.
t
;
i
++)
{
//
fsum
+=
this
.
sums
[
i
];
// Lisätään jokaisen summainpalvelimen sums[]-alkio fsumiin niin
...
...
@@ -35,6 +39,10 @@ public class Answer implements Runnable {
}
//
}
else
if
(
this
.
request
==
2
)
{
// Jos pyyntö 2:
try
{
Thread
.
sleep
(
1000
);
}
catch
(
Exception
e
)
{
}
int
fsummain
=
0
;
// Oletetaan summaimen 0 sums[]-alkio suurimmaksi
for
(
int
i
=
1
;
i
<
this
.
t
;
i
++)
{
// tutkitaan jokaisen muun summaimen sums[]-alkio
if
(
this
.
sums
[
i
]
>
this
.
sums
[
fsummain
])
{
...
...
@@ -42,12 +50,17 @@ public class Answer implements Runnable {
}
}
//
try
{
//
fsummain
=
fsummain
+
1
;
this
.
out
.
writeInt
(
fsummain
);
// Lähetetään tulos Y:lle
this
.
out
.
flush
();
// Puhdistetaan kirjoitusvirta.
}
catch
(
IOException
e
)
{
// Ei käsitellä mahdollista virhettä
}
//
}
else
if
(
this
.
request
==
3
)
{
// Jos pyyntö 3:
try
{
Thread
.
sleep
(
1000
);
}
catch
(
Exception
e
)
{
}
int
famount
=
0
;
// Määritellään final amount kuten pyynnöllä 1 final sum
for
(
int
i
=
0
;
i
<
this
.
t
;
i
++)
{
//
famount
+=
this
.
amounts
[
i
];
// Lisätään vastaavasti famountin arvoa jokaisen summaimen
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment