Java Reference
In-Depth Information
ask what the current month is and then ask for the rainfall figures for the previ-
ous 12 months. The output should correctly label the months. There are a vari-
ety of ways to deal with the month names. One straightforward method is to
code the months as integers and then do a conversion to a string for the month
name before doing the output. A large switch statement is acceptable in an out-
put method. The month input can be handled in any manner you wish so long
as it is relatively easy and pleasant for the user. Include a loop that allows the user
to repeat this entire calculation until the user requests that the program end.
4.
Write a static method called deleteRepeats that has a partially filled array
of characters as a formal parameter and that deletes all repeated letters from
the array. Because a partially filled array requires two arguments, the method
should actually have two formal parameters: an array parameter and a formal
parameter of type int that gives the number of array positions used. When a
letter is deleted, the remaining letters are moved one position to fill in the
gap. This creates empty positions at the end of the array so that less of the
array is used. Because the formal parameter is a partially filled array, a second
formal parameter of type int should tell how many array positions are filled.
This second formal parameter cannot be changed by a Java method, so have
the method return the new value for this parameter. For example, consider
the following code:
char a[10];
a[0] = 'a';
a[1] = 'b';
a[2] = 'a';
a[3] = 'c';
int size = 4;
size = deleteRepeats(a, size);
After this code is executed, the value of a[0] is 'a' , the value of a[1] is 'b' , the
value of a[2] is 'c' , and the value of size is 3 . (The value of a[3] is no longer
of any concern, because the partially filled array no longer uses this indexed
variable.) You may assume that the partially filled array contains only lowercase
letters. Write a suitable test program for your method.
5.
The standard deviation of a list of numbers is a measure of how much the numbers
deviate from the average. If the standard deviation is small, the numbers are clustered
close to the average. If the standard deviation is large, the numbers are scattered far
from the average. The standard deviation of a list of numbers n 1 , n 2 , n 3 , and so forth
is defined as the square root of the average of the following numbers:
(n 1 - a) 2 , (n 2 - a) 2 , (n 3 - a) 2 , and so forth.
The number a is the average of the numbers n 1 , n 2 , n 3 , and so forth.
Define a static method that takes a partially filled array of numbers as its argument
and returns the standard deviation of the numbers in the partially filled array.
Because a partially filled array requires two arguments, the method should actually
Search WWH ::




Custom Search