-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.md.bak
162 lines (132 loc) · 5.32 KB
/
README.md.bak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
## Gas Station Employee Simulation
This project simulates an employee at a gas station performing various tasks such as refueling cars, cleaning windshields, and inflating tires. It demonstrates the use of Java threads to handle multiple concurrent activities, ensuring realistic simulation of an employee's tasks at a gas station.
### Description
The Gas Station Employee Simulation project uses Java's multithreading capabilities to simulate an employee performing various tasks at a gas station. The main class, `Empleado`, contains multiple threads representing different tasks, ensuring they are executed concurrently and synchronized to mimic real-life scenarios at a gas station.
### Features
- **Multithreading:** Utilizes Java's threading capabilities to manage concurrent tasks.
- **Synchronization:** Ensures conflicting actions are not performed simultaneously.
- **Simulation:** Creates a realistic scenario of a gas station employee's tasks using print statements to represent the employee's actions.
### File Structure
- **GasStationSim/**: Root directory containing project files and directories.
- **pom.xml**: Maven Project Object Model file containing project configuration.
- **src/main/java/**: Source directory containing Java source files.
- **PemexSimulator.java**: Main Java source file for the project.
- **target/**: Directory containing compiled classes and build related files.
- **classes/**: Compiled class files.
- **.netbeans_automatic_build**: NetBeans automatic build indicator file.
- **Empleado.class**: Compiled bytecode of the Empleado class.
- **PemexSimulator.class**: Compiled bytecode of the PemexSimulator class.
- **maven-status/maven-compiler-plugin/compile/default-compile/**: Maven compiler plugin status files.
- **createdFiles.lst**: List of files created during the build process.
- **inputFiles.lst**: List of input files for the build process.
- **test-classes/**: Directory for compiled test classes.
- **.netbeans_automatic_build**: NetBeans automatic build indicator file for test classes.
### Main Classes and Methods
#### Empleado Class
This class simulates an employee performing various tasks at a gas station, utilizing multiple threads to handle different actions.
**Constructor:**
```java
public Empleado() {
this.hiloLlenarTanquePrincipal = new Thread(this::LlenadoPrincipal);
this.hiloLlenarTanque= new Thread(this::llenarTanque);
this.hiloLimpiarParabrisas = new Thread(this::limpiarParabrisas);
this.hiloLimpiarParabrisas2 = new Thread(this::limpiarParabrisas);
this.hiloLlenarLlantas = new Thread(this::llenarLlantas);
}
```
Initializes the threads for various actions.
**Start Method:**
```java
public void start() {
this.hiloLlenarTanquePrincipal.start();
}
```
Starts the main refueling thread, which sequentially manages other tasks.
**LlenadoPrincipal Method:**
```java
private synchronized void LlenadoPrincipal() {
try {
// Simulation of refueling and other tasks
System.out.println("Un auto solicita llenado de tanque completo ($1200MXN)");
System.out.println("LLENANDO TANQUE PRINCIPAL");
Thread.sleep(1000);
// Additional tasks
} catch (InterruptedException e) {
e.printStackTrace();
}
}
```
Manages the main refueling process and coordinates with other threads.
**LimpiarParabrisas Method:**
```java
private void limpiarParabrisas() {
int cont = 0;
while (cont < 3) {
if (accionLimpiarParabrisas) {
if(x == 1){
System.out.println("\tLimpiando parabrisas...");
} else {
System.out.println("\t\t\tLimpiando parabrisas...");
}
try {
Thread.sleep(1000);
cont++;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
```
Simulates the process of cleaning windshields.
**LlenarTanque Method:**
```java
private void llenarTanque() {
int cont = 0;
while (cont < 3) {
if (accionLlenadoTanque) {
System.out.println("\t\tLlenando tanque...");
try {
if(cont == 0){
Thread.sleep(10000);
} else {
Thread.sleep(1000);
}
cont++;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
```
Simulates the process of refueling a car.
**LlenarLlantas Method:**
```java
private void llenarLlantas() {
int cont = 0;
while (cont < 4) {
if(accionLlenadoLlantas){
System.out.println("\t\t\tInflando llanta...");
try {
Thread.sleep(1000);
cont++;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
```
Simulates the process of inflating tires.
### Getting Started
To run the simulation, compile the Java files and execute the `PemexSimulator` class.
### Requirements
- Java Development Kit (JDK)
- Maven for managing project dependencies
- An IDE or text editor for Java development
### Usage
1. Clone the repository.
2. Navigate to the project directory.
3. Compile the Java files using `mvn compile`.
4. Run the simulation using `mvn exec:java -Dexec.mainClass="PemexSimulator"`