[text] updatedprac6

Viewer

copydownloadembedprintName: updatedprac6
  1. package prac6;
  2.  
  3. public class PlayerDemo {
  4.  
  5.         public static void main(String[] args) {
  6.                 // TODO Auto-generated method stub
  7.                 Player p1=new Player(11,"Rohit",34,200,false);
  8.                 Player p2=new Player(12,"sachin",40,350,true); 
  9.                 Player p3=new Player(13,"dhoni",39,280,true); 
  10.                 Player p4=new Player(14,"sevag",41,290,true); 
  11.                 Player p5=new Player(15,"kohli",32,300,false);
  12.                 Player[] pList=new Player[5]; 
  13.                 pList[0]=p1; pList[1]=p2;
  14.                 pList[2]=p3; pList[3]=p4; 
  15.                 pList[4]=p5; 
  16.                 Player[] rList=findSeniorPlayers(pList);
  17.                 for(int i=0;i<rList.length;i++)
  18.                 { 
  19.                         System.out.println("Senior Name is "+ rList[i].getName()+ " and run is "+rList[i].getHighestRuns());
  20.                         } 
  21.         String[] snew=findTopPlayers(pList); 
  22.         System.out.println("top players are:");
  23.                 for(int i=0;i<snew.length;i++)
  24.                 { 
  25.                         System.  out.println(snew[i]); 
  26.                 } 
  27.                 }
  28.        
  29.        
  30.         public static Player[] findSeniorPlayers(Player[] pList)
  31.         {int count=0;
  32.                 for(int i=0;i<pList.length;i++)
  33.                 {
  34.                         if(pList[i].getAge()>35)
  35.                         {
  36.                                 count++;
  37.                         }
  38.                 }
  39.                 Player[] tmp=new Player[count];
  40.                 int j=0;
  41.                 for(int i=0;i<pList.length;i++)
  42.                 {
  43.                         if(pList[i].getAge()>35)
  44.                         {
  45.                                 tmp[j]=pList[i];
  46.                                 j++;
  47.                         }
  48.                 }
  49.                 return tmp;
  50.         }
  51.         public static String[] findTopPlayers(Player[] pList)
  52.         {
  53.                 int count=0;
  54.                 for(int i=0;i<pList.length;i++)
  55.                 {
  56.                         if(pList[i].getHighestRuns()>250)
  57.                         {
  58.                                 count++;
  59.                         }
  60.                 }
  61.                 String[] tmp1=new String[count];
  62.                
  63.                 int j=0;
  64.                 for(int i=0;i<pList.length;i++)
  65.                 {
  66.                         if(pList[i].getHighestRuns()>250)
  67.                         {
  68.                                 tmp1[j]=pList[i].getName()+" : "+pList[i].getHighestRuns();
  69.                                
  70.                                 j++;
  71.                         }
  72.                 }
  73.                 return tmp1;
  74.         }
  75.        
  76.         }
  77.  
  78.  
  79.  

Editor

You can edit this paste and save as new:


File Description
  • updatedprac6
  • Paste Code
  • 17 Feb-2020
  • 1.63 Kb
You can Share it: