Individual: Simple Commission Calculation Program Part 2

profilejaego
commission1.zip

commission1/Application.java

commission1/Application.java


import  java . util . Scanner ;
import  java . text . NumberFormat ;

public   class   Application   {
     public   static   void  main ( String  args []){

         //create an object of Scanner class to get the keyboard input
         Scanner  keyInput  =   new   Scanner ( System . in );
         //for currency format
         NumberFormat  numberFormat  =   NumberFormat . getCurrencyInstance ();

         //creating an object of SalesPerson class
         SalesPerson  salesPerson  =   new   SalesPerson ();

         //prompt the user to enter the annual sales
         System . out . print ( "Enter the annual sales : " );
         double  sale  =   keyInput . nextDouble ();

         //set the value of annual sale of sales person object
        salesPerson . setAnnualSales ( sale );

         //displaying the report
         System . out . println ( "The total annual compensation : " + numberFormat . format ( salesPerson . getAnnualCompensation ()));
     }

}

commission1/SalesPerson.java

commission1/SalesPerson.java


public   class   SalesPerson   {
    
     private   final   double  fixedSalary   =   120000.00 ;
     private   final   double  commissionRate  =   .04 ;

     private   double  annualSales ;

     //default constructor
     public   SalesPerson ()   {
        annualSales  =   0.0 ;
     }

     //parameterized constructor
     public   SalesPerson ( double  aSale )   {
        annualSales  =  aSale ;
     }

     //getter method for the annual sales
     public   double  getAnnualSales (){
         return  annualSales ;
     }

     //method to set the value of annual sale
     public   void  setAnnualSales ( double  aSale )   {
        annualSales  =  aSale ;
     }

     //method to calculate and get commission
     public   double  getCommission (){
         return  annualSales  *   ( commissionRate / 100.0 );
     }

     //method to calculate and get annual compensation
     public   double  getAnnualCompensation (){
         return  fixedSalary   +  getCommission ();
     }

}