findSongBasedOnArtists
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class main
  9. {
  10.         public static void main (string[] args)
  11.         {
  12.  int i,dur;
  13.  string name,artists,lang;
  14.  double rating;
  15.  Scanner sc=new Scanner(system.in);
  16.  Songs[] arr=new Songs[5];
  17.  for(i=0;i<5;i++)
  18.  {
  19.   name=sc.nextLine();
  20.   dur=sc.nextInt();sc.nextLine();
  21.   artists=sc.nextLine();
  22.   lang=sc.nextLine();
  23.   rating=sc.nextDouble();sc.nextLine();
  24.   arr[i]=new Songs(name,dur,artists,lang,rating);
  25.  }
  26.  string lang2=sc.nextLine();
  27.  string art=sc.nextLine();
  28.  
  29.  
  30.  string[] res1=findSongBasedOnLanguage(arr,lang2);
  31.  if(res1==null)
  32.   system.out.println("There are no songs with the given language");
  33.  else
  34.  {
  35.   for(i=0;i<res1.length;i++)
  36.    system.out.println(res1[i] + "nfdfd");
  37.  }
  38.  
  39.  Songs[] res2=findSongBasedOnArtists(arr,art);
  40.  
  41.  if(res2==null)
  42.   system.out.println("There are no Songs with the given artists");
  43.  else
  44.  {
  45.   for(i=0;i<res2.length;i++)
  46.   {
  47.   system.out.println(res2[i].getSongName());
  48.   system.out.println(res2[i].getRating() +" Noor ");
  49.   }
  50.  }
  51.  
  52. }
  53.  
  54.  
  55. public static string[] findSongBasedOnLanguage(Songs[] arr,string lang2)
  56. {
  57.  int i,j=0;
  58.  string[] temp;
  59.  for(i=0;i<arr.length;i++)
  60.  {
  61.   if(arr[i].getLanguage().equalsIgnoreCase(lang2))
  62.    j++;
  63.  }
  64.  if(j==0)
  65.   return null;
  66.  else
  67.  {
  68.   temp=new string[j];
  69.   j=0;
  70.   for(i=0;i<arr.length;i++)
  71.  {
  72.   if(arr[i].getLanguage().equalsIgnoreCase(lang2))
  73.    temp[j++]=arr[i].getSongName();
  74.  }
  75.  return temp;
  76.  }
  77. }
  78.  
  79.  
  80. public static Songs[] findSongBasedOnArtists(Songs[] arr,string art)
  81. {
  82.  int i,j=0,k;
  83.  Songs[] temp;
  84.  for(i=0;i<arr.length;i++)
  85.  {
  86.   if((arr[i].getArtists()).equalsIgnoreCase(art))
  87.    {
  88.         j++;
  89.    }
  90.  }
  91.  system.out.println("J is: "+j);
  92.  if(j==0)
  93.   return null;
  94.  else
  95.  {
  96.   temp=new Songs[j];
  97.   j=0;
  98.   for(i=0;i<arr.length;i++)
  99.  {
  100.   if(arr[i].getArtists().equalsIgnoreCase(art))
  101.    temp[j++]=arr[i];
  102.  }
  103.  
  104.  for(i=0;i<j-1;i++)
  105.  {
  106.   for(k=0;k<j-1;k++)
  107.   {
  108.    if(temp[k].getRating()>temp[k+1].getRating())
  109.    {
  110.     Songs t=temp[k];
  111.     temp[k]=temp[k+1];
  112.     temp[k+1]=t;
  113.    }
  114.   }
  115.  }
  116.  return temp;
  117.  }
  118. }
  119.  
  120. }
  121.  
  122.  
  123. class Songs
  124. {
  125.  private string songName;
  126.  private int duration;
  127.  private string artists;
  128.  private string language;
  129.  private double rating;
  130.  
  131.  public Songs(string songName,int duartion,string artists,string language,double rating)
  132.  {
  133.   this.songName=songName;
  134.   this.duration=duration;
  135.   this.artists=artists;
  136.   this.language=language;
  137.   this.rating=rating;
  138.  }
  139.  public string getSongName()
  140.  {
  141.   return songName;
  142.  }
  143.  public int getDuration()
  144.  {
  145.   return duration;
  146.  }
  147.  public string getArtists()
  148.  {
  149.   return artists;
  150.  }
  151.  public string getLanguage()
  152.  {
  153.   return language;
  154.  }
  155.  public double getRating()
  156.  {
  157.   return rating;
  158.  }
  159. }
Parsed in 0.060 seconds