38: Quiz#10: Modules and classes , Name: ___________________________
CS 340, Fall 2019, York College of Pennsylvania
41, 20 points, 2019-12-05 (at start of class)
Write a small example that has a main code part and a module part that contains a class. Draw a box around the module and the main code and label each as main or module.
The module part should define a class
Adder. Use your initials for the prefix of the module name. The module name suffix should be
Adder. The constructor should set the integer class sum to zero. The class should contain a method
sumAdd which takes one integer and adds that value to the sum. The class should contain a method
sumGet which should return the current sum.
The main code should access the module, create an instance of the
Adder class and then call that instance to add the integer values from
0 to
8 (inclusive) using the
sumAdd method of the
Adder class. The main code should then use the
sumGet method to get and display the sum using a print statement.
Note: This example can be worked out and tested before the quiz, but you need to remember how to do the various parts from memory for the quiz.
Module code complete filename: _________________________ (not C, C++, Java)
Here are some general comments.