Javadocs Exercises

  < Previous  Next >
  1. Discuss with someone else what is the difference between a Javadoc (comment) and a multi-line comment
  2. Discuss with someone else:
    1. What is a Javadoc tag
    2. When and how to use the @author tag
    3. When and how to use the @version tag
    4. When and how to use the @param tag
    5. When and how to use the @return tag
    6. When and how to use the @see tag
  3. Write appropriate Javadocs for the code below:
    public class TaxCalculator{
        private double tax;  // the amount of tax due
    
        // annual income in dollars
        private final double LEVEL_1_INCOME = 10_000.00;
        private final double LEVEL_2_INCOME = 50_000.00;
        private final double LEVEL_3_INCOME = 100_000.00;
    
        private final double TAX_RATE_1 = 0.10; // % of income
        private final double TAX_RATE_2 = 0.15; // % of income
        private final double TAX_RATE_3 = 0.20; // % of income
        private final double TAX_RATE_4 = 0.30; // % of income
    
        public TaxCalculator( ){
    	tax = 0.0;
        }
    
        /*
         * Returns the amount of tax due:
         * if income is less than $10,000, 10% of income
         * if income is less than $50,000, 15% of income
         * if income is less than $100,000, 20% of income
         * otherwise, 30% of income
         */
        public double getTax( double income ){
    	if( income < LEVEL_1_INCOME ){
    	    tax = income * TAX_RATE_1;
    	}else if( income < LEVEL_2_INCOME ){
    	    tax = income * TAX_RATE_2;
    	}else if( income < LEVEL_2_INCOME ){
    	    tax = income * TAX_RATE_3;
    	}else{
    	    tax = income * TAX_RATE_4;
    	}
    	tax = Math.round(tax * 100.0) / 100.0; // round to 2 decimal places
    	return tax;
        }
    }