Hello everybody, i am stuck on a problem in Java.I need helppppp
import java.util.concurrent.ThreadLocalRandom;
class Entry extends Thread{
private int Entry;
public void run() {
Thread thread = new Thread();
if(getEntry() > 3) {
try {
thread.wait(5000);
} catch (InterruptedException e) {
System.err.println("Exceeded entry " + e.getMessage());
}
}
}
public int getEntry() {
return Entry;
}
public void setEntry(int Entry) {
this.Entry = Entry;
}
}
class Exit extends Thread {
private int Exit;
public void run() {
Thread thread2 = new Thread();
if(getExit() > 1) {
try {
thread2.wait(5000);
} catch(InterruptedException e) {
System.err.println("Exceeded exit " + e.getMessage());
}
}
}
public int getExit() {
return Exit;
}
public void setExit(int Exit) {
this.Exit = Exit;
}
}
public class Parking extends Exit {
private int Parking;
public void run() {
Thread thread2 = new Thread();
if(getParking() > 10) {
try {
thread2.wait(5000);
} catch(InterruptedException e) {
System.err.println("Exceeded Parking " + e.getMessage());
}
}
}
private int getParking() {
// TODO Auto-generated method stub
return 0;
}
private int sum = ThreadLocalRandom.current().nextInt(3);
public int Entry(int Entry) {
sum = Entry + sum;
System.out.println("- A car came in entry " +".In Parking are: " + sum + " cars");
return sum;
}
public int getsum() {
return sum;
}
public void setsum(int sum) {
this.sum = sum;
}
public int Exit(int extras) {
sum = getsum() - extras;
System.out.println("- A car came out" + ".In Parking are: " + sum + " cars");
return extras;
}
public static class Main extends Entry{
public static void main(String[] args) {
Parking parc= new Parking();
System.out.println(parc.Entry(1));
System.out.println(parc.Entry(1));
System.out.println(parc.Entry(1));
System.out.println(parc.Exit(1));
System.out.println(parc.Entry(1));
System.out.println(parc.Entry(1));
System.out.println(parc.Exit(1));
System.out.println(parc.Entry(1));
System.out.println(parc.Exit(1));
System.out.println(parc.Entry(1));
System.out.println(parc.Entry(1));
}
}
}
The car parking has 10 spaces, 3 entrances and one exit. 4 operations can be performed simultaneously: 3 cars can enter and one can leave
car in / from the parking lot. Each operation will be performed in a thread.the Parking class is created, with member variables total number of places
and number of seats occupied, variables that are initialized by the constructor. The class will have a synchronized method for simulating the input of a machine, which accepts as a parameter input input number. As long as there are no places available, a place is expected to be vacated.When there are places available, the car enters the parking lot and the number of occupied places increases. itdisplays an appropriate message. There will also be a synchronized method for
simulating the output of a car, which decrements the number of seats occupied and displays a corresponding message. All changes in the number of seats occupied are accompanied by notifications which the threads transmit. The Input class is created that represents the manufacturer and
Output class that represents the consumer. These classes therefore correspond to threads extend the Thread class and redefine the run method. The main thread creates the 4 threads and passes them in the ready-to-run state.