Final answer:
The Gram class represents mass in grams with methods to convert to kilograms and pounds and to perform addition and subtraction with other Gram objects, ensuring no negative mass values.
Step-by-step explanation:
The question requires the implementation of a class in a programming context, specifically a class named Gram to represent mass in grams. This class should have a constructor to initialize the mass value, and include methods to convert the mass to other units such as kilograms and pounds. Additionally, it should be able to add and subtract mass values while ensuring the result never falls below zero.
Methods of the class include toKilos() which converts the gram value to kilograms by dividing the original value by 1000, and toPounds() which converts grams to US pounds by multiplying the value by 0.00220462. The add method allows for the addition of two Gram objects, whereas the sub method handles subtraction. If the resulting value of sub is less than zero, it is set to zero to prevent negative mass.