Answer to Question #248244 in C++ for Junaid

Question #248244
You are to write a code that simulates the working of a Cosmetic Store which has a small sales team.
The store pays commissions to each member of its sales team every six months. The commission is
based on the total sales generated by each employee and their position in the company. You need to
design a code that calculates and compares the commissions earned by every member of the sales
team and also clearly identifies the sales team member earning the highest commissions.
1
Expert's answer
2021-10-08T04:35:10-0400
import java.util.*;

class Test{
   public static void main(String args[]){
       Scanner sc=new Scanner(System.in);
       System.out.print("Enter Name: ");
       String name=sc.nextLine();
       System.out.println("Enter E for Entry Level employee");
       System.out.println("Enter M for Mid Level employee");
       System.out.println("Enter T for Top Tier Level employee");
       char type=sc.next().charAt(0);
      
       //clear buffer
       sc.nextLine();
       System.out.print("Enter date of joining: ");
       String doj=sc.nextLine();
      
       //create a Salesperson
       Salesperson sp=new Salesperson(name,doj,type);
      
       //compute the comission
       sp.Calculate_quarterly_sales();
      
       //display the resutl
       sp.display();
   }
}

class Salesperson{
   //member variables
   private String name;
   private String doj;
   private char type;
   private double comm_1;
   private double comm_2;
  
   //constructor
   Salesperson(String name,String doj,char type)
   {
       this.name=name;
       this.doj=doj;
       this.type=type;
       this.comm_1=0;
       this.comm_2=0;
   }
  
   void Calculate_quarterly_sales()
   {
       Scanner sc=new Scanner(System.in);
       System.out.print("Enter the total sales for first six months: ");
       double sales1=sc.nextDouble();
       System.out.print("Enter the total sales for next six months: ");
       double sales2=sc.nextDouble();
      
       if(type=='E')
       {
           comm_1=(5*sales1)/100;
           comm_2=(5*sales2)/100;
       }
       else if(type=='M')
       {
           comm_1=(10*sales1)/100+6000;
           comm_2=(10*sales2)/100+6000;
       }
       else{
           comm_1=(20*sales1)/100+12000;
           comm_2=(20*sales2)/100+12000;
       }
   }
  
   String getType()
   {
       if(type=='E')
           return "Entry Level employee";
       else if(type=='M')
           return "Mid Level employee";
       else
           return "Top Tier employee";
   }
  
   void display()
   {
       System.out.println("\nSalesperson Information:");
       System.out.println("Name: "+name);
       System.out.println("Type: "+getType());
       System.out.println("Date Of Joining: "+doj);
       System.out.printf("Comission for Jan-June: %.2f\n",comm_1);
       System.out.printf("Comission for July-December: %.2f\n",comm_2);
   }
}
  

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS