# Code Samples

The following examples are used to illustrate this topic.

  1. Calculator – This class introduces simple arithmetic operations, demonstrating simple addition and multiplication.
  2. Person - This adaptation of the person class changes the previous design by replacing the age field with a "read-only" field for the person's birth date. The approximate age of the person is then calculated based on the current date and the birth date.
  3. Account - This class illustrates simple addition and calculation by allowing deposits and withdrawals. Note that changes to the balance can now only be made through deposits and withdrawals; the balance is now "read-only".
  4. ElapsedTime – This class demonstrates overloaded constructors and introduces the concepts of operator precedence and integer division.
  5. ResolveExpressions – This class is used in conjuncture with several sample expressions that illustrate operator precedence and automatic type conversion.
  6. Circle - This class represents a simple circle of a specified diameter. The radius, area and circumference are calculated.
  7. Square - This class represents a simple square with a specified length for its side. The area and perimeter are calculated.
  8. Fraction - This class represents a fraction as a numerator and denominator. It provides the double equivalent of the fraction's value as well as a string representation that uses the numerator and denominator. It demonstrates type casting and the integer division issue.
  9. Angle - This class represents an angle and provides the value in the following units: degrees, radians and grads. It also gives a simple example of unicode characters (for degrees).
  10. StockItem - This class represents an item that is part of an inventory. The item has an item name, a cost and a profit margin (which can be positive or negative). By using the profit margin, it can derive the price of the item. This example illustrates rounding.
  11. Die - This class represents a single six-sided die. This example is used to illustrate random number generation and casting.
  12. ParkingCounter - This class represents a simple counter to monitor whether a parking lot is full or not; it tracks vehicles entering and leaving the parking lot and allows the counter to be reset when the lot is full or empty. This class illustrates increment and decrement operators and/or the assignment increment or assignment decrement operators.
  13. QuadradicEquation - This class is used to solve for the two possible values of a quadratic formula where quadradic equals zero. This sample illustrates order of operations and parentheses.
Last updated on: 9/21/2019, 11:09:56 PM