If you use a “one class, one main method” approach to grade 10 Java, this is a good end-of-year exercise revising the work done during the year. This program reads in a text file of “learner houses” and “money raised”. It totals the amount raised per house, and then gives a final total. Each house has its own array and counter.

The program features the following coding structures and algorithms . . .

  • Reading from a text file using simple String handling instead of delimiters.
  • Using the Scanner class to access the text file.
  • Storing data in different one dimensional arrays.
  • Features the while loop, the for loop and if else.
  • Rounds off to two decimal places using DecimalFormat.

INPUT – TEXT FILE LOOKS LIKE THIS . . .
The learners house, followed by the amount of money the learner raised.
Houses are – Ibus, Kingfisher, Weaver and Cormorant.

C 84.81
W 46.52
I 42.59
W 48.81
K 79.97
C 41.85
W 87.71 etc etc

OUTPUT LOOKS LIKE THIS . . .

Click here for the text file.

Click here for the solution

HOWEVER . . .

I do not believe in the one class, one main method teaching of Java. Period.

For my grade 10 novice coders we start OOP right out of the box, “Java-101” with an OOP approach to even “Hello World” i.e. a UI class and a manager class (this prevents me from having to “unteach” in grade 11 – this makes no sense to me.)

Here is the OOP version of the same program in a single Notepad++ format

Click here

The text file is above . . .