Free University of Bolzano/Bozen
Faculty of Computer Science - Bachelor in Applied Computer Science
Bachelor in Production Engineering
Introduction to Programming - A.A. 2006/2007

Exercise 7

Loop statements and Arrays

Exercise 7A

Design and realize a class Experiment that stores data obtained from a temperature measurement. The data values are delivered as a string of space-separated integers (at least one) and are stored in an array of integers.
The class Experiment should export the following functionalities:

Hint: use the StringTokenizer class once more to implement the constructor. Use its countTokens methods to count the number of integers in the input string.

Exercise 7B

Extend the class Experiment with the following functionalities:

Finally, implement a method toString that returns a string representation of the experiment's data values.

Solution for 7A and 7B

Exercise 7C

Write a client class for the class Experiment that does the following:

  1. create two experiments from data inserted by the user;
  2. print the number of values, the sum as well as the average and minimum values of the two experiments;
  3. check whether the two experiments are equal and print a message accordingly;
  4. if they're not equal, check whether they are similar and print a message accordingly;
  5. create an experiment that contains the data of both experiments;
  6. have the user input an integer value and print out how often it is present in the newly merged experiment;
  7. check if there are repeated values in the merged experiment;
  8. have the merged experiment plotted;

Hint: to have the user input a data set, implement a static method that:
  1. repeatedly calls JOptionPane.showInputDialog() (or the nextLine() or next() method of the Scanner class) until the user presses Cancel,
  2. builds a space-separated string from the so-inserted integer values,
  3. creates an Experiment object by passing the string to the constructor of Experiment, and
  4. returns such an object.