Using Queues To Simulate Airport Operation

Nov 13, 2014

*Write a program to simulate this airport's operation. You might assume a simulated clock that advances in one-minute intervals. For each minute, generate two random numbers: If the first in less than LandingTime /60, a "landing arrival" has occurred and is added to the landing queue, and if the second is less than TakeOffTime /60, a "takeoff arrival" has occurred and is added to the takeoff queue*.

*Next, check whether the runway is free. If it is, first check whether the landing queue is nonempty, and if so, allow the first plane to land; otherwise, consider the takeoff queue. Have the program calculate the average queue length and the average time that an airplane spends in a queue.*

I have most of the code done as you can see below:

* Queue Interface: Queue.java
* Queue Implementation: ArrayQueue.java
* Demo Program: Airport.java

Right now, I am stuck on the first calculation which is trying to figure out the average size of the landing queue. For some reason, as you can see at the bottom of my demo program, the average always comes out to be 0.0 and I'm not sure what's wrong.

Secondly, how to calculate the average time a plane stays inside a queue for. Write a program to simulate this airport's operation. You might assume a simulated clock that advances in one-minute intervals. For each minute, generate two random numbers: If the first in less than LandingTime /60, a "landing arrival" has occurred and is added to the landing queue, and if the second is less than TakeOffTime /60, a "takeoff arrival" has occurred and is added to the takeoff queue.

Next, check whether the runway is free. If it is, first check whether the landing queue is nonempty, and if so, allow the first plane to land; otherwise, consider the takeoff queue. Have the program calculate the average queue length and the average time that an airplane spends in a queue.

I have most of the code done as you can see below:

* Queue Interface: Queue.java
* Queue Implementation: ArrayQueue.java
* Demo Program: Airport.java

Right now, I am stuck on the first calculation which is trying to figure out the average size of the landing queue. For some reason, as you can see at the bottom of my demo program, the average always comes out to be 0.0 and I'm not sure what's wrong.

Secondly, how to calculate the average time a plane stays inside a queue for.

View Replies


ADVERTISEMENT

Using Queues To Simulate Airport

Nov 2, 2014

Suppose that a certain airport has one runway, that each airplane takes LandingTime minutes to land and TakeOffTime minutes to take off, and that on the average, TakeOffTime planes take off and LandingTime planes land each hour.

Assume that the planes arrive at random instants of time. (Delays make the assumption to randomness quite reasonable.) There are 2 types of queues: a queue of airplanes waiting to land and a queue of airplanes waiting go take off. Because it is more expensive to keep a plane airborne than to have one waiting on the ground, we assume that the airplanes in the landing queue have priority over those in the take off queue.

Write a program to simulate this airport's operation. You might assume a simulated clock that advances in one-minute intervals. For each minute, generate two random numbers: If the first in less than LandingTime /60, a "landing arrival" has occurred and is added to the landing queue, and if the second is less than TakeOffTime /60, a "takeoff arrival" has occurred and is added to the takeoff queue. Next, check whether the runway is free. If it is, first check whether the landing queue is nonempty, and if so, allow the first plane to land; otherwise, consider the takeoff queue. Have the program calculate the average queue length and the average time that an airplane spends in a queue. You might also investigate the effect of varying arrival and departure rates to simulate the prime and slack times of day, or what happens if the amount of time to land or takeoff is increased or decreased.

My Queue Interface: [URL] ....
My Queue Implementation: [URL] ....
My Demo (Main Method) Program: [URL] ....

Right now, I'm struggling with the demo program. I wrote some pseudocode in which I tried to match what the instructions were asking:

for(each minute) {
rand1 = generator.nextInt();
rand2 = generator.nextInt();
if(rand1 < LANDING_RATE / 60)
Add to the landing queue
if(rand2 < TAKE_OFF_RATE/60)

[Code] .....

Firstly, exactly how many minutes am I supposed to be doing this for? The assignment gave me a variable called final int ITERATIONS = 1440 , could that have something to do with how long I loop? Secondly, what exactly do I add to the queue if the conditions are true. For example, if rand1 < LANDING_RATE/60, what would I enqueue to the landingQueue? Thirdly, how am I supposed to check if the runway is free? Does that mean check to see whether the takeOffQueue is empty or not? Fourth, would allowing the first plane to land mean removing an item from the landingQueue? Also, what does it mean by "otherwise, consider the takeoff queue". Does that mean if the landingQueue is empty, I should start removing items from the takeOff queue?

The biggest problem is the fact that I have to calculate the average queue length and average time that an airplane spends in a queue.

View Replies View Related

Simulate Airport - Calculate Average Time A Plane Stays Inside A Queue For

Nov 13, 2014

Write a program to simulate this airport's operation. You might assume a simulated clock that advances in one-minute intervals. For each minute, generate two random numbers: If the first in less than LandingTime /60, a "landing arrival" has occurred and is added to the landing queue, and if the second is less than TakeOffTime /60, a "takeoff arrival" has occurred and is added to the takeoff queue.

Next, check whether the runway is free. If it is, first check whether the landing queue is nonempty, and if so, allow the first plane to land; otherwise, consider the takeoff queue. Have the program calculate the average queue length and the average time that an airplane spends in a queue.

I have most of the code done as you can see below:

* Queue Interface: Queue.java
* Queue Implementation: ArrayQueue.java
* Demo Program: Airport.java

Right now, I am stuck on the first calculation which is trying to figure out the average size of the landing queue. For some reason, as you can see at the bottom of my demo program, the average always comes out to be 0.0 and I'm not sure what's wrong.

Secondly, how to calculate the average time a plane stays inside a queue for.

View Replies View Related

Program To Simulate Operation Of Simple Robot

Apr 26, 2015

Write a program to simulate the operation of a simple robot. The robot moves in four directions: Forward, backwawrd, left, and right. The job of the robot is to move items and place it in the right slots in each station. There are 8 stations plus the pickup station. Pick up station is the initial start where the robot picks the items. 8 items can be placed on each station. The nearest station must be filled before placing items on the next station. The items are marked with identification or serial numbers. The items with odd serial number go to the right and items with even number go to the eft. The last slot, number 7 is reserved for light items which are less than 80kg. The serial number is a five digit number, the MSB digit 5 indicates that the product must be placed in the fifth station which is keeping the product at 20 degree F.

View Replies View Related

Queues - Reading And Counting

Jul 21, 2014

Here's what I'm trying to do:

Complete the body of the following method. Use a CharQueue to store the input line as it is being read. The parameter is an EasyReader from Appendix B of the text. Use the method in.charInput( ) to read and return the next character of the EasyReader, and use in.isEOLN( ) to determine whether the next input character is the end-of-line.

public static int counter(EasyReader in)
// Precondition: There is a line of input waiting to be read from in.
// Postcondition: A line of input has been read from in, up to but not
// including the newline character. The return value of the method
// is the number of times that the LAST character of the line appeared
// somewhere in this line.

[EXAMPLE Input: ABBXDXXZX - The value returned by counter would be 4 for this input since there are 4 X's in the input line.]

***When I look at this I understand that I'm being asked to finish the method, that I have 1 input, which is an "EasyReader" object called in and that I use a CharQueue object along with the method isEOLN( ) to grab characters from in while looking for an end of line and then sticking the values in the queue and then I can go through the queue and figure out the number of times that last character shows up in the queue. I just am at a loss on the "how".

View Replies View Related

Stacks And Priority Queues Project

Feb 21, 2014

So I have 3 classes in this project, and When it compiles, I get a null pointer.

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class Project2 {
 
[Code] .....

View Replies View Related

Queues - IsEmpty Method Only Returns False

Jan 29, 2015

My isEmpty method only returns false. Is something wrong? I printed the empty and not empty for testing purposes.

//determines if there are any items in the queue
public boolean isEmpty() {
if (front == -1 && rear == -1) {
System.out.println("empty");
return true;
} else {
System.out.println("not empty");
return false
}
}

View Replies View Related

Palindrome Program - Java Stack And Queues

Aug 13, 2014

I am trying to figure out stacks and queues and was trying to get this Palindrome program working so I could then play with it and use the Java visualizer site but for some reason the program isn't working correctly. It always states that the input is a palindrome no matter what the user input is.

The book that I got the code from is a little old so I changed a couple small things that I thought needed updating like adding scanner. I wanna use one with a custom array based stack and queue class rather than the java.util.Stack and Queue interface, just for understanding stacks and queues better hopefully.

import java.util.Scanner;
import javax.imageio.IIOException;
public class PalTest {
public static void main(String[]args) throws IIOException
{
Scanner scan = new Scanner(System.in);
PalindromeTesting x = new PalindromeTesting();

[Code] .....

View Replies View Related

Simulate Rolling Two Dice

Oct 18, 2014

Write a method called statistic that simulates the rolling of two dice 1000 times. (1000 times is a parameter of the method statistic).The program should have no input, and should use pseudo random numbers to simulate the rolls (one random number per die). Store the sum resulting from each roll of two dice, determine the number of times each 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, and 12 was rolled. The out produced by the program is:

Sum 2 3 4 5 6 7 8 9 10 11 12
Total 33 49 93 103 127 159 150 124 85 49 28

This is my code:

public static void main(String[] args) {
statistic(1000);
}
public static void statistic(int number) {
Random randomNumbers = new Random();

[code]...

i have been trying for hours to make it look like the output above but no luck. I was wondering if there's any other way writing the code without using arrays.

View Replies View Related

Applets :: Simulate Stack - Using Push / Pop

May 10, 2014

I have designed an applet to simulate a stack (last-in, first-out) of strings. The applet consists of:

Two JButtons
Two JTextFields
Two JLabels
A TextArea

The user enters text in the first text field then clicks the push button and it goes in the textArea. After entering several strings the user can click the pop button and the top string goes into the second text field. I am a total newbie and am stuck. I can get a string of text to push to the textArea and then pop it out; however I can't stack them LIFO. Most examples I've seen use integers and I'm not sure how to translate the concept to strings. I'm just not sure how the stack concept works even though I read the API webpage.

My code

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JApplet;
import javax.swing.JButton;

[Code] ....

View Replies View Related

Code A Program To Simulate Rolling Of 2 Dice

Jul 1, 2014

my assignment is to code a program to simulate the rolling of 2 dice. I have most of it set but when I run it and have it print out how many times each number (2-12) was rolled, it displays the numbers 1 off. for instance it will display the number of 4s rolled next to the 5s.

here it is

import java.util.Scanner; //allows info to be inputted//
import java.util.Random; //opens random number generator//
public class RollTheDiceWithArray13
{
 
public static void main(String[] args)

[code]....

View Replies View Related

Java Program To Simulate Rolling Of Two Dice?

Feb 25, 2015

Write a program to simulate the rolling of two dice. The program should use Math.random (google how to use Math.random if needed) to roll the first die and should use Math.random again to roll the second die. The sum of the two values should then be calculated your program should roll 50,000 times. Use a single dimensional array to tally the numbers of times each possible sum appear(the possible values are 2 through 12, think about why?). Print the results in a tabular format.

Here's the code I'm working on so far:

public class RollingDice{
public static void main(String[] args){
int die1;
int die2;
int roll;
die1 = (int)(Math.random()*6) + 1;
die2 = (int)(Math.random()*6) + 1;
roll = die1 + die2;
System.out.println("The roll of the first dice is: " + die1);
System.out.println("The roll of the second dice is: " + die2);
System.out.println("Your total roll is: " + roll);
}
}

What am I missing at this point, and what parts did I do wrong to change it?

View Replies View Related

Create And Simulate ATM Interface Using Scanner Class

Sep 28, 2014

I need to create and simulate an ATM interface for my computer programming class using scanner class, if else & switch statements. I've been working on this assignment all day and I'm still no closer to figuring out how to do it. I'm currently working in NetBeans to try and solve it. I have attached the pdf , what I need to do. This is what I have so far:

package bankatmifelse;
//Gator Bank ATM Program
import java.util.Scanner;
public class BankATMIfElse {

[code]...

View Replies View Related

Simulate Press Of Space Button Every 15 Minutes

Jul 1, 2014

I'm on windows 8 and I want to use notepad or notepad++ to simulate the press of the space bar every 15 minutes so my computer doesn't auto lock.

View Replies View Related

Simulate Rolling Dice - Int Values Representation

Jan 20, 2015

import java.util.Random;
/**
* A very basic Dice that can be rolled and represent int values
*/

public class Dice{
private Random rand;
public Dice(){
rand=new Random();
}
/**simulates rolling the dice*/

[Code] ....

Why the Random rand is initiated at the Constructor and not at roll? Like the code works for both but I remember our teacher telling us something about one uses more memory than the other.

View Replies View Related

Operation With Strings

May 6, 2014

I have to write a java programm,where i have given string. Output should be like that:

1. print only once what characters are apearinng in string, and the last index of it

2. print how many characters are in the string

I have to do it only with loops,no special classes

So far:

public static void main( String[] args ) {
String besedilo = "Testiranje";
besedilo = besedilo.toLowerCase();
for (int i=0; i<besedilo.length();i++)

[code]...

View Replies View Related

Simulate Simple Calculator That Performs Basic Arithmetic Operations Of JAVA

Sep 9, 2014

How can i write a java program that simulate a simple calculator that performs the basic arithmetic operations of JAVA. (JOption Pane and Repeat control structure)

Example : Addition, Subtraction, Multiplication, Division.

The program will prompt to input two floating point numbers and a character that represents the operations presented above. In the event that the operator input is valid, prompt the user to input the operator again.

Sample Output :

First number 7
Second number 4
Menu

<+> Addition
<-> Subtraction
<*> Multiplication
</> Division

Enter Choice: * <enter>

The answer is 28.

View Replies View Related

Mathematical Operation On Bytes

Jan 28, 2015

byte a1 = 0;
byte a2 = 4
byte a3 = 4;

//below statement gives a compilation error
a1 = a2 + a3;

//below line compiles fine.
a1 = 4 + 4;

View Replies View Related

String To Math Operation

Sep 14, 2014

Given a string of numbers and operator. Compute as follows:

Consider, "000293000002030403+0400293059694" is the input.

a. Separate the two operands and one operator:
"000293000002030403" "+" "0400293059694"

b. On each string operand, take each digit. ADD them all.
(2+9+3+2+3+4+3) + (4+2+9+3+5+9+6+9+4)
The two string operands should now become two integers.

c. Lastly, perform the operation using the string operator specified on the original string.
26 + 51 = 77

I don't know why I get the sum of 52 when I use a for loop.

Here are my codes:

public class string2math {
public static void main(String[] args) {
String input = "000293000002030403+0400293059694";
String [] operand = input.split("+");
String firstOpera = operand[0];

[Code] ...

View Replies View Related

Addition Operation On Character Variables

Feb 8, 2015

When addition operation is performed on the character variables ,then it specifies actually that the ASCII values are added because the character variable stores ASCII value of the character constant ,then why after the addition the result cannot be stored inside a character variable ,why it needs to be stored in an integer variable only ,when actually the character variable stores the ASCII value then why is it an error to store the added result in an character variable.

View Replies View Related

Swing/AWT/SWT :: JDialog Close Operation

Mar 4, 2011

how the entire application could be close when you click on X in a JDialog Box. I have tried

System.Exit (0)

but it only close the Dialog box

View Replies View Related

Recursion - If Else Loop To Check If Operation Is Completed

Feb 2, 2014

I am currently learning recursion, and i have a query. I have a program that receives user input, and outputs the decimal input into binary form. In my recursive function, I have a if else loop to check if operation is completed.

public static int Converter(int input, int weight) {
System.out.printf("Input is now %d, weight is now %d
",input,weight);
if(input==0) {
return 0;

[Code] .....

The final return, when input finally hits zero is concatenating 0 to whatever i have this far. e.g. Decimal 10 should give 1010, but because of the "return 0", instead of getting 1010+0, i am getting 10100.

I can solve the problem by creating a variable sum,and passing along, but i am just curious why the final return 0 is giving me not a +0, but a concatenate 0.

View Replies View Related

How To Perform Row Operation - Store Data Into 2D Matrix

Sep 18, 2014

I am able to perform column operation but not able to perform row operation because i am not able to store data say a 2 matrix [][]. I need to store the data into a 2-D matrix. Here is my code:

Java Code:

import java.awt.List;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;
public class colRowRead {

[Code] ....

I tried something like that:

for(int i=0; i<rows; i++) {
for(int j=0; j<cols; j++){
matrix [i][j]=textFile.get(i).split(" ");
//System.out.println(matrix[i][j]);
}
}
*/ mh_sh_highlight_all('java');

File col.txt is like this:

Java Code:
5 9 7 1 5
3 6 8 6 8
4 6 7 8 9
9 8 3 5 7 mh_sh_highlight_all('java');

View Replies View Related

Invalid Operation At Current Cursor Position

Sep 30, 2014

I have now slowly moving on the learning Database Connectivity.Found a simple example on one site and tried to execute it, Creating a database, connecting to it and displaying the output.

I am getting trouble with recordset in displaying all the records in the badabase. It displays the very first record correctly but if I try to enclose it in while(rs.next()) loop, it generates an error message saying "Invalid operation at current cursor position".

package database_console;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.ResultSet;

[code]....

View Replies View Related

Arithmetic Operation - String Index Out Of Range Error?

Nov 17, 2014

I am trying to write a program which asks the user to enter two numbers and then do the arithmetic operation based on user's input . No compiling errors but when I run the program I keep getting "StringIndexOutOfBounds" error .
 
class arithmetic { 
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int ent1 = 0;

[Code]....

View Replies View Related

Servlets :: Clean Way To Log Every Database Operation Issued By Which User

May 16, 2014

So, there's a new requirement to log which user issues what database operations. The dumb way is to pass the session object around, but I hope said dumb way is not the only way to achieve this. Hopefully there's another cleaner and smarter way to do this.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved