Work in pairs on this lab.
Write a program that has an array of articles, an array of adjectives,
an array of nouns, and an array of verbs and constructs random sentences
based on the scheme
article + adjective + noun + verb
For instance, the program may randomly select an article "My", an adjective "old",
a noun "dog", and a verb "is walking", to make a sentence "My old dog is walking".
Make sure to have at a different number of elements in different arrays
(for instance, you would probably have fewer articles than nouns).
Write methods as needed; avoid code repetition (if you repeat roughly
the same code, make it into a method).
Write a program that simulates 500 rolls of two six-sided dice. Create an array of integers to count how many times each sum occurs. For instance, if you get 3 on the first die and 5 on the second one, then the result is 8, and the array element that counts the number of 8s needs to be incremented. At the end print out how many times each sum occurred. In comments write your conclusions about probabilities of different sums.
Write and test a method int
) and returns the number of negative elements in the array.
Write and test a method
The strings need to be changed in the orginal array. The return type of the method is void
.
This program seems to produce an unexpected result. Please explain what's happening and why.
public class Lab3Example {
public static void main(String[] args) {
// Should be 2000, right?
System.out.println(method(100l));
}
public static long method(long n) {
for (int i = 0; i < 999; ++i) {
n = n + 1;
}
return n;
}
}
Submit the java file(s) by e-mail to me. The subject of the message must be 2101 Lab 3. Make sure to CC your group partner.