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


ADVERTISEMENT

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 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

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

Program That Implement Final Method And Perform Arithmetic Operation

Mar 4, 2014

class A
{
public final int Add(int a,int b) {
return a+b;
}
}

class B
{
public static void main (String args[])
{
System.out.println(Model.Add(5,10));
}
}

This is what I have. I'm not sure if this even makes use of a final method. But when I run it I get an error saying cannot find symbol for line 13.

View Replies View Related

Running A Simple GUI Program

Nov 23, 2014

I'm getting back into the swing of things with Java after using I'm asked to utilize a simple GUI in order to take in the starting data, I cannot seem to get this to work. I'm getting this error Exception in thread "main" java.lang.NullPointerException

at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at Input.buildPanel(Input.java:53)
at Input.<init>(Input.java:27)
at InputDemo.main(InputDemo.java:5)

I've created two classes

import javax.swing.*;
public class Input extends JFrame {
private JPanel panel;
private JLabel messageLabel;
private JLabel messageLabel1;
private JLabel messageLabel2;
private JTextField shiftHrs;

[code]....

View Replies View Related

Simple Three Button Program

Dec 14, 2014

I have my program set up I thought correctly. When I click the buttons, nothing is happening.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class RobertMaloneChapter18 extends JFrame
{
//set final sizes for window
private static final int WIDTH = 300;
private static final int HEIGHT = 200;

[code]....

View Replies View Related

Simple Pyramid Program

Jun 28, 2014

I was learning Java and there was this exersize to construct a simple pyramid of prespecified height and width. The program i wrote is turining up with the wrong result.

package asgn2;
import acm.graphics.*;
import acm.program.*;
public class pyramid extends GraphicsProgram {
private static final int BRICK_WIDTH = 30;
private static final int BRICK_HEIGHT = 12;
private static final int BASE_BRICKS =14;

[code]...

View Replies View Related

How To Make Robot Print Out Colons

May 1, 2014

I've tried making my robot print out colons but I just can't seem to. I tried doing

Java Code:
robot.keyPress(KeyEvent.VK_COLON); mh_sh_highlight_all('java');

and

ava Code:
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_SEMICOLON); mh_sh_highlight_all('java');

And neither seem to work, in fact I can't seem to get any symbols typed out (I don't want to copy to clipboard and paste out) (yes, I do keyRelease as well -> I've tried a bunch of stuff)...

View Replies View Related

Drag And Drop Using Robot Class

Jun 4, 2014

Is it possible to do drag and drop using robot class instead of using TransferHandler class?

View Replies View Related

Simple Averaging Program Using Two Different Classes?

Apr 9, 2014

This is a simple project that i was using to test my current java knowledge (kinda like revision) and for that i used two classes to make a simple averaging program. i know i0m making it more difficult but like i said i'm testing myself but i come up with an unexpected error. Here's the code:

- 1st Class

import java.util.Scanner;
public class Main {
public static int num;
public static int total = 0;
public static int average;

[Code].....

Now the problem is after inputing the numbers it doesn't give me the average but the value of 0.

View Replies View Related

Exception Errors In Simple Program?

Mar 26, 2015

I'm trying to read lines from a textfile and count all the words using String Tokenizer. However I keep getting an error "Unhandled exception type FileNotFoundException" on my IDE(Eclipse) referring to lines 13 and 8. When I let the IDE automatically, and I've even tried typing this manually, insert a try-catch block more errors show up concerning inputFile. When I insert the throws FileNotFoundException for each method it compiles but after running it gives me a FileNotFoundException for textfile.txt. What's even more interesting is that when I copy the .java file out of the IDE project folder, place it in a random empty folder on the Desktop with the textfile.txt, and try running it through command line, it gives a NoSuchElementException: No line found.

import java.util.Scanner;
import java.util.StringTokenizer;
import java.io.*;

[Code].....

View Replies View Related

Simple Encryption / Decryption Program

Nov 1, 2014

I have to write an encryption/decryption program for a sentence entered by the user that uses arrays. Here is my code so far. I'm kind of lost on what to do next in the code.

import java.util.Scanner;

/*Program that encrypts then decrypts a sentence
Encryption
*/
public class Encryption extends java.swing.JFrame{

[code]....

View Replies View Related

Make A Simple Calculator Program

Mar 11, 2015

i am working on my assignment in Compro 2, we are ask to make a simple calculator program

here's my code;

import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JFrame;
import java.awt.BorderLayout;

[code]...

View Replies View Related

How To Make A Simple Connect Four Program Without GUI

Nov 19, 2014

My code below is trying to make a connect four program without GUI. I'm having trouble with getting the players to make their moves. What should I put in my "makeAMove" method...

Java Code:

public class Connect

final static int MAXROW = 6;
final static int MAXCOL = 7;
public static void main(String[] args){

[code]....

View Replies View Related

Simple Vending Machine Program

Jan 22, 2014

I am having a difficult time writing what started out as a simple vending machine program. As I go on though, it seems that I'm overcomplicating it and it is getting messy, so I have resorted to the forum before I really get off the path. how to clean it up? I'm going to list a few of the problems I am having with the code below:

1. The user is supposed to enter his/her money and the program is to read each value separately (Do-While loop) and keep a running total of the money entered. I can't seem to get the right code format to do this. I was trying to do this with the variable total and so that is why the total exists in the switch statement, but it did not work.

2. In the second Do-While statement, is there a way to kick back an error when their are insufficient funds to purchase an item? Instead of getting a negative change return.

package practice;
import java.util.Scanner;
public class Practice {
public static void main(String[] args) {
double count, total;
int item;
//Display Available Options To Customer
Scanner input = new Scanner(System.in);
System.out.println("*VENDING MACHINE*");

[code]....

View Replies View Related

Simple 2D Optics Simulation Program

Sep 13, 2014

I'm very new to Java (I literally started learning it yesterday) and I've been working on a simple program that's meant to simulate interactions between optics objects and light rays.

Everything has been going really well, except that my mirrors only reflect the first ray that comes in contact with them.

Here's a screenshot : 2014-09-13 at 7.39.23 PM.jpg

I wrote 7 classes:

Main class to create the optics objectOptics class. the most important class that uses a recursive function to detect the nearest intersection point of a ray with the nearest optics object. It then calculates a reflected ray and inputs it back into the function until no intersections are found or the max recursion depth is met.Ray. creates a rays (in parametric form O + tD where O is the origin, D is the direction and t is a non-negative scalar)Object. empty abstract class used for polymorphism (so when i add more optics objects like prisms and lenses they'll share the object type)Mirror. Basically a line segment created with the Line classLine. Creates a line segmentDraw. JComponent with paintComponent function that loops through an array of shapes and draws them to the screen.

What I know so far is that the problem boils down to the checkRay() function in the Optics class. When a mirror has already reflected a ray, the line:

Intersection sec = new Intersection(ray,(Mirror)obj);

creates an intersection with a null point.

I debugged it line by line and found the problem was that my variable 't' (that is the parameter for the parametric line which represents the mirror) in the Intersection class got big values when it's meant to be between 0 and 1 (since it's a line segment), which resulted in the function returning null (as it should when 't' is not between 0 and 1).

I've confirmed with tests that this has nothing to do with the specific mirror or angle of incidence. It only occurs when a mirror has already been intersected with by a ray.

I've found out that my function:

public PVector getNormal(PVector D){
D.normalize();
return new PVector(D.y,-D.x);
}

Changes the value of the 'D' PVector of the mirror inside my 'objects' ArrayList. How can it access the private PVector 'D' from outside the Mirror class? This normalization to the direction vector is what causes the Intersection class to return null the second time around!

The problem was that in the getNormal function, the input vector argument was a reference to the 'D' vector for the mirror in my 'objects' ArrayList so the .normalize() function acted upon the original vector, changing it's value and screwing things up. The two classes I talked about:

Optics: (note line 64. this line returns a null intersection when it shouldn't)

package ofer.davidson;
 import java.util.ArrayList;
 public class Optics {
 //Arrays to store all the optics objects and rays that are created
ArrayList<Object> objects;
ArrayList<Ray> rays;
 
[Code] .....

Also why doesn't my background turn white??

View Replies View Related

Coding A Robot To Follow A Line In Eclipse?

Mar 11, 2014

I have a serious issue with getting this robot to follow a line?

View Replies View Related

How To Make Resizable Screencapture Using Robot In Java

May 9, 2015

I am new to java. I am trying to make a simple screencapture and display program.

I am using robot class to capture a particular portion of the screen and display it in a separate frame.

However I need to be able to resize the area of screencapture. I searched but I dint find any solution wherein I can do so.

I am using this command for capturing the screen

But I couldn't find a way to make the rectangle re-sizable.

Java Code:

BufferedImage buff = robot.createScreenCapture(new Rectangle(0,0,1300,750)); // x-coord, y-coord, width, height mh_sh_highlight_all('java');

View Replies View Related

Make Simple Program Which Takes In Argument?

May 12, 2015

So I'm trying to make a simple program which takes in an argument (target) and then looks through an ArrayList of strings. If it finds a string that begins with (target) then it will return the index of that string. If it doesn't find a string which begins with (target) then it will return -1 instead.

For some reason, the program is always returning -1, rather than the index of the string within the ArrayList when there is one which matches the search criteria.

Here is the code:

public int getIndex(ArrayList<String> text, String target)
{
int i = 0;
int index = -1;
boolean found = false;

[Code].....

View Replies View Related

Designing A Game That Simulates Roomba Robot Vacuum

Feb 14, 2014

I am designing a game that simulates a roomba robot vacuum and have most of the framework done. So I have random floating circles and the Roomba bot in the center. The boot is suppose to move with the arrow keys. However when i run the program and select the keys nothing happens. Here's my code.

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.Ellipse2D;
import java.awt.Graphics;
import javax.swing.*;
public class Roomba extends JFrame implements ActionListener, KeyListener{
 
[Code] .....

View Replies View Related

Creating A Program That Calculates Simple And Compound Interest

Aug 12, 2014

I need getting started designing and creating a program that calculates simple and compound interest. Simple interest in this case means that interest is only applied to the original amount. For instance, if a person deposits $1000 at 10% annual interest, then after one year they would have $1100 (the original $1000 plus the $100 interest) and after two years they would have $1200 (the original $1000, plus the $100 earned the first year, plus the $100 earned the second year).

With compound interest, the interest is applied to all money earned. So, starting with $1000 at 10% annual interest, after one year the user would have $1100 (the original amount plus $100 interest) and after two years the user would have $1210 (the $1100 they started with at the beginning of the year plus the $110 interest).

The requirements of this program are:

-Create a class that will hold methods to calculate the interest. Do not include the main method in this class.
-In the class that is used to calculate the interest, include a method to print to the screen, by interest period, the starting amount for the period, the interest earned for the period, and the total amount at the end of the period. Note that each period represents the time frame for how often it is updated. If annual is selected the period is every year. If it is semi-annual it is every six months. If it is quarterly it is every three months.
-Create a demo class that will use your interest calculation class. Prompt the user for the original amount, the type of interest (simple or compound), the annual interest rate, and whether it is updated annually, semi-annually, or quarterly. Use method calls to your calculate interest class to do all calculations and display the result. Loop the program until the user chooses to quit.

Sample output ($10000 initial investment, 10% simple interest, annual, for 4 years):

Period Beginning Amount Interest Earned Ending Amount
1 10000.00 1000.00 11000.00
2 11000.00 1000.00 12000.00
3 12000.00 1000.00 13000.00
4 13000.00 1000.00 14000.00

View Replies View Related

Simple Chat Program With Client / Server EOFException

Feb 13, 2015

When I Start Server and login from client everything goes fine but as soon as I want to send amessage or use showIn or even logOut .

Get below error

Exception creating new Input/output Streams: java.io.EOFException

View Replies View Related

Getting NullPointer Exception Error In Simple ArrayList Program

Mar 21, 2015

I am creating a simple ArrayList program that would enable one to input their username to it using a scanner. However, i am getting this error: "Exception in thread "main" java.lang.NullPointerException

at home.Members.addUser(Members.java:16)
at home.Main.main(Main.java:14)"

Here is the code! :

Main.java class
Java Code: import java.util.Scanner;
public class Main {

[code]....

View Replies View Related

Simple Logic Error In Cipher-shifting Program?

Feb 8, 2015

I was tasked with creating a program that encrypts a line of text (for example, CANDY) by shifting the letters X amount of times. For example, if the user inputs the sentence CANDY and selects a shift of 5, the output would be: HFSID. I got this part working fine. The issue I am having is with the decryption part of the program.

This is simply the reverse of the above, as the user would enter the phrase HFSID, with a shift of 5, and the program would output: CANDY. It works fine, all except for one letter, being the "F" letter. With my code, when I enter the above word to be decrypted it outputs: C[NDY

Obviously, that [ bracket is not an 'A'. I realise the issue falls with the equation, Here is my code:

public class SimpleEncryption {

/**
* @param args the command line arguments
*/
static int answer;
public static void main(String[] args) {
String cipher = JOptionPane.showInputDialog(null, "Please enter a sentence or word that you wish to encode or decode. This program uses"
+ " a basic cipher shift.");

[code]....

View Replies View Related







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