Question

In: Computer Science

I want the program to use 1- D array and display a table as output. Write...

I want the program to use 1- D array and display a table as output.

Write a script to simulate the rolling of two dice. The script should use Math.random to roll the first die and again to roll the second die. The sum of the two values should then be calculated. [Note: Since each die can show an integer value from 1 to 6, the sum of the values will vary from 2 to 12, with 7 being the most frequent sum, and 2 and 12 the least frequent sums. Figure 10.22 shows the 36 possible combinations of the two dice. Your program should roll the dice 36,000 times. Use a one-dimensional array to tally the number of times each possible sum appears. Display the results in an HTML5 table. Also determine whether the totals are reasonable (e.g., there are six ways to roll a 7, so approximately 1/6 of all the rolls should be 7).]

Solutions

Expert Solution

<!DOCTYPE html>
<html>
<body>
<script language="javascript" type="text/javascript">
var myArray = new Array();
var min=1;
var max=7;
var i=0;
for(i=1;i<=3600;i++)
{
var random1=Math.floor(Math.random() * (+max - +min)) + +min;
var random2=Math.floor(Math.random() * (+max - +min)) + +min;
myArray[i]=random1+random2;
}
var myTable= "<table><tr><td style='width: 100px; color: red;'>Col Head 1</td>";
myTable+= "<td style='width: 100px; color: red; text-align: right;'>Col Head 2</td></tr>";

myTable+="<tr><td style='width: 100px; '>---------------</td>";
myTable+="<td style='width: 100px; text-align: right;'>---------------</td></tr>";

for (var i=1; i<=3600; i++) {
myTable+="<tr><td style='width: 100px;'>Sum " + i + " is:</td>";
myArray[i] = myArray[i];
myTable+="<td style='width: 100px; text-align: right;'>" + myArray[i] + "</td></tr>";
}
myTable+="</table>";
document.write( myTable);
</script>
</body>
</html>


Related Solutions

Java Program Use for loop 1.) Write a program to display the multiplication table of a...
Java Program Use for loop 1.) Write a program to display the multiplication table of a given integer. Multiplier and number of terms (multiplicand) must be user's input. Sample output: Enter the Multiplier: 5 Enter the number of terms: 3 5x0=0 5x1=5 5x2=10 5x3=15 2 Create a program that will allow the user to input an integer and display the sum of squares from 1 to n. Example, the sum of squares for 10 is as follows: (do not use...
For C program, convert the 1-D stencil program from lab03 to use array reference (B[I]) to...
For C program, convert the 1-D stencil program from lab03 to use array reference (B[I]) to access array element instead of using pointers. The C program follows these steps: 1) declare two arrays, each has 100 elements; 2) use a for loop to randomly generate 100 integers and store them in one array; 3) use another for loop to do the 1-D stencil and store the result in the other array;
powers: Write a program to display the following table with headings and totals. You must use...
powers: Write a program to display the following table with headings and totals. You must use variables to represent all quantities and a for loop for repetition.          x       x^2      x^3          11      121      1331          14      196      2744          17      289      4913          20      400      8000          23      529      12167          26      676      17576          29      841      24389          32      1024     32768          35      1225     42875          38      1444     54872 Totals:  245     6745     201635
Create a Java8 Program to play Bulgarian Solitaire: Use an Assertion Use Array and/or ArrayList Display...
Create a Java8 Program to play Bulgarian Solitaire: Use an Assertion Use Array and/or ArrayList Display every turn/iteration of this game. Simple print statements with asterisks is fine.
Pandas exercises: 1. Write a python program using Pandas to create and display a one-dimensional array-like...
Pandas exercises: 1. Write a python program using Pandas to create and display a one-dimensional array-like object containing an array of data. 2. Write a python program using Pandas to convert a Panda module Series to Python list and print it's type. (Hint: use ds.tolist() to convert the pandas series ds to a list) 3. Create a pandas dataframe called **my_df** with index as integer numbers between 0 to 10, first column (titled "rnd_int") as 10 integer random numbers between...
Write Matrix Addition 2 D (dimensional) Array program in c++.
Write Matrix Addition 2 D (dimensional) Array program in c++.
Meant to be written in Java JDK 14.0 Write a program to display the conversion table...
Meant to be written in Java JDK 14.0 Write a program to display the conversion table from meter to feet using formatted output (printf()): 1 meter = 3.28084 feet; 1 foot = 12 inch When display the number, round the number to 2 decimal places. Set the number in the 1st the 2nd columns to the left align, set the 3rd column to the right align: meter(s) feet inch(es) 1 3.28 37.37 2 x.xx xx.xx 3 x.xx xxx.xx
I want to write this program in java. Write a simple airline ticket reservation program in...
I want to write this program in java. Write a simple airline ticket reservation program in java.The program should display a menu with the following options: reserve a ticket, cancel a reservation, check whether a ticket is reserved for a particular person, and display the passengers. The information is maintained on an alphabetized linked list of names. In a simpler version of the program, assume that tickets are reserved for only one flight. In a fuller version, place no limit...
Write a program to calculate the area and circumference of a cuboid. Use printf to display...
Write a program to calculate the area and circumference of a cuboid. Use printf to display 2 digits after decimal point in all the results Program should be in java language.
Write a Java program that will use a two-dimensional array to solve the following tasks: 1....
Write a Java program that will use a two-dimensional array to solve the following tasks: 1. Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. 2. Create a method to print the array. 3. Create a method to find the largest element in the array 4. Create a method to find the smallest element in the array 5. Create a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT