These questions are slightly open-ended, so remember to start by building something
simple. SAVE IT, then progressively make it snazzier. For example, tackling the second
question, it would make sense to start by writing a program which has the numbers already
hard-coded into the program to check that you can actually find the max, min, mean and
stdD of a collection of numbers. When that works, move on to i/o by reading the numbers
from the keyboard in the way we've discussed in class. Finally, try reading numbers in from a file
(initially from a file whose name has been hard-coded into the program, but later from a file whose
name has been acquired by the program as described below);
first with the file having just one line of space-separated numbers, and then many such lines.
- 'Strings' can be added together (appending, concatenation) using the '+' operator. Write a program having methods
append(String x, String y) and deAppend(String x, String y) where the first method returns the String
having value that of x + y and the second one returns the String x either unchanged or with y
removed (if y happens to match the final substring of x). For example, if x = abchuttd,
y = wthhe and z = uttd then append(x,y) will return abchuttdwthhe,
deAppend(x,y)will return abchuttd, and deAppend(x,z) will return abch.
Your program should ask for two Strings and ask if the second string should be appended or 'de-pended' from the
first.
- Write a program which will offer two ways to handle data to be analysed; the
data being a collection of numbers (doubles). The 'analysis' will comprise
finding the max and the min of the collection of numbers, as well as the mean* and
the standard deviation*. The first way of gathering the data should invite the user
to type in numbers at the keyboard once the program has been started, with the 'typing'
of an empty string or the typing of a non-number being used to terminate the list of
numbers. The second choice to be provided
should ask the user for the name of a file to be read from, this file containing a space
separated list of 'doubles' spread over several lines. When the program starts, it should ask the user if
they'd prefer to type in data or give the name of a file holding the data, and then run
accordingly. In both cases the answer should be displayed on the screen, though an option should be provided
to write the analysis data to a file whose name has also been asked for by the program.
* The mean, m, of a list of numbers, (a1, a2, a3, ..., an), is the average, ie
m = (a1 + a2 + ... + an) / n ; and the standard deviation, s, is the square root of the
average of the squares of the differences between the numbers and the mean, ie
s = sqrt[ ( (a1 - m)^2 + (a2 - m)^2 + ... + (an - m)^2 ) / n ] . (Note that there is
some variation in the stats community about whether to divide by n or (n-1) when computing the standard deviation.
This arises perhaps since dividing by n fits within the whole theory of moments, which puts things like means,
std devs, skewness, kurtosis, etc in a consistent framework, whereas dividing by (n-1) reflects nicely the numbers
of degrees of freedom, which fits well within sampling theory. Since there are good arguments for adopting each
version, we'll adopt the division by n version simply to aim for consistency of answers within the course.)
- Write a program to convert numbers from 'base p' to 'base q', where p and q are integers. (So for example, the
number 2231322 regarded as being written base 5 would equal
2(5^6) + 2(5^5) + 3(5^4) + 1(5^3) + 3(5^2) + 2(5^1) + 2.) Your program should ask the
user for the two 'bases' to convert between, and should ask for the initial number, and then display the converted
description of that number. (Again, think simply at first. Write something which will convert from base p into
base 10, then generalise it to writing into base q. Don't start off being clever with bases larger than nine, or
negative numbers or fractional
numbers (decimals, p-mals?). Remember that simple and working is better than sophisticated and broken, at least at
this stage!) Provide also the ability for your program to add two numbers given in the same base. To accomodate this,
your program should provide the option to add instead of convert.