Questions
Problem Description: Game: Bean Machine or Galton Box To figure out if the ball falls to...

Problem Description: Game: Bean Machine or Galton Box

To figure out if the ball falls to Left or Right, you can generate a random number using Math.random(). If this random number is greater than or equal to 0.5 we assume the ball falls to the Right otherwise it falls to the Left (or vise versa).

If there are 8 slots, the ball should hit 7 nails (8 -1), thus you should run a loop 7 times to figure out the path for that ball. If you have N balls, this whole process should be repeated N times. Here is a basic algorithm.

# of balls = N

# of slots = K

array of K elements

for ( i = 0 to N) {

   int R = 0;

   for (j = 0 to K-1) {

        if ( random number >= 0.5)

                  R++;

}//end loop j

array[R] ++;

}// end loop i

Output the array to show how many balls are in each slot.

Things to DO!!!!!

Analysis: (3 points)

(Describe the problem including inputs and outputs in your own words.)

Design: (3 points)

(Describe the major steps in your algorithm for solving the problem.)

Coding: Write a well documented and properly indented Java source program. Your program should have a block comment with your name and a statement of purpose at the very top. Use meaningful variable names. You must have proper labels and informative statements for all inputs and outputs. (10 points)

Testing: (Describe how you test this program, you should use your own input data to test not just the test cases given in sample runs.) (4 points)

Test your program according to following test schedule and generate output to show the number of balls in each slot.

N K
10 8
50 10
100 20
500 30

What to Submit:

  1. A PDF with descriptions of Analysis, Design, and Testing. Must have a title with your name and assignment number. (Do not submit a Word document!!!!)
  2. Error free Java source program (Programs with syntax errors receive 0 credit) with methods, proper comments and indentation. Java source program is the program you wrote with .java file extension. (Do not submit a Word or any other document of your code!!!!)
  3. The Program outputs for the 4 different test cases in a PDF

In: Computer Science

C Programming Assignment 4 Cache Simulation Objective: To write a C program that simulates reading and...

C Programming Assignment 4

Cache Simulation

Objective:

To write a C program that simulates reading and writing to a custom-sized direct-mapped cache, involving a custom-sized main memory.

The program will read all values from the ZyLab as Test Bench inputs.

Main Menu Options:

The program simulates reading from and writing to a cache based on choosing from a menu of choices, where each choice calls the appropriate procedure, where the choices are:

  1. Enter Configuration Parameters
  2. Read from Cache
  3. Write to Cache
  4. Quit Program

Note that when you read from ZyLab, the input values are not displayed on the screen as they are in the sample run at the end of this document.

Inputs:

  • Enter Parameters
    • The total size of accessible main memory (in words)
    • The total size of the cache (in words)
    • The block size (words/block)
  • Read from Cache
    • The main memory address to read
  • Write to Cache
    • The main memory address to write
    • The contents of the address for writing to the cache

Input Value Checks:

  • All the parameter values must be powers of 2.
  • The block size must never be larger than the size of accessible main memory.
  • The total cache size must be some multiple of the block size.
  • Your program should verify that all input variables are within limits as they are entered.

Output Messages:

All messages should be display EXACTLY as shown in the sample run; that is, prefixed by three asterisks, a space and hyphen and one more space. The message should be followed by a blank line.   

  • Data Accepted Message is comprised of two sentences:

*** All Input Parameters Accepted.

     Starting to Process Write/Read Requests

  • Error Messages are preceded by “*** Error –“. A list of possible errors is given below.

Note that one message has been deleted from previous versions of this Specification and three new ones have been added.

*** Error - Main Memory Size is not a Power of 2

*** Error - Block Size is not a Power of 2

*** Error - Cache Size is not a Power of 2

*** Error – Block size is larger than cache size

  • Deleted Error Message

*** Error – Cache Size is not a multiple of Block Size

  • Newly Added Error Messages

*** Error – Read Address Exceeds Memory Address Space

*** Error – Write Address Exceeds Memory Address Space (The write value following the invalid address value should be read and then discarded)

*** Error – Invalid Menu Option Selected (Until configuration data has been accepted, the only valid menu options that can be entered are “1” or “4.”)

Whenever any one of these errors occurs, the program should loop back to the Main Menu.

  • Content Message resulting from reading/writing to the cache

*** Word WW of Cache Line LL with Tag TT contains Value VV

This message should appear after all successful reads or writes

WW is the word number in the cache line, LL is the line number in the cache, TT is the line’s tag value and VV is the content value in the cache.

All values are in decimal.

  • Read Messages (two possible messages)

*** Read Miss - First Load Block from Memory (followed on the next line by the Content Message above)

*** Cache Hit (followed on the next line by the Content Message above)

  • Write Messages

*** Write Miss - First Load Block from Memory (followed on the next line by the Content Message above)

*** Cache Hit (followed on the next line by the Content Message above)

  • Quit Program Message

*** Memory Freed Up – Program Terminated Normally

When option 4 is entered, the memory should be freed up and the message “Memory Freed Up – Program Terminated Normally”, followed by a blank line, should be displayed before exiting the program.

Program Requirements:

  • Use a structure (struct) to represent a cache line consisting of a tag (integer) and a block (integer pointer). Define the cache to be a pointer to the struct.
  • Upon entering the parameters, the main memory and cache are to be dynamically allocated (use malloc) based on their respective total sizes.

Each word i of main memory is initialized with the value Mi, where M is the size of main memory in words. So, memory location 0 will contain the address of the last memory location and the last memory location will contain the address of the first memory location (i.e. 0).

  • Reading/writing from/to a new block in the cache results in dynamically allocating a block for that instance, based on the previously entered block size.

Prologue & Comments:

At the very beginning of your source code (the very first lines), please include a prologue which looks like the following:

/*

Dr. George Lazik                      (use your full name not mine)

Programming Assignment 4: Cache Simulation

Comp 222 – Fall 2019

Meeting Time: 0800-0915       (your meeting time)

*/

  • Include simple (brief) comments strategically throughout your program so that someone else can readily follow what you are doing, but don’t overdo it. Examples might look like these:

// Reading input values from ZyLab

// Determining the contents of memory

ZyLab Test Benches:

  • You will be permitted unlimited submission attempts on ZyLab until the due date. Afterwards, the inputs will be changed, the point value of the assignment will be increased to 100 and only one submission will be permitted. This last submission will be on the day following the due date and should be the one with the highest score.

  • Hardcopy printed listing of your program. Please place this on the Professor’s desk at the beginning of class on day the assignment is due. It should be properly C formatted listing and not one from programs such as Word.

Make sure your full name appears on each page of the listing and that all pages are stapled together in their correct order BEFORE you come to class.

Failure to provide this listing will result in no grade for the assignment.

Sample Test Run

The following is a sample run of one of the tests in Assignment 4’s Test Bench on ZyBooks. Note: Some recently added error conditions are not included in this run.

1

65536

512

1024

1

65536

1027

16

1

65536

1024

15

1

65537

1026

4096

1

65536

1024

18

1

65536

1024

16

3

65535

14

2

65535

3

65534

512

2

1023

4

Your output

Programming Assignment 4: Cache Simulation

Comp 222 - Fall 2019

Main Menu - Main Memory to Cache Memory Mapping

------------------------------------------------

1) Enter Configuration Parameters

2) Read from Cache

3) Write to Cache

4) Quit Program

Enter selection:

Enter main memory size (words):

Enter cache size (words):

Enter block size (words/block):

*** Error - Block Size is Larger than Cache Size

Main Menu - Main Memory to Cache Memory Mapping

------------------------------------------------

1) Enter Configuration Parameters

2) Read from Cache

3) Write to Cache

4) Quit Program

Enter selection:

Enter main memory size (words):

Enter cache size (words):

Enter block size (words/block):

*** Error - Cache Size is not a Power of 2

Main Menu - Main Memory to Cache Memory Mapping

------------------------------------------------

1) Enter Configuration Parameters

2) Read from Cache

3) Write to Cache

4) Quit Program

Enter selection:

Enter main memory size (words):

Enter cache size (words):

Enter block size (words/block):

*** Error - Block Size is not a Power of 2

Main Menu - Main Memory to Cache Memory Mapping

------------------------------------------------

1) Enter Configuration Parameters

2) Read from Cache

3) Write to Cache

4) Quit Program

Enter selection:

Enter main memory size (words):

Enter cache size (words):

Enter block size (words/block):

*** Error - Main Memory Size is not a Power of 2

Main Menu - Main Memory to Cache Memory Mapping

------------------------------------------------

1) Enter Configuration Parameters

2) Read from Cache

3) Write to Cache

4) Quit Program

Enter selection:

Enter main memory size (words):

Enter cache size (words):

Enter block size (words/block):

*** Error - Cache size is not a multiple of block size

Main Menu - Main Memory to Cache Memory Mapping

------------------------------------------------

1) Enter Configuration Parameters

2) Read from Cache

3) Write to Cache

4) Quit Program

Enter selection:

Enter main memory size (words):

Enter cache size (words):

Enter block size (words/block):

*** All Input Parameters Accepted. Starting to Process Write/Read Requests

Main Menu - Main Memory to Cache Memory Mapping

------------------------------------------------

1) Enter Configuration Parameters

2) Read from Cache

3) Write to Cache

4) Quit Program

Enter selection:

Enter Main Memory Address to Write:

Enter Value to Write:

*** Write Miss - First load block from memory

*** Word 15 of Cache Line 63 with Tag 63 contains the Value 14

Main Menu - Main Memory to Cache Memory Mapping

------------------------------------------------

1) Enter Configuration Parameters

2) Read from Cache

3) Write to Cache

4) Quit Program

Enter selection:

Enter Main Memory Address to Read:

*** Cache Hit

*** Word 15 of Cache Line 63 with Tag 63 contains the Value 14

Main Menu - Main Memory to Cache Memory Mapping

------------------------------------------------

1) Enter Configuration Parameters

2) Read from Cache

3) Write to Cache

4) Quit Program

Enter selection:

Enter Main Memory Address to Write:

Enter Value to Write:

*** Cache Hit

*** Word 14 of Cache Line 63 with Tag 63 contains the Value 512

Main Menu - Main Memory to Cache Memory Mapping

------------------------------------------------

1) Enter Configuration Parameters

2) Read from Cache

3) Write to Cache

4) Quit Program

Enter selection:

Enter Main Memory Address to Read:

Read Miss - First Load Block from Memory

*** Word 15 of Cache Line 63 with Tag 0 contains the Value 64513

Main Menu - Main Memory to Cache Memory Mapping

------------------------------------------------

1) Enter Configuration Parameters

2) Read from Cache

3) Write to Cache

4) Quit Program

Enter selection:

*** Memory Freed Up - Program Terminated Normally

In: Computer Science

Select 1 of the economic concentrations (clusters) below: Seattle-Tacoma-Olympia, WA aerospace / defense industry Central California...

Select 1 of the economic concentrations (clusters) below:

  • Seattle-Tacoma-Olympia, WA aerospace / defense industry
  • Central California winemaking industry
  • Hollywood movie industry
  • Silicon Valley Technology hub
  • Texas / Louisiana Gulf Coast crude oil and natural gas production and refining
  • Pre-1994 vs Post-1994 US auto and light truck production and the reasons for the change in economic concentration

Write a 700- to 1,050-word paper evaluating economists’ assessments of the role the 4 factors of production played in determining how the economic concentration you selected has evolved. Complete the following in your paper:

  • Analyze how the economic concentration in the area you chose was influenced by competition and pricing.
  • Analyze how the economic concentration in the area you chose influenced the supply chain.
  • Analyze which of the 4 factors of production were the most and least important in determining the economic concentration of the area you chose.
  • Predict changes you anticipate for the area of economic concentration you chose. Support your predictions.

In: Economics

A country experiences severe storms which destroys its main resource, oil rigs. Assume that the countries...

A country experiences severe storms which destroys its main resource, oil rigs. Assume that the countries economy was in long-run equilibrium before this shock happens.

  1. Use the aggregate demand–aggregate supply model to illustrate graphically the short-run and long-run impact of this supply shock on output and prices. In other word how does the economy get back to long run? Be sure to label: i. the axes; ii. the curves; iii. the initial equilibrium values; iv. the direction the curves shift; and v. the terminal equilibrium values. State in words what happens to prices and output as a combined result of the supply shock, both in the short run and long run. What happens to unemployment rate in the short run and in the long run?
  1. If the Central Bank of the country attempted to offset this deviation from the natural rate in the short run, should the money supply be increased or decreased? Show this action in the same graph and label the shifts. Which curve shifts? Does it shift to the right or left? What happens to output and prices as a result? What happens to unemployment rate? Explain.

In: Economics

Prepare the answer to the following question by either entering text directly or uploading an Excel...

Prepare the answer to the following question by either entering text directly or uploading an Excel or Word file. Do NOT upload a .pdf or .jpg file or you will receive zero credit. Show computations. The prepaid insurance account has an unadjusted balance of $46,000 at December 31, 2018, the end of Hanson Company's accounting year. Insurance expense has an unadjusted $2,000 balance at the same point in time. Some policies that were in effect have expired. Some of those were renewed and some were not. The following policies are in effect at December 31, 2018: Policy Date Policy Total Premium Type Acquired Term Paid when acquired Liability 1-31-17 2 years $48,000 Auto 6-30-18 2 years 9,000 Business interruption 8-1-18 1 year 840 Determine the adjusted balance in prepaid insurance at December 31, 2018. 2.Determine the amount of total insurance expense (you need not separate the expense by policy type) to report on the income statement for the year ended December 31, 2018.

In: Accounting

Prepare the answer to the following question by either entering text directly or uploading an Excel...

Prepare the answer to the following question by either entering text directly or uploading an Excel or Word file. Do NOT upload a .pdf or .jpg file or you will receive zero credit. Show computations.

The prepaid insurance account has an unadjusted balance of $46,000 at December 31, 2018, the end of Hanson Company's accounting year. Insurance expense has an unadjusted $2,000 balance at the same point in time. Some policies that were in effect have expired. Some of those were renewed and some were not. The following policies are in effect at December 31, 2018:

Policy                                                                 Date                 Policy            Total Premium

  Type                                                               Acquired             Term         Paid when acquired

Liability                                                              1-31-17          2 years         $48,000

Auto                                                                   6-30-18             2 years             9,000

Business interruption 8-1-18              1 year                 840

  1. Determine the adjusted balance in prepaid insurance at December 31, 2018.

2.Determine the amount of total insurance expense (you need not separate the expense by policy type) to report on the income statement for the year ended December 31, 2018.

In: Accounting

In a system employing a paging scheme for memory management; wasted space is due to: External...

In a system employing a paging scheme for memory management; wasted space is due to:

External fragmentation

Internal fragmentation

Pages and frames of different specified sizes

None of these are reasons for wasted space in a paging scheme

The page table for each process maintains:

The frame location for each page of the process

The page location for each frame of the process

The physical memory location of the process

None of these are what the page table maintains

The real address of a word in memory is translated from the following portions of a virtual address:

Page number and frame number

Page number and offset

Frame number and offset

None of these are how a virtual address is translated to a real address

The replacement policy that can be implemented in practice and performs the best among the replacement policies that can be actually coded is:

Optimal Policy

Least recently used (LRU) policy

Clock policy

None of these are the described replacement policy

A reference to a memory location independent of the current assignment of data to memory is called a(n):

Special address

Logical address

Absolute address

None of these are the name for this type of memory reference

In: Computer Science

To obviate current beach erosion potentials and as a part of beach re-nourishment, Research department’s Dr....

To obviate current beach erosion potentials and as a part of beach re-nourishment, Research department’s Dr. Smith proposed a construction of a series of submerged wave energy dissipation structures (=submerged-plate breakwaters) at 110 ft from the shoreline of the Beach. Based on design specifications of the structure, the distribution of the number of waves dissipatable by the proposed structure per hour could be approximated by a normal distribution with a mean of 189 waves and a standard deviation of 7 waves.
1) Use the Empirical Rule to describe the 90% distribution/range of X, i.e., the number
of waves dissipatable by the proposed structure per hour.
2) If the structure is built with dissipating a maximum 195 waves/hour capacity, what
fraction of an hour, i.e., minutes, might the structure be unable to handle incoming
waves (or in other word, how many minutes per hour the structure exceeds 195
waves/hour capacity)?
3) What wave dissipating capacity of the structure should be built so that the
probability of the incoming waves exceeding the structure capacity is equal to only
0.05 (or 5%)?

In: Statistics and Probability

Suppose patient demand for blood tests at a local hospital to screen for various illnesses is...

Suppose patient demand for blood tests at a local hospital to screen for various illnesses is given by Q = 5,000 - 10P, where Q is the number of tests and P is the price of each test in dollars. It costs the hospital a constant $250 to run each test.

(a).Now suppose that all patients that visit the hospital have insurance that covers 80% of the cost of a blood test. In that case, the number of blood tests that will be run at the hospital is __________ . The deadweight loss that results from the hospital administering blood tests in this case is _________$  (enter only numbers in the blank, and please round to the nearest whole number if necessary).

(b)Consider the hospital from the previous problems. Continue to assume that patients have insurance that covers 80% of the cost of a blood test. However, suppose that, because it helps to detect communicable diseases, each blood test that is administered has a positive externality that can be valued at $25. The deadweight loss resulting from the hospital administering blood tests in this case will be [size] in size relative to if there were no positive externality associated with the tests (enter just the word larger, smaller, or identical in the blank). __________

In: Economics

Suppose patient demand for blood tests at a local hospital to screen for various illnesses is...

Suppose patient demand for blood tests at a local hospital to screen for various illnesses is given by Q = 5,000 - 10P, where Q is the number of tests and P is the price of each test in dollars. It costs the hospital a constant $250 to run each test.

(a).Now suppose that all patients that visit the hospital have insurance that covers 80% of the cost of a blood test. In that case, the number of blood tests that will be run at the hospital is __________ . The deadweight loss that results from the hospital administering blood tests in this case is _________$  (enter only numbers in the blank, and please round to the nearest whole number if necessary).

(b)Consider the hospital from the previous problems. Continue to assume that patients have insurance that covers 80% of the cost of a blood test. However, suppose that, because it helps to detect communicable diseases, each blood test that is administered has a positive externality that can be valued at $25. The deadweight loss resulting from the hospital administering blood tests in this case will be [size] in size relative to if there were no positive externality associated with the tests (enter just the word larger, smaller, or identical in the blank). __________

In: Economics