Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Hi, im begginer in java

  1. #1
    Junior Member
    Join Date
    May 2021
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Hi, im begginer in java

    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.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Hi, im begginer in java

    Do you have any questions?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. java begginer
    By Mphilele in forum The Cafe
    Replies: 0
    Last Post: September 17th, 2014, 07:22 AM
  2. Looking for Java Books/Videos for absolute begginer
    By marko245 in forum Java Theory & Questions
    Replies: 1
    Last Post: August 5th, 2014, 11:57 AM
  3. Java help with Methods (Begginer)
    By maddiexc in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 15th, 2013, 10:53 PM
  4. Java Help for a begginer
    By miller4103 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 15th, 2013, 09:00 PM
  5. Begginer Java - Bug in my code?
    By rk2010 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: March 7th, 2012, 08:12 AM

Tags for this Thread