[text] eee

Viewer

  1. public class CertificateDemo1 {
  2.  
  3.         public static void main(String[] args) {
  4.                 // TODO Auto-generated method stub
  5.                 Certificate1 certificate1= new Certificate1(60,"cnexirk","cbnifms",77);
  6.                 Certificate1 certificate2= new Certificate1(45,"gphspvq","pqjbhmz",62);
  7.                 Certificate1 certificate3= new Certificate1(41,"nfpxsmp","vimiopu",89);
  8.                 Certificate1 certificate4= new Certificate1(95,"ionouca","bsbknpx",38);
  9.                 Certificate1 certificate5= new Certificate1(39,"yhzrafu","itnbskb",44);
  10.  
  11.  
  12.                 Certificate1[] objArray= {certificate1,certificate2,certificate3,certificate4,certificate5};
  13.  
  14.                 Certificate1[] objResultArray1= getEvenPositionCertificate(objArray);
  15.                
  16.                
  17.                 if(objResultArray1==null){
  18.                         System.out.println("Output after first operation is null. ");
  19.                         }else{
  20.                         System.out.println("Displaying contents of result array: ");
  21.  
  22.                         for(Certificate1 certificate:objResultArray1){
  23.                         System.out.println(certificate.getId()+" " + certificate.getTitle()+" " + certificate.getDate()+" " + certificate.getRank()+" ");
  24.                         }
  25.                
  26.                         }
  27.                
  28.                
  29.                
  30.                
  31.                
  32.         }
  33.  
  34.        
  35.         public static Certificate1[] getEvenPositionCertificate(Certificate1[] obj)
  36.         {
  37.                 int n=((obj.length)/2)+1;
  38.                 Certificate1[] obj1=new Certificate1[n];
  39.                 int j=0;
  40.                 for(int i=0; i<obj.length; i++)
  41.                 {
  42.                         if(i%2==0)
  43.                         {
  44.                                 obj1[j]=obj[i];
  45.                                 j++;
  46.                         }
  47.                 }
  48.                
  49.                
  50.                
  51.                
  52.                
  53.                 return obj1;
  54.         }
  55.        
  56.        
  57.        
  58.        
  59.        
  60. }
  61.  
  62.  class Certificate1
  63. {
  64.         private int id,rank;
  65. private String title,date;
  66. public Certificate1(int id,String title,String date,int rank)
  67. {this.id=id;
  68. this.title=title;
  69. this.date=date;
  70. this.rank=rank;
  71.        
  72. }
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. int getId()
  81. {
  82.         return id;
  83. }
  84. int getRank()
  85. {
  86.         return rank;
  87. }
  88. String getTitle()
  89. {
  90.         return title;
  91. }
  92. String getDate()
  93. {
  94.         return date;
  95. }
  96. void setId(int id)
  97. {
  98.         this.id=id;
  99. }
  100.  
  101.  void setRank(int rank) {
  102.         this.rank = rank;
  103. }
  104.  
  105.  void setTitle(String title) {
  106.         this.title = title;
  107. }
  108.  
  109.  
  110.  void setDate(String date) {
  111.         this.date = date;
  112. }
  113.  
  114.  
  115. }
  116. .......................................................................................................................................................................
  117. public class CertificateDemo1 {
  118.  
  119.         public static void main(String[] args) {
  120.                 // TODO Auto-generated method stub
  121.                 Certificate1 certificate1= new Certificate1(60,"cnexirk","cbnifms",77);
  122.                 Certificate1 certificate2= new Certificate1(45,"gphspvq","pqjbhmz",62);
  123.                 Certificate1 certificate3= new Certificate1(41,"nfpxsmp","vimiopu",89);
  124.                 Certificate1 certificate4= new Certificate1(95,"ionouca","bsbknpx",38);
  125.                 Certificate1 certificate5= new Certificate1(39,"yhzrafu","itnbskb",30);
  126.  
  127.  
  128.                 Certificate1[] objArray= {certificate1,certificate2,certificate3,certificate4,certificate5};
  129.  
  130.                 Certificate1[] objResultArray1= searchCertificateByRank(objArray,44);
  131.                
  132.                
  133.                 if(objResultArray1.length==0){
  134.                         System.out.println("Output after first operation is null. ");
  135.                         }else{
  136.                         System.out.println("Displaying contents of result array: ");
  137.  
  138.                         for(Certificate1 certificate:objResultArray1){
  139.                         System.out.println(certificate.getId()+" " + certificate.getTitle()+" " + certificate.getDate()+" " + certificate.getRank()+" ");
  140.                         }
  141.                
  142.                         }
  143.                
  144.                
  145.                
  146.                
  147.                
  148.         }
  149.  
  150.        
  151.         public static Certificate1[] searchCertificateByRank (Certificate1[] obj,int rank)
  152.         {
  153.                
  154.                 int j=0;
  155.                 int c=0;
  156.                 for(int i=0; i<obj.length; i++)
  157.                 {
  158.                         int no=obj[i].getRank();
  159.                         if(no==rank) {
  160.                                 c++;
  161.                         }
  162.                 }
  163.                
  164.                 Certificate1 [] arr=new Certificate1[c];
  165.                
  166.                
  167.                 for(int i=0; i<obj.length; i++)
  168.                 {
  169.                         int no=obj[i].getRank();
  170.                         if(no==rank)
  171.                         {
  172.                                 arr[j]=obj[i];
  173.                                 j++;
  174.                         }
  175.                 }
  176.                 return arr;
  177.         }
  178.        
  179.        
  180.        
  181.        
  182.        
  183. }
  184.  
  185.  class Certificate1
  186. {
  187.         private int id,rank;
  188. private String title,date;
  189. public Certificate1(int id,String title,String date,int rank)
  190. {this.id=id;
  191. this.title=title;
  192. this.date=date;
  193. this.rank=rank;
  194.        
  195. }
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203. int getId()
  204. {
  205.         return id;
  206. }
  207. int getRank()
  208. {
  209.         return rank;
  210. }
  211. String getTitle()
  212. {
  213.         return title;
  214. }
  215. String getDate()
  216. {
  217.         return date;
  218. }
  219. void setId(int id)
  220. {
  221.         this.id=id;
  222. }
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  void setRank(int rank) {
  231.         this.rank = rank;
  232. }
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  void setTitle(String title) {
  241.         this.title = title;
  242. }
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  void setDate(String date) {
  250.         this.date = date;
  251. }
  252.  
  253.  
  254. }
  255.  
  256. .......................................................................................................................................................................
  257.  
  258.  
  259. public class MailBoxDemo {
  260.  
  261.         public static void main(String[] args) {
  262.                 // TODO Auto-generated method stub
  263.  
  264.                 MailBox mailbox1= new MailBox(22,"rsqhpiz","yjsympz");
  265.                 MailBox mailbox2= new MailBox(83,"xwjrqnu","ahrxtbb");
  266.                 MailBox mailbox3= new MailBox(47,"zgesjsr","cxnkctl");
  267.                 MailBox mailbox4= new MailBox(66,"xaosles","jvdrtxf");
  268.                 MailBox mailbox5= new MailBox(1,"yilxuua","ycnejof");
  269.                 MailBox[] objArray= {mailbox1,mailbox2,mailbox3,mailbox4,mailbox5};
  270.                 MailBox mailboxRes1= new MailBox(27,"ffatwgo","dkxgaid");
  271.  
  272.                 boolean result= replaceMailBoxById(objArray, mailboxRes1);
  273.                 System.out.println("Output for performing replace on mailboxRes1 is: "+ result  );          
  274.  
  275.                 System.out.println("Displaying contents of array: ");
  276.  
  277.                 for(MailBox mailbox:objArray){
  278.                 System.out.println(mailbox.getId()+" " + mailbox.getName()+" " + mailbox.getCreationDate()+" ");
  279.                 }
  280.                 System.out.println();
  281.  
  282.                 MailBox mailboxRes2= new MailBox(1,"hqzmrfz","fcbudyi");
  283.                 result= replaceMailBoxById(objArray, mailboxRes2);
  284.  
  285.                 System.out.println("Output for performing replace on mailboxRes2 is: "+ result  );          
  286.  
  287.                 System.out.println("Displaying contents of array: ");
  288.  
  289.                 for(MailBox mailbox11:objArray){
  290.                 System.out.println(mailbox11.getId()+" " + mailbox11.getName()+" " + mailbox11.getCreationDate()+" ");
  291.                
  292.                 }
  293.         }
  294.        
  295.         public static boolean replaceMailBoxById(MailBox[] objArry,MailBox objNew)
  296.         {
  297.                
  298.                 for(int i=0; i<objArry.length; i++)
  299.                 {
  300.                         if(objArry[i].getId()==objNew.getId())
  301.                         {
  302.                                 objArry[i]=objNew;
  303.                                 return true;
  304.                         }
  305.                 }
  306.                 return false;
  307.                
  308.         }
  309.  
  310. }
  311. class MailBox 
  312. {
  313.         private int id;
  314.         private String name,creationDate;
  315.         public MailBox(int id, String name, String creationDate) {
  316.                 super();
  317.                 this.id = id;
  318.                 this.name = name;
  319.                 this.creationDate = creationDate;
  320.         }
  321.         public int getId() {
  322.                 return id;
  323.         }
  324.         public void setId(int id) {
  325.                 this.id = id;
  326.         }
  327.         public String getName() {
  328.                 return name;
  329.         }
  330.         public void setName(String name) {
  331.                 this.name = name;
  332.         }
  333.         public String getCreationDate() {
  334.                 return creationDate;
  335.         }
  336.         public void setCreationDate(String creationDate) {
  337.                 this.creationDate = creationDate;
  338.         }
  339.        
  340.        
  341. }
  342. .......................................................................................................................................................................
  343.  
  344. public class MailBoxDemo {
  345.  
  346.         public static void main(String[] args) {
  347.                 // TODO Auto-generated method stub
  348.  
  349.                 MailBox mailbox1= new MailBox(22,"rsqhpiz","yjsympz");
  350.                 MailBox mailbox2= new MailBox(83,"xwjrqnu","ahrxtbb");
  351.                 MailBox mailbox3= new MailBox(47,"zgesjsr","cxnkctl");
  352.                 MailBox mailbox4= new MailBox(66,"xaosles","jvdrtxf");
  353.                 MailBox mailbox5= new MailBox(1,"yilxuua","ycnejof");
  354.                 MailBox[] objArray= {mailbox1,mailbox2,mailbox3,mailbox4,mailbox5};
  355.  sortMailBoxById(objArray);
  356.                
  357.                 System.out.println("Displaying contents of array: ");
  358.  
  359.                 for(MailBox mailbox:objArray){
  360.                 System.out.println(mailbox.getId()+" " + mailbox.getName()+" " + mailbox.getCreationDate()+" ");
  361.                 }
  362.                
  363.         }
  364.        
  365.         public static void sortMailBoxById(MailBox[] objArry)
  366.         {
  367.                
  368.                 for(int i=0; i<objArry.length; i++)
  369.                 {
  370.                         for(int j=i+1; j<objArry.length; j++)
  371.                         if(objArry[i].getId()>objArry[j].getId())
  372.                         {
  373.                                 MailBox temp=objArry[i];
  374.                                 objArry[i]=objArry[j];
  375.                                 objArry[j]=temp;
  376.                                
  377.                         }
  378.                 }
  379.                
  380.         }
  381.  
  382. }
  383. class MailBox 
  384. {
  385.         private int id;
  386.         private String name,creationDate;
  387.         public MailBox(int id, String name, String creationDate) {
  388.                 super();
  389.                 this.id = id;
  390.                 this.name = name;
  391.                 this.creationDate = creationDate;
  392.         }
  393.         public int getId() {
  394.                 return id;
  395.         }
  396.         public void setId(int id) {
  397.                 this.id = id;
  398.         }
  399.         public String getName() {
  400.                 return name;
  401.         }
  402.         public void setName(String name) {
  403.                 this.name = name;
  404.         }
  405.         public String getCreationDate() {
  406.                 return creationDate;
  407.         }
  408.         public void setCreationDate(String creationDate) {
  409.                 this.creationDate = creationDate;
  410.         }
  411.        
  412.        
  413. }
  414. .......................................................................................................................................................................
  415.  
  416. public class MailBoxDemo {
  417.  
  418.         public static void main(String[] args) {
  419.                 // TODO Auto-generated method stub
  420.  
  421.                 MailBox mailbox1= new MailBox(67,"isyvzun","egyyxwz");
  422.                 MailBox mailbox2= new MailBox(74,"xrxpxrr","bkmxnck");
  423.                 MailBox mailbox3= new MailBox(12,"xcromhc","sbndhax");
  424.                 MailBox mailbox4= new MailBox(22,"jlnyloj","ouyrjyo");
  425.                 MailBox mailbox5= new MailBox(9,"xyyhkuk","usqzuhu");
  426.                 MailBox[] objArray= {mailbox1,mailbox2,mailbox3,mailbox4,mailbox5};
  427.                 sortMailBoxByName(objArray);
  428.                
  429.                 System.out.println("Displaying contents of array: ");
  430.  
  431.                 for(MailBox mailbox:objArray){
  432.                 System.out.println(mailbox.getId()+" " + mailbox.getName()+" " + mailbox.getCreationDate()+" ");
  433.                 }
  434.                
  435.         }
  436.        
  437.         public static void sortMailBoxByName(MailBox[] objArry)
  438.         {
  439.                
  440.                 for(int i=0; i<objArry.length; i++)
  441.                 {
  442.                         for(int j=i+1; j<objArry.length; j++)
  443.                         if(objArry[i].getName().compareTo(objArry[j].getName())>0)
  444.                         {
  445.                                 MailBox temp=objArry[i];
  446.                                 objArry[i]=objArry[j];
  447.                                 objArry[j]=temp;
  448.                                
  449.                         }
  450.                 }
  451.                
  452.         }
  453.  
  454. }
  455. class MailBox 
  456. {
  457.         private int id;
  458.         private String name,creationDate;
  459.         public MailBox(int id, String name, String creationDate) {
  460.                 super();
  461.                 this.id = id;
  462.                 this.name = name;
  463.                 this.creationDate = creationDate;
  464.         }
  465.         public int getId() {
  466.                 return id;
  467.         }
  468.         public void setId(int id) {
  469.                 this.id = id;
  470.         }
  471.         public String getName() {
  472.                 return name;
  473.         }
  474.         public void setName(String name) {
  475.                 this.name = name;
  476.         }
  477.         public String getCreationDate() {
  478.                 return creationDate;
  479.         }
  480.         public void setCreationDate(String creationDate) {
  481.                 this.creationDate = creationDate;
  482.         }
  483.        
  484.        
  485. }
  486. .......................................................................................................................................................................
  487.  
  488. public class MailBoxDemo {
  489.  
  490.         public static void main(String[] args) {
  491.                 // TODO Auto-generated method stub
  492.  
  493.                 MailBox mailbox1= new MailBox(66,"xiibrnp","twqjgvl");
  494.                 MailBox mailbox2= new MailBox(94,"wdgxzwr","pvixict");
  495.                 MailBox mailbox3= new MailBox(40,"xhetnxe","wvtmcwk");
  496.                 MailBox mailbox4= new MailBox(69,"abeshrf","mfdjwqq");
  497.                 MailBox mailbox5= new MailBox(92,"bhdeebj","oymobpe");
  498.                 MailBox[] objArray= {mailbox1,mailbox2,mailbox3,mailbox4,mailbox5};
  499.                 sortMailBoxByCreationDate(objArray);
  500.                
  501.                 System.out.println("Displaying contents of array: ");
  502.  
  503.                 for(MailBox mailbox:objArray){
  504.                 System.out.println(mailbox.getId()+" " + mailbox.getName()+" " + mailbox.getCreationDate()+" ");
  505.                 }
  506.                
  507.         }
  508.        
  509.         public static void sortMailBoxByCreationDate(MailBox[] objArry)
  510.         {
  511.                
  512.                 for(int i=0; i<objArry.length; i++)
  513.                 {
  514.                         for(int j=i+1; j<objArry.length; j++)
  515.                         if(objArry[i].getCreationDate().compareTo(objArry[j].getCreationDate())>0)
  516.                         {
  517.                                 MailBox temp=objArry[i];
  518.                                 objArry[i]=objArry[j];
  519.                                 objArry[j]=temp;
  520.                                
  521.                         }
  522.                 }
  523.                
  524.         }
  525.  
  526. }
  527. class MailBox 
  528. {
  529.         private int id;
  530.         private String name,creationDate;
  531.         public MailBox(int id, String name, String creationDate) {
  532.                 super();
  533.                 this.id = id;
  534.                 this.name = name;
  535.                 this.creationDate = creationDate;
  536.         }
  537.         public int getId() {
  538.                 return id;
  539.         }
  540.         public void setId(int id) {
  541.                 this.id = id;
  542.         }
  543.         public String getName() {
  544.                 return name;
  545.         }
  546.         public void setName(String name) {
  547.                 this.name = name;
  548.         }
  549.         public String getCreationDate() {
  550.                 return creationDate;
  551.         }
  552.         public void setCreationDate(String creationDate) {
  553.                 this.creationDate = creationDate;
  554.         }
  555.        
  556.        
  557. }
  558. .......................................................................................................................................................................
  559.  
  560. public class MailBoxDemo {
  561.  
  562.         public static void main(String[] args) {
  563.                 // TODO Auto-generated method stub
  564.  
  565.                 MailBox mailbox1= new MailBox(30,"lsatkwk","ckbkape");
  566.                 MailBox mailbox2= new MailBox(38,"jbqeszs","tzxuuhz");
  567.                 MailBox mailbox3= new MailBox(22,"rpatwey","qkkjexb");
  568.                 MailBox mailbox4= new MailBox(80,"pfciraa","unafxwg");
  569.                 MailBox mailbox5= new MailBox(39,"ghohpje","fglxdpa");
  570.  
  571.  
  572.                 MailBox[] objArray= {mailbox1,mailbox2,mailbox3,mailbox4,mailbox5};
  573.  
  574.                 MailBox[] objResultArray1= searchMailBoxByName(objArray, "hxrkvyu");
  575.                 if(objResultArray1==null){
  576.                 System.out.println("Output after first search is null. ");
  577.                 }else{
  578.                 System.out.println("Displaying contents of result array: ");
  579.  
  580.                 for(MailBox mailbox:objResultArray1){
  581.                 System.out.println(mailbox.getId()+" " + mailbox.getName()+" " + mailbox.getCreationDate()+" ");
  582.                 }
  583.                 }
  584.  
  585.                 MailBox[] objResultArray2= searchMailBoxByName(objArray, "lsatkwk");
  586.                 if(objResultArray2==null){
  587.                 System.out.println("Output after first search is null. ");
  588.                 }else{
  589.                 System.out.println("Displaying contents of result array: ");
  590.  
  591.                 for(MailBox mailbox:objResultArray2){
  592.                 System.out.println(mailbox.getId()+" " + mailbox.getName()+" " + mailbox.getCreationDate()+" ");
  593.                 }
  594.                 }
  595.                 }
  596.                
  597.  
  598.        
  599.         public static MailBox[] searchMailBoxByName(MailBox[] objArry,String name)
  600.         {
  601.                 int c=0;
  602.                 for(int i=0; i<objArry.length; i++)
  603.                 {
  604.                  String nam=objArry[i].getName();
  605.                 if(nam.equals(name))
  606.                  {c++;
  607.                                
  608.                         }
  609.                 }
  610.                 int j=0;
  611.                 MailBox[] arr= new MailBox[c];
  612.                 for(int i=0; i<objArry.length; i++)
  613.                 {
  614.                  String nam=objArry[i].getName();
  615.                 if(nam.equals(name))
  616.                  {
  617.                                 arr[j]=objArry[i];
  618.                                 j++;
  619.                         }
  620.                 }
  621.                
  622.                
  623.                 return arr;
  624.         }
  625.  
  626. }
  627. class MailBox 
  628. {
  629.         private int id;
  630.         private String name,creationDate;
  631.         public MailBox(int id, String name, String creationDate) {
  632.                 super();
  633.                 this.id = id;
  634.                 this.name = name;
  635.                 this.creationDate = creationDate;
  636.         }
  637.         public int getId() {
  638.                 return id;
  639.         }
  640.         public void setId(int id) {
  641.                 this.id = id;
  642.         }
  643.         public String getName() {
  644.                 return name;
  645.         }
  646.         public void setName(String name) {
  647.                 this.name = name;
  648.         }
  649.         public String getCreationDate() {
  650.                 return creationDate;
  651.         }
  652.         public void setCreationDate(String creationDate) {
  653.                 this.creationDate = creationDate;
  654.         }
  655.        
  656.        
  657. }
  658. .......................................................................................................................................................................
  659.  
  660. public class MailBoxDemo {
  661.  
  662.         public static void main(String[] args) {
  663.                 // TODO Auto-generated method stub
  664.                 MailBox mailbox1= new MailBox(93,"hfyquem","xclzutr");
  665.                 MailBox mailbox2= new MailBox(25,"ajdlukm","hzeustv");
  666.                 MailBox mailbox3= new MailBox(26,"rsusdgf","upxpgwq");
  667.                 MailBox mailbox4= new MailBox(37,"kasysrr","rahcqck");
  668.                 MailBox mailbox5= new MailBox(39,"fvhepzs","djkljsd");
  669.  
  670.  
  671.                 MailBox[] objArray= {mailbox1,mailbox2,mailbox3,mailbox4,mailbox5};
  672.  
  673.                 MailBox[] objResultArray1= searchMailBoxByCreationDate(objArray, "jvxfaua");
  674.                 if(objResultArray1==null){
  675.                 System.out.println("Output after first search is null. ");
  676.                 }else{
  677.                 System.out.println("Displaying contents of result array: ");
  678.  
  679.                 for(MailBox mailbox:objResultArray1){
  680.                 System.out.println(mailbox.getId()+" " + mailbox.getName()+" " + mailbox.getCreationDate()+" ");
  681.                 }
  682.                 }
  683.  
  684.                 MailBox[] objResultArray2= searchMailBoxByCreationDate(objArray, "rahcqck");
  685.                 if(objResultArray2==null){
  686.                 System.out.println("Output after first search is null. ");
  687.                 }else{
  688.                 System.out.println("Displaying contents of result array: ");
  689.  
  690.                 for(MailBox mailbox:objResultArray2){
  691.                 System.out.println(mailbox.getId()+" " + mailbox.getName()+" " + mailbox.getCreationDate()+" ");
  692.                 }
  693.                 }
  694.                
  695.                 }
  696.                
  697.  
  698.        
  699.         public static MailBox[] searchMailBoxByCreationDate(MailBox[] objArry,String name)
  700.         {
  701.                 int c=0;
  702.                 for(int i=0; i<objArry.length; i++)
  703.                 {
  704.                  String nam=objArry[i].getCreationDate();
  705.                 if(nam.equals(name))
  706.                  {c++;
  707.                                
  708.                         }
  709.                 }
  710.                 int j=0;
  711.                 MailBox[] arr= new MailBox[c];
  712.                 for(int i=0; i<objArry.length; i++)
  713.                 {
  714.                  String nam=objArry[i].getCreationDate();
  715.                 if(nam.equals(name))
  716.                  {
  717.                                 arr[j]=objArry[i];
  718.                                 j++;
  719.                         }
  720.                 }
  721.                
  722.                
  723.                 return arr;
  724.         }
  725.  
  726. }
  727. class MailBox 
  728. {
  729.         private int id;
  730.         private String name,creationDate;
  731.         public MailBox(int id, String name, String creationDate) {
  732.                 super();
  733.                 this.id = id;
  734.                 this.name = name;
  735.                 this.creationDate = creationDate;
  736.         }
  737.         public int getId() {
  738.                 return id;
  739.         }
  740.         public void setId(int id) {
  741.                 this.id = id;
  742.         }
  743.         public String getName() {
  744.                 return name;
  745.         }
  746.         public void setName(String name) {
  747.                 this.name = name;
  748.         }
  749.         public String getCreationDate() {
  750.                 return creationDate;
  751.         }
  752.         public void setCreationDate(String creationDate) {
  753.                 this.creationDate = creationDate;
  754.         }
  755.        
  756.        
  757. }
  758. .......................................................................................................................................................................
  759.  
  760. public class MailBoxDemo {
  761.  
  762.         public static void main(String[] args) {
  763.                 // TODO Auto-generated method stub
  764.                 MailBox mailbox1= new MailBox(18,"scfkfwm","vjlhejv");
  765.                 MailBox mailbox2= new MailBox(44,"vykwuqm","hxbgccj");
  766.                 MailBox mailbox3= new MailBox(77,"ddwhwhg","eiqshsv");
  767.                 MailBox mailbox4= new MailBox(79,"ctppqch","quyvfim");
  768.                 MailBox mailbox5= new MailBox(9,"fdoyxqc","vikysdr");
  769.  
  770.  
  771.                 MailBox[] objArray= {mailbox1,mailbox2,mailbox3,mailbox4,mailbox5};
  772.  
  773.                 MailBox[] objResultArray1= getOddPositionMailBox(objArray);
  774.                 if(objResultArray1==null){
  775.                 System.out.println("Output after first operation is null. ");
  776.                 }else{
  777.                 System.out.println("Displaying contents of result array: ");
  778.  
  779.                 for(MailBox mailbox:objResultArray1){
  780.                 System.out.println(mailbox.getId()+" " + mailbox.getName()+" " + mailbox.getCreationDate()+" ");
  781.                 }
  782.                 }
  783.        
  784.                
  785.                 }
  786.                
  787.  
  788.        
  789.         public static MailBox[] getOddPositionMailBox(MailBox[] objArry)
  790.         {
  791.                 int j=0;
  792.                 int c=(objArry.length/2);
  793.                 MailBox[] arr= new MailBox[c];
  794.                 for(int i=0; i<objArry.length; i++)
  795.                 {
  796.                
  797.                 if(i%2!=0)
  798.                  {
  799.                                 arr[j]=objArry[i];
  800.                                 j++;
  801.                         }
  802.                 }
  803.                
  804.                
  805.                 return arr;
  806.         }
  807.  
  808. }
  809. class MailBox 
  810. {
  811.         private int id;
  812.         private String name,creationDate;
  813.         public MailBox(int id, String name, String creationDate) {
  814.                 super();
  815.                 this.id = id;
  816.                 this.name = name;
  817.                 this.creationDate = creationDate;
  818.         }
  819.         public int getId() {
  820.                 return id;
  821.         }
  822.         public void setId(int id) {
  823.                 this.id = id;
  824.         }
  825.         public String getName() {
  826.                 return name;
  827.         }
  828.         public void setName(String name) {
  829.                 this.name = name;
  830.         }
  831.         public String getCreationDate() {
  832.                 return creationDate;
  833.         }
  834.         public void setCreationDate(String creationDate) {
  835.                 this.creationDate = creationDate;
  836.         }
  837.        
  838.        
  839. }
  840. .......................................................................................................................................................................
  841.  
  842. public class MailBoxDemo {
  843.  
  844.         public static void main(String[] args) {
  845.                 // TODO Auto-generated method stub
  846.                 MailBox mailbox1= new MailBox(7,"vjcmlwe","szfolwb");
  847.                 MailBox mailbox2= new MailBox(67,"imcftaw","jlnzywo");
  848.                 MailBox mailbox3= new MailBox(26,"lsckexs","lyqonys");
  849.                 MailBox mailbox4= new MailBox(5,"cbajxhj","rgwyxze");
  850.                 MailBox mailbox5= new MailBox(4,"bxifplc","wevsaco");
  851.  
  852.  
  853.                 MailBox[] objArray= {mailbox1,mailbox2,mailbox3,mailbox4,mailbox5};
  854.  
  855.                 MailBox[] objResultArray1= getEvenPositionMailBox(objArray);
  856.                 if(objResultArray1==null){
  857.                 System.out.println("Output after first operation is null. ");
  858.                 }else{
  859.                 System.out.println("Displaying contents of result array: ");
  860.  
  861.                 for(MailBox mailbox:objResultArray1){
  862.                 System.out.println(mailbox.getId()+" " + mailbox.getName()+" " + mailbox.getCreationDate()+" ");
  863.                 }
  864.                 }
  865.                 }
  866.  
  867.        
  868.         public static MailBox[] getEvenPositionMailBox(MailBox[] objArry)
  869.         {
  870.                 int j=0;
  871.                 int c=(objArry.length/2)+1;
  872.                 MailBox[] arr= new MailBox[c];
  873.                 for(int i=0; i<objArry.length; i++)
  874.                 {
  875.                
  876.                 if(i%2==0)
  877.                  {
  878.                                 arr[j]=objArry[i];
  879.                                 j++;
  880.                         }
  881.                 }
  882.                
  883.                
  884.                 return arr;
  885.         }
  886.  
  887. }
  888. class MailBox 
  889. {
  890.         private int id;
  891.         private String name,creationDate;
  892.         public MailBox(int id, String name, String creationDate) {
  893.                 super();
  894.                 this.id = id;
  895.                 this.name = name;
  896.                 this.creationDate = creationDate;
  897.         }
  898.         public int getId() {
  899.                 return id;
  900.         }
  901.         public void setId(int id) {
  902.                 this.id = id;
  903.         }
  904.         public String getName() {
  905.                 return name;
  906.         }
  907.         public void setName(String name) {
  908.                 this.name = name;
  909.         }
  910.         public String getCreationDate() {
  911.                 return creationDate;
  912.         }
  913.         public void setCreationDate(String creationDate) {
  914.                 this.creationDate = creationDate;
  915.         }
  916.        
  917.        
  918. }
  919. .......................................................................................................................................................................

Editor

You can edit this paste and save as new:


File Description
  • eee
  • Paste Code
  • 16 Sep-2019
  • 20.74 Kb
You can Share it: