Chain Marketing Coding Question

Chain marketing Coding Question TCS 2020

TCS Coding Question Day 2 Slot 2 : Question 2

 

This question has been asked in the TCS NQT 2020 Day 2 Slot 1

Topic : Conditional Statement

Time Given : 30 Minutes

Difficulty : 3/5 stars

Chain Marketing Organization has has a scheme for income generation, through which its members generate income for themselves. The scheme is such that suppose A joins the scheme and makes R and V to join this scheme  then A is Parent Member of R and V who are child Members. When any member joins the scheme then the parent gets total commission of 10% from each of its child members.
Child members receive commission of 5% respectively. If a Parent member does not have any member joined under him, then he gets commission of 5%.
Take name of the members joining the scheme as input.
Display how many members joined the scheme including parent member.Calculate the Total commission gained by each members in the scheme. The fixed amount for joining the scheme is Rs.5000 on which commission will be generated
SchemeAmount = 5000

Example 1: When there are more than one child members 
Input : (Do not give input prompts.Accept values as follows. )
Amit                     //Enter parent Member as this
Y                           //Enter Y if  Parent member has child members otherwise enter N
Rajesh,Virat        //Enter names of child members of Amit in comma separated
Output:(Final Output must be in format given below.)
TOTAL MEMBERS:3
COMISSION DETAILS
Amit: 1000 INR
Rajesh :250 INR
Virat: 250 INR

Example 2: When there is only one child member in the hierarchy
Input :
Amit
Y
Rajesh
Output:
Total Members: 2 
Comission Details
Amit: 500 INR
Rajesh: 250 INR

Day 2 Slot 2 Question 1

Click on the below button to study Day 2 Slot 2 Question 1 of TCS NQT Coding 2020 exam

Code

TCS Coding Questions

Click on the below button to study more TCS Coding Question

TCS Coding Question

4 comments on “Chain Marketing Coding Question”


  • Arkamitra

    import java.util.Scanner;
    public class Ques22 {
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println(“enter parent member”);
    String s = sc.nextLine();
    int childCount = 0;
    double parentComission;
    boolean ans = true;
    final int scheme = 5000;
    for (int i = 0; i < 2; i++) {
    System.out.println("enter 'Y' if parent member has child or enter 'N' ");
    String status = sc.next();
    if (status.equals("Y")) {
    childCount++;
    ans=true;
    }
    else if (status.equals("N")){
    ans = false;
    }

    }
    System.out.println("enter name of child");
    String name="";
    int j=0;
    while ( j<childCount){
    if(ans==true){
    name = sc.nextLine();
    }
    else if(ans==false){
    break;
    }
    j++;
    }

    parentComission = (0.1 * scheme) * childCount;
    double childComission = (0.05 * scheme);
    int totalMember = 1 + childCount;
    System.out.println("TOTAL MEMBERS: " + totalMember);
    System.out.println("COMISSION DETAILS\n");
    System.out.println(s + " : " + parentComission + "INR");
    if(childCount==2){
    System.out.println(name.substring(0,name.lastIndexOf(",")) + " : " + childComission + "INR");
    System.out.println(name.substring((name.lastIndexOf(",")+1),name.length()) + " : " + childComission + "INR");
    }
    else if(childCount==1){
    System.out.println(name + " : " + childComission + "INR");
    }

    }
    }


  • Shreyas

    import java.util.Scanner;
    public class ChainMarketing {

    public static void main(String args[]) {

    Scanner sc = new Scanner(System.in);
    String parent = sc.next();
    char yn = sc.next().charAt(0);
    int pcomm=0;
    if(yn== ‘N’) {
    pcomm = 250;
    System.out.println(“Total members: 1”);
    System.out.println(“Commission details\n”+parent+” “+pcomm);
    }
    else if(yn == ‘Y’) {
    int chComm1,chComm2;
    String child[] = new String[2];
    child = sc.next().split(“,”);
    pcomm = 1000;
    chComm1 = 250;
    chComm2 = 250;

    System.out.println(“Total members: 3”);
    System.out.println(“Commission details\n”+parent+” “+pcomm);

    System.out.println(child[0]+” “+chComm1);
    System.out.println(child[1]+” “+chComm2);

    }
    else
    System.out.println(“INVALID INPUT”);
    }
    }


  • Ankita

    package PrepInsta;

    import java.util.Scanner;

    public class Commision {

    public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    String Parent=sc.nextLine();
    char ch=sc.next().charAt(0);

    int count=1;
    int schemeAmt=5000;
    int ParentCom=0;

    if(ch==’Y’)
    {
    String Child=sc.next();
    String[] member=Child.split(“,”);
    count=member.length;
    System.out.println(“Total member: “+(count+1));

    System.out.println(“Commision Details: “);
    int x=count*5000;
    ParentCom=(x*10)/100;
    System.out.println(Parent+”:”+ParentCom+”INR”);

    for(int i=0;i<member.length;i++)
    {

    int memberCom=(5*5000)/100;
    System.out.println(member[i]+":"+memberCom+"INR");

    }
    }
    if(ch=='N')
    {
    System.out.println("Total member:1");
    System.out.println("Commision Details: ");
    System.out.println(Parent+":"+ 250 +"INR");
    }
    }

    }


    • Anil

      p=input()
      c=input()
      x=list(map(str,input().split(‘,’)))
      if c == “y”:
      Total=1+len(c)
      print(“TOTAL MEMBERS:”,Total)
      print(“COMMISION DETAILS:”)
      print(p,’:’,len(x)* 500)
      for i in x:
      print(i,’:’,250)
      if c==’n’:
      print(“TOTAL MEMBERS:”,1)
      print(“COMMISION DETAILS:”)
      PRINT(P,’:’,250)