Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
first_git
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
areej.mohammad
first_git
Commits
4e884139
Commit
4e884139
authored
Nov 03, 2025
by
areej.mohammad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
I added src
parents
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
135 additions
and
0 deletions
+135
-0
AscendingHackerThread.java
src/hackingrace/AscendingHackerThread.java
+17
-0
DescendingHackerThread.java
src/hackingrace/DescendingHackerThread.java
+17
-0
HackerThread.java
src/hackingrace/HackerThread.java
+22
-0
PoliceThread.java
src/hackingrace/PoliceThread.java
+29
-0
Vault.java
src/hackingrace/Vault.java
+22
-0
VaultHackingRace.java
src/hackingrace/VaultHackingRace.java
+28
-0
No files found.
src/hackingrace/AscendingHackerThread.java
0 → 100644
View file @
4e884139
package
hackingrace
;
public
class
AscendingHackerThread
extends
HackerThread
{
public
AscendingHackerThread
(
Vault
vault
){
super
(
vault
,
"Ascending Hacker"
);
}
@Override
public
void
run
(){
for
(
int
guess
=
0
;
guess
<=
9999
;
guess
++)
{
if
(
vault
.
isCorrectPassword
(
guess
)){
onHacked
(
guess
);
}
}
}
}
src/hackingrace/DescendingHackerThread.java
0 → 100644
View file @
4e884139
package
hackingrace
;
public
class
DescendingHackerThread
extends
HackerThread
{
public
DescendingHackerThread
(
Vault
vault
){
super
(
vault
,
"Descending Hacker"
);
}
@Override
public
void
run
(){
for
(
int
guess
=
10000
;
guess
>=
0
;
guess
--)
{
if
(
vault
.
isCorrectPassword
(
guess
)){
onHacked
(
guess
);
}
}
}
}
src/hackingrace/HackerThread.java
0 → 100644
View file @
4e884139
package
hackingrace
;
public
abstract
class
HackerThread
extends
Thread
{
protected
final
Vault
vault
;
public
HackerThread
(
Vault
vault
,
String
name
)
{
super
(
name
);
this
.
vault
=
vault
;
}
@Override
public
abstract
void
run
();
protected
void
onHacked
(
int
password
){
System
.
out
.
printf
(
"*** % WINS! The vault has been hacked with password: %d ****\n"
,
this
.
getName
(),
password
);
System
.
exit
(
0
);
}
}
src/hackingrace/PoliceThread.java
0 → 100644
View file @
4e884139
package
hackingrace
;
public
class
PoliceThread
extends
Thread
{
public
PoliceThread
(){
super
(
"Police"
);
}
@Override
public
void
run
(){
for
(
int
i
=
10
;
i
>=
0
;
i
--)
if
(
i
>
0
)
{
System
.
out
.
printf
(
"Police arrive in %d seconds...\n"
,
i
);
}
else
{
// عند الوصول إلى 0، تفوز الشرطة [cite: 23, 31]
System
.
out
.
println
(
"\n**************************************************"
);
System
.
out
.
println
(
"Game over for you hackers! Police have arrived."
);
System
.
out
.
println
(
"**************************************************"
);
// يُنهي البرنامج بالكامل [cite: 23, 57]
System
.
exit
(
0
);
}
try
{
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
){
return
;
}
}
}
src/hackingrace/Vault.java
0 → 100644
View file @
4e884139
package
hackingrace
;
import
java.util.Random
;
public
class
Vault
{
private
final
int
correctpassword
;
public
Vault
(){
this
.
correctpassword
=
new
Random
().
nextInt
(
10000
);
}
public
boolean
isCorrectPassword
(
int
gusses
)
{
try
{
Thread
.
sleep
(
5
);
}
catch
(
InterruptedException
e
){
Thread
.
currentThread
().
interrupt
();
}
return
gusses
==
this
.
correctpassword
;
}
}
src/hackingrace/VaultHackingRace.java
0 → 100644
View file @
4e884139
package
hackingrace
;
public
class
VaultHackingRace
{
public
static
void
main
(
String
[]
args
){
Vault
vault
=
new
Vault
();
Thread
ascendingHacker
=
new
AscendingHackerThread
(
vault
);
Thread
descendingHacker
=
new
DescendingHackerThread
(
vault
);
Thread
policeThread
=
new
PoliceThread
();
// 3. يستخدم أولوية Thread.MAX_PRIORITY لنياسب القراصنة [cite: 28, 45]
ascendingHacker
.
setPriority
(
Thread
.
MAX_PRIORITY
);
descendingHacker
.
setPriority
(
Thread
.
MAX_PRIORITY
);
// نيسب الشرطة يعمل بالأولوية الافتراضية (عادةً NORM_PRIORITY)
// 4. يُطلق النياسب الثلاثة في نفس الوقت [cite: 27]
policeThread
.
start
();
ascendingHacker
.
start
();
descendingHacker
.
start
();
System
.
out
.
println
(
"--- Vault Hacking Race Started ---"
);
System
.
out
.
println
(
"Two hackers are competing to find the password (0-9999)."
);
System
.
out
.
println
(
"Police arrive in 10 seconds. Hackers have MAX_PRIORITY."
);
System
.
out
.
println
(
"------------------------------------"
);
// البرنامج ينتظر حتى يُنهي System.exit(0)
}
}
Write
Preview
Markdown
is supported
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