⌛ Median

The program is built using Maven. Place the pom.xml file in the round3/median directory of your local repository and create to this directory the src/main/java subdirectory. You may name your classes freely, as long as your files are in the round3/median/src/main/java directory. If you create your project with NetBeans, it’s recommended to leave the Package: field empty, to ensure the files are placed in the correct directory.

The program should first output the prompt Enter numbers: after which the numbers the median is calculated from are given. The numbers must be given in a single line, separated by spaces. The numbers are converted into double values, and the program prints out their median in the form “Median: x”, where x is the median of the numbers.

We define median as the number that occurs in the middle when the numbers are sorted into ascending order. If the count of numbers is even, the median is computed as the mean of the two middle-most numbers.

The automatic tests, and the ones given below, assume that you make the following definitions in your pom.xml project file:

  • The value of artifactId is median.

  • The value of version is 1.0.

  • The values of the maven.compiler.source and maven.compiler.target elements are 17 or lower. The grader uses Java 17, so any newer versions won’t work.

  • A Onejar plugin definition where the value of mainClass element refers to the main class of your program, which you can name freely in this task. For example, if your main class is named Median, the element value is Median.

Example

The tests compile your program with the following command:

mvn package

If the compilation is successful the program is run with this command:

java -jar target/median-1.0.one-jar.jar

The program outputs the prompt Enter numbers: after which the numbers from which the median is calculated are given. In the first test the numbers are:

58.03125 62.5 75.03125 25.03125 -39.9375 7 -38.75

The expected program output in the first test is:

Enter numbers:
Median: 25.03125

Explanation: the numbers sorted into ascending order are -39.9375, -38.75, 7, 25.03125, 58.03125, 62.5, 75.03125. There are 7 numbers (an odd number) and the median is the middle-most, that is, 4th number 25.03125.

In the second test the numbers are:

-37.5 -37.875 -87.9375 -41.5 100.125 53.0625 48.03125 -48

Now the expected program output is:

Enter numbers:
Median: -37.6875

Explanation: the numbers sorted into ascending order are -87.9375, -48, -41.5, -37.875, -37.5, 48.03125, 53.0625, 100.125. There are 8 number (en even number) and the two middle-most numbers are -37.875 and -37.5. The median is the mean of these two: (-37.875 + -37.5) / 2 = -37.6875.

Submitting

Make sure before submission that your files are in the /round3/median/ directory and that you have pushed the latest changes to your personal remote repository. When ready, enter the URL of your personal remote directory in the field below. The URL is https://course-gitlab.tuni.fi/compcs140-fall2023/------, where ------ denotes your Tampere university username.

A+ presents the exercise submission form here.