answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Tasya [4]
2 years ago
14

Two-dimensional random walk (20 points). A two-dimensional random walk simulates the behavior of a particle moving in a grid of

points. At each step, the random walker moves north, south, east, or west with probability equal to 1/4, independent of previous moves. Write a program RandomWalker.java that takes an int command-line argument n and simulates the motion of a random walk for n steps. Print the location at each step (including the starting point), treating the starting point as the origin (0, 0). Also, print the square of the final squared Euclidean distance from the origin as double. Note: you do not need arrays for this problem, just keep track of the x and y coordinates during the random walk.

Computers and Technology
1 answer:
natka813 [3]2 years ago
4 0

Answer:

The following code in the explanation does the job for you. Here I have made use of Random class of Java to generate random numbers.

Explanation:

Code:

import java.util.*;

class RandomWalker {

  public static void main(String args[]){

      int n = Integer.parseInt(args[0]);

      int x = 0;

      int y = 0;

      Random random = new Random();

      for(int i = 0; i < n; i++){

          int tmp = random.nextInt(4);

          if(tmp == 0){

              x++;

          }

          if(tmp == 1){

              y++;

          }

          if(tmp == 2){

              y--;

          }

          if(tmp == 3){

              x--;

          }

          System.out.println("(" + x + "," + y + ")");

      }

      int distance = x*x + y*y;

      System.out.println("Squared Distance = " + distance);

  }

}

You might be interested in
Under what category of programs and apps do databases and enterprise computing fall?
Evgesh-ka [11]
Answer is productivity

Sometimes called the office or personal productivity software, productivity software is dedicated to producing databases, spreadsheets, charts, graphs, documents, graphs, digital video and worksheets. Reason behind the name productivity is due to the fact that it increases productivity in office work.

6 0
1 year ago
Suppose your name was George Gershwin. Write a complete program that would print your last name, followed by a comma, followed b
NNADVOKAT [17]

Answer:

I will write the code in C++ and JAVA      

Explanation:

<h2>JAVA CODE</h2>

public class Main

{ public static void main(String[] args) {

       // displays Gershwin,George

     System.out.println("Gershwin,George"); }  }

<h2>C++ Code:</h2>

#include <iostream>

using namespace std;  

int main()

{  cout<<"Gershwin,George"; }    

// displays last name Gershwin followed by , followed by first name George

//displays Gershwin,George as output.

6 0
2 years ago
Read 2 more answers
Which of the following attributes of a website indicates a more reliable source for information?
scoundrel [369]
An attribute of a website that will indicate a more reliable source of information is when the site ends in ".edu". It is a top-level domain for education. It would mean that this particular site is linked to universities, colleges or other educational sites thus it gives more information that is real and factual.
3 0
1 year ago
Compare the elements of the basic Software Development Life Cycle with 2 other models. How are they similar? How are they differ
Artemon [7]

Answer:

Explanation:

One of the basic notions of the software development process is SDLC models which stands for Software Development Life Cycle models. SDLC – is a continuous process, which starts from the moment, when it’s made a decision to launch the project, and it ends at the moment of its full remove from the exploitation. There is no one single SDLC model. They are divided into main groups, each with its features and weaknesses. The most used, popular and important SDLC models are given below:

1. Waterfall model

2. Iterative model

3. Spiral model

4. V-shaped model

5. Agile model

Stage 1. Planning and requirement analysis

Each software development life cycle model starts with the analysis, in which the stakeholders of the process discuss the requirements for the final product.

Stage 2. Designing project architecture

At the second phase of the software development life cycle, the developers are actually designing the architecture. All the different technical questions that may appear on this stage are discussed by all the stakeholders, including the customer.  

Stage 3. Development and programming

After the requirements approved, the process goes to the next stage – actual development. Programmers start here with the source code writing while keeping in mind previously defined requirements. The programming by itself assumes four stages

• Algorithm development

• Source code writing

• Compilation

• Testing and debugging

Stage 4. Testing

The testing phase includes the debugging process. All the code flaws missed during the development are detected here, documented, and passed back to the developers to fix.  

Stage 5. Deployment

When the program is finalized and has no critical issues – it is time to launch it for the end users.  

SDLC MODELS

Waterfall – is a cascade SDLC model, in which development process looks like the flow, moving step by step through the phases of analysis, projecting, realization, testing, implementation, and support. This SDLC model includes gradual execution of every stage completely. This process is strictly documented and predefined with features expected to every phase of this software development life cycle model.

ADVANTAGES  

Simple to use and understand

DISADVANTAGES

The software is ready only after the last stage is over

ADVANTAGES

Management simplicity thanks to its rigidity: every phase has a defined result and process review

DISADVANTAGES

High risks and uncertainty

Iterative SDLC Model

The Iterative SDLC model does not need the full list of requirements before the project starts. The development process may start with the requirements to the functional part, which can be expanded later.  

ADVANTAGES                                        

Some functions can be quickly be developed at the beginning of the development lifecycle

DISADVANTAGES

Iterative model requires more resources than the waterfall model

The paralleled development can be applied Constant management is required

Spiral SDLC Model

Spiral model – is SDLC model, which combines architecture and prototyping by stages. It is a combination of the Iterative and Waterfall SDLC models with the significant accent on the risk analysis.

4 0
1 year ago
Choose the correct function to convert the user’s response to the number 3.5. &gt;&gt;&gt; answer = input("How much does the sam
FromTheMoon [43]

Answer:

The answer to the given question is given bellow in the explanation section:

Explanation:

<p>This is python code</p>

<p>In python when you enter input into the input function as given:</p>

<code> answer = input("How much does the sample weigh in grams? ") </code>

I will be taken as string.

So I have to convert this string to number format here the given data is float value i-e 3.5

so let convert it. using float function.

<code> answer = float (input("How much does the sample weigh in grams? ") )  </code>

6 0
1 year ago
Read 2 more answers
Other questions:
  • Which data type stores images and audio visual clips?
    15·1 answer
  • Which social network made the mistake of alienating its early adopters by deleting suspicious accounts?​?
    5·1 answer
  • 4.2.3: Basic while loop expression. Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Fol
    6·2 answers
  • Nathan would like to save his PowerPoint presentation as a video that can be replayed easily on any device at full quality. Whic
    14·1 answer
  • Determining the Services Running on a Network Alexander Rocco Corporation has multiple OSs running in its many branch offices. B
    10·1 answer
  • Suggest how the following requirements might be rewritten in a quantitative way. You may use any metrics you like to express the
    7·1 answer
  • A school principal trying to find out if parents will help buy new playground equipment shows digital leadership by.
    8·2 answers
  • Computers represent color by combining the sub-colors red, green, and blue (rgb). Each sub-color's value can range from 0 to 255
    5·1 answer
  • In a system where Round Robin is used for CPU scheduling, the following is TRUE when a process cannot finish its computation dur
    13·1 answer
  • a key part of staying safe is employing good habits. drag the step number to the proper sequence triple a
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!