Number Generating Road Cross

Dec 8, 2014

The program I'm supposed to create generates a random number between one to ten. Then the program is to ask me if I wish to cross the road.

If you choose to cross, the outcomes for 0-2 are "You crossed safely."

For 3-5, 75% of the time it should say "RIP you got run over", and 35% of the time it should say "You crossed the street."

For 6-8, 60% of the time it should say you made it.", and 40% of the time it should say "You died". For 9-10, it should say "RIP".

So far I have gotten the random number generation part working,

import java.util.Random;
public class test4 {
public static void main(String[] args) {
Random random = new Random();
for(int i =0; i < 1; i++){
int num = random.nextInt(10) + 1;
System.out.println("The number of cars on the street are: " + num + "
Do you wish to cross the road?");
}
}
}

View Replies


ADVERTISEMENT

Java Random Road Cross - Generate Random Number Between One To Ten

Dec 8, 2014

The program I'm supposed to create generates a random number between one to ten. Then the program is to ask me if I wish to cross the road. If you choose to cross, the outcomes for 0-2 are "You crossed safely." For 3-5, 75% of the time it should say "RIP you got run over", and 35% of the time it should say "You crossed the street." For 6-8, 60% of the time it should say you made it.", and 40% of the time it should say "You died". For 9-10, it should say "RIP".

So far I have gotten the random number generation part working. I have up to here:

import java.util.Random;
public class test4 {
public static void main(String[] args) {
Random random = new Random();
for(int i =0; i < 1; i++){
int num = random.nextInt(10) + 1;
System.out.println("The number of cars on the street are: " + num + "Do you wish to cross the road?");
}
}
}

View Replies View Related

Generating Random Number Between 1-1000

Oct 31, 2013

I am very new to programming. This is for a college assignment. It says in the brief of the assignment that we will need to convert Math.random to output a random number between 1-1000. How can I do this?

View Replies View Related

Generating Double Number From The Range

Apr 18, 2014

I am trying to generate a double number from the range [-1,2]

so what i did is this

xs[i]= Math.random() *(2-(-1))+(-1);

I did that as a loop to generate multiple numbers and i got this result:

initial x values 2.17 2.66 3.04 2.81 1.83 2.66 3.67 2.81 1.04 3.1 3 1.23 1.44 3.5 3.84 3.03 1.7 2.79 4 1.43

see some numbers are out of range! and i don't know why aren't there any minus numbers...

View Replies View Related

Finding Road With Stack Or Queue

May 2, 2014

I have to make code about finding road with Stack or Queue. At first, I tried to make it in this way...

Java Code:

//public class QueueMain {
public static void main(String[] args){
int [][] arr = {{0, 0, 1, 0, 0, 1, 0, 0, 0}, //p
{0, 0, 0, 0, 0, 0, 1, 0, 0},//q
{0, 0, 0, 0, 0, 0, 1, 0, 0},//r
{0, 0, 0, 0, 1, 0, 0, 0, 0},//s
{0, 0, 0, 0, 0, 1, 0, 0, 0},//t
{0, 0, 0, 1, 0, 0, 0, 1, 0},//w
{0, 0, 0, 0, 0, 0, 0, 0, 0},//x
{0, 0, 1, 0, 0, 0, 0, 0, 1},//y
{0, 0, 0, 0, 0, 0, 0, 0, 0}};//z
String [] add = {"P", "Q", "R", "S", "T", "W", "X", "Y", "Z"};
int originnumber = 0;
int destinationnumber = 8;

[Code] ....

But it doesn't work at all. I tried to put visited address into array<mark>... but it didn't work.

View Replies View Related

Swing/AWT/SWT :: Road Map Of Some Area Inside Desktop Application?

Jul 20, 2014

I try to create Java Swing Desktop application which show Road map of some area in JFrame. But pc not connected to internet it will be in LAN. Map should be like if we scroll the mouse we go down from height in map. Like zooming the area.

I try to find out by google i get lots of forum links but each showing me.

1. I have to do web application.
2. Google not support 'without internet' map facility.
3. I should use lots of jpgs which store in folder for showing map from various height so it look like when we see any map in Google Earth application.

I found goworldwind.org but not clear understanding right now.

View Replies View Related

Creating A Diagonal Cross?

Oct 3, 2014

I need to create a diagonal cross however I can not figure out how to do the upper left side of it.

Currently I am getting

0*
1--*
2---*
3 *--*
4*-----*

I want to get it to look like

0*------*
1 *--*
2----*
3 *---*
4*------ *

( I replaced spaces with -) So far I have

System.out.println("Input a size(must be larger than 1: )");
size=input.nextInt();
if (size>1) {
for (x=0;x<size;x++){
System.out.println("");

[Code] ....

View Replies View Related

Cross-site Scripting (XSS) In Search Box

Aug 13, 2014

I need fixing an issue in the search textbox in one of the jsp's. I was informed that cross site scripting can be done in the textbox and I kept the below code in my jsp to fix the issue:

Java Code:

searchTerm = request.getParameter("search");
searchTerm = searchTerm.replaceAll("<", "<").replaceAll(">", ">");
searchTerm = searchTerm.replaceAll("[^A-Za-z0-9 ]", "");
searchTerm = searchTerm.replaceAll("eval((.*))", "");
searchTerm = searchTerm.replaceAll("["'][s]*((?i)javascript):(.*)["']", """");

[Code] ....

Now, after applying the above code, the cross site scripting can be done and the problem is that the search can't be done using the textbox and all the time will display none results.

View Replies View Related

Calculate Auto And Cross-correlation From A File

Oct 30, 2014

I have to calculate auto and cross-correlation from a file, like this:

Rxx(n)= 1/N* SUM[from k=1 to N-n]((x(k)-x(mean))*x(k+n)-x(mean))

and after

Rxy(n)= 1/N* SUM[from k=1 to N-n]((x(k)-x(mean))*y(k+n)-y(mean))

I've 600 x an y,
k = the numbers of x (N is the last one)
n = 0....N-1

View Replies View Related

Fixing Cross-site Scripting In Search Box

Aug 13, 2014

fixing an issue in the search textbox in one of the jsp's. I was informed that cross site scripting can be done in the textbox and I kept the below code in my jsp to fix the issue:

searchTerm = request.getParameter("search");
searchTerm = searchTerm.replaceAll("<", "<").replaceAll(">", ">");
searchTerm = searchTerm.replaceAll("[^A-Za-z0-9 ]", "");
searchTerm = searchTerm.replaceAll("eval((.*))", "");
searchTerm = searchTerm.replaceAll("["'][s]*((?i)javascript):(.*)["']", """");
 
[code]...

Now, after applying the above code, the cross site scripting can be done and the problem is that the search can't be done using the textbox and all the time will display none results.

View Replies View Related

Calculate Auto And Cross-correlation From A File

Oct 26, 2014

I have to calculate auto and cross-correlation from a file, like this:

Rxx(n)= 1/N* SUM[from k=1 to N-n]((x(k)-x(mean))*x(k+n)-x(mean))

and after

Rxy(n)= 1/N* SUM[from k=1 to N-n]((x(k)-x(mean))*y(k+n)-y(mean))

I've 600 x an y,

k = the numbers of x (N is the last one)
n = 0....N-1

already calculated mean, and I've tried the following (but it doesnt work):

String sor;
int i=0;
while ((sor = br.readLine()) != null) {
String [] adatok =sor.trim().split(",");

[Code] ....

View Replies View Related

Java Servlet :: Prevent Cross Site Script In URL

Jan 12, 2015

If some one add script in my URL, I want the script not pop up, we have tomcat 6 [URL] .....

View Replies View Related

Draw 3 Rectangles In Different Spots / Move Elements In Order So They Do Not Cross

Apr 9, 2014

I made a small aplication which draws 3 rectangles in different spots(0,0 , 50,50 , 100,100)

Am I used an KeyListener + ActionListener, to make them move in the let's call it box.

How can I do in order that those 3 elements do not cross, so you can always see them, they don't collapse into each other?

Java Code:

package matrixmoveelements;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

[Code] ......

View Replies View Related

Prime Numbers - Find N From List That Is Not Crossed And Cross Out All Its Multiples

Jun 20, 2014

the prime numbers from 1 to 2500 can be obtained as follows. From a list of the numbers of 1 to 2500,cross out al multiples of 2 (but not 2 itself). Then, find the next number (n, say) that is not crossed out and cross out all multiples of n (but not including n).

Repeat this last step provided that n has not exceeded 50 (the square root of 2500). The numbers remaining in the list (except 1) are prime. Write a program which uses this method to print all primes from 1 to 2500. Store your output in a file called primes.out.

View Replies View Related

Randomly Generating A 0 Or 1

Nov 4, 2014

My random integer always seems to be zero.. I am at the ends of my wit.

package Exercises;

import java.util.Random;
import java.util.Scanner;
import javax.swing.JOptionPane;

/**
* Heads or tails?
* That is what this is.
*/
public class num14 {

[Code] ....

Attached File(s) : New Text Document.txt (2.59K)

View Replies View Related

JSP :: Generating Unique ID With Session

Sep 5, 2004

Is it a good idea to use the date and time with the first or last few values of the session ID. Or should I just use the complete session ID value for my "unique id"?

View Replies View Related

Generating Method To Be Called

Jun 25, 2014

I want to call getter method from method based on parameter send to this method e.g

Java Code:

void myCrazyMethod(MyDto dto, String prop){
System.out.println("Value of " + prop + ": " + dto.get{Prop}()");
} mh_sh_highlight_all('java');

View Replies View Related

Generating Series Of Numbers - How To Get A Zero To Appear

Jun 8, 2014

My project is writing a program that generates a series of numbers to appear like a social security number (XXX-XX-XXXX). My code runs.. But any number below 10 it just shows one number (XXX-X-XXXX). What do I need to enter in to my code so that if the number is <10 it will show (00,01,02,03....)?

Java Code:

import java.util.Random;
public class IDnumber
{
public static void main (String[] args) {
Random generator = new Random()
int num1 = (generator.nextInt(7) + 1) * 100 + (generator.nextInt(8) * 10) + generator.nextInt(8);
int num2 = generator.nextInt(74);
int num3 = generator.nextInt(10000);
String IDnumber = num1 + "-" + num2 + "-" + num3;
System.out.println(IDnumber);
}
} mh_sh_highlight_all('java');

View Replies View Related

Generating Reports Using Java

Jun 25, 2014

I have a problem in generating reports using java code. I created a report using iReport 5.5.0 with MySql Database connection. In iReports, it shows the correct output while previewing it. Then i copied my .jrxml file and pasted it into my netbeans project folder(..sample/web/WEB-INF/sample.jrxml) and then i added the required jar files in my project's library folder. i am generating the report in netbeans using jsp and servlet. THE REPORT IS GENERATING AND SAVED SUCCESSFULLY IN MY DESKTOP. BUT IT DOESN'T GENERATE THE REPORT FOR FIRST RESULT. For Example.., if i generating report based on a particular date. After executing the query, it returns 4 results. So it has to create the reports in 4 pages. But it generates the report for last 3 pages only. It doesn't generate the report for first page. I have attached my .jrxml file servlet file for your reference.

View Replies View Related

Generating Random Sentences

Nov 3, 2014

I have been set this task, which is supposed to make me code using string arrays. The idea is to generate random sentences.This is what i have been able to do so far :

package usingarraysagain;
public class sentences {
public static void main (String[] args){
String[] NOUNS = { "lizards",
"Nikola Tesla",

[code]....

View Replies View Related

Generating Compound Interest With Integers

Sep 15, 2011

I am trying to change this code to use only integers to calculate the compound interest.

// Compound-interest calculations with for.

public class Interest {
public static void main( String args[] ) {
double amount; // amount on deposit at end of each year
double principal = 1000.0; // initial amount before interest
double rate = 0.05; // interest rate

[Code] .....

And here is the output I get :

Why do I get the output after year 2? I assume it has something to do with the remainder.

I also have to format this output with the decimal point, etc.. which I think I will be ok with after I get through this part.

View Replies View Related

Generating Random Numbers Within Interval

Jan 13, 2014

I've been trying to find the easiest way to write to generate a number which is between intervals of a arbitrary min and a max value.I've been searching for this but I don't find this particular thing.I've found that this combination works:

Java Code: int guess = rand.nextInt(max - (min - 1)) + min; mh_sh_highlight_all('java');

But I wonder, is this really the easiest way of writing it?

View Replies View Related

Generating Random Numbers Without Repeating

Aug 21, 2014

I am working on a bingo project and created random numbers between 1 and 75 to generate. I have it set up that it shows the number in a text box and changes the color on the board if the number is called. When I test the program, some numbers are highlighted in addition to the number called. I believe this is because extra numbers are being chosen, but not being noted in the text box. Below is my code for the unique random numbers.

int CallNo;
String CallerTxt = new String();
public void CallNum() {
Random RandCall = new Random();
//Generate Caller Random Number
CallNo = RandCall.nextInt(75)+1;

[Code] ....

View Replies View Related

How To Keep Colors / Layout And Formatting After Generating JAR

May 10, 2014

After generating a. JAR with Netbeans Java, when I play I see the colors of the components, the design and formatting is lost and the form gets a very basic formatting, for example, if I set a button with the color [0, 40.255] and build the. JAR after this, when I run the. JAR this button turns gray, and it happens with all the layout of the form.

settings:
Netbeans 8.0
Windows 7

View Replies View Related

Generating All Combinations Of Characters Given A Length N

Nov 10, 2014

I am trying to iterate through all combinations of characters given a length n with the added notion that all characters are numerical (0-9).e.g I have been given n = 5. The I want to iterate through all combinations starting with "00000" and ending with "99999". My first instinct was to just have a for loop like the following:

for(int i= 0; i<99999; i++){
// extra code here
}

but obviously this does not a account for combinations such as "00010".

View Replies View Related

How To Keep Colors / Layout And Formatting After Generating JAR

May 11, 2014

After generating a. JAR with Netbeans Java, when I play I see the colors of the components, the design and formatting is lost and the form gets a very basic formatting, for example, if I set a button with the color [0, 40.255] and build the. JAR after this, when I run the. JAR this button turns gray, and it happens with all the layout of the form.

settings:
Netbeans 8.0
Windows 7

View Replies View Related







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