Git Product home page Git Product logo

roller-coaster's Introduction

Roller Coaster Problem

Description

This is a work from the Concurrent Programming course in which two solutions were implemented using different methods of synchronization. The methods used to solve the problem were implicit locks - with monitor implementation - and explicit locks.

Problem

A roller coaster with only one car

A roller coaster is a popular attraction of amusement parks and modern theme parks. It consists of a steel structure forming a trail made up of elevations followed by falls and, sometimes, inversions. Most of the roller coasters have several cars in which passengers sit and are restrained (obviously for safety reasons), while some work with a single car and a larger number of passengers.

Suppose a roller coaster that has a single car with capacity for C passengers. Passengers, in a total of n (n > C), often wait to get into the car, which can only be allowed to enter the trail when it is full. After completing a ride, each passenger strolls through the amusement park before returning to the roller coaster to try to enter on another ride. For safety reasons, the car carries out only P tours per day and, once reached that number, it is turned off.

Design and implement a program that simulates the operation of a roller coaster meeting the following requirements:

  • the car allows the entry of exactly C passengers;
  • no passenger can enter the car while it is moving on the track;
  • no passenger can jump off from the car while it is moving on the track;
  • no passenger can enter the car again without first leaving it.

During the execution of the program, the following actions must be performed for each entity:

  • the actions carried out by passengers are boarding and unloading (unboarding) of the car;
  • the car allows the entry (load) and exit (unload) of passengers;
  • the car movement is started by executing the run operation;
  • passengers cannot enter the car until the load operation is performed by the car;
  • the car cannot start its movement until all the passengers have entered;
  • passengers cannot leave the car until the unload operation is performed by the car.
  • the time each passenger walks through the park before going back to the roller coaster is random and different on each run of the program.

For readability purposes, the program shall display on the standard output the execution of each of the operations performed by the passengers and the car. The total number of passengers n, the capacity of car C, and the maximum number of P-trips that can be performed per day should be provided as input to the program as command line arguments. Case C < n, the program should show an error message to the user and be immediately shut down.

Compiling and Running

We usually use an IDE (like NetBeans or Eclipse) to compile and build the program, but if you want to compile via terminal use the following commands.

Dependencies

  • Java 8.0 or greater

Roller Coaster Monitor

Open the project folder:

cd RollerCoasterMonitor

How to compile

Run the following commands:

./make.sh
make.sh content
#!/bin/bash
cd src
# Compile
javac rollercoastermonitor/*.java rollercoastermonitor/rollercoaster/*.java
# Generate jar
jar cfm ../RollerCoasterMonitor.jar ../manifest.mf rollercoastermonitor/*.class rollercoastermonitor/rollercoaster/*.class

How to run

java -jar RollerCoasterMonitor.jar

Roller Coaster Lock

Open the project folder:

cd RollerCoasterLock

How to compile

Run the following commands:

./make.sh
make.sh content
#!/bin/bash
cd src
# Compile
javac rollercoasterlock/*.java rollercoasterlock/rollercoaster/*.java
# Generate jar
jar cfm ../RollerCoasterLock.jar ../manifest.mf rollercoasterlock/*.class rollercoasterlock/rollercoaster/*.class

How to run

java -jar RollerCoasterLock.jar

Team

Breno Viana Patrícia Cruz

roller-coaster's People

Contributors

brenomfviana avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.