Skip to content

Commit

Permalink
Music (IPA-35)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arijit-SE committed Feb 26, 2023
1 parent c856d09 commit 501f0d1
Show file tree
Hide file tree
Showing 2 changed files with 243 additions and 0 deletions.
141 changes: 141 additions & 0 deletions IPA31/Music_IPA.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package IPA31;
import java.util.*;
public class Music_IPA{

public static void main(String []args){
Scanner sc = new Scanner(System.in);
Music[] m = new Music[4];
for(int i=0; i<4; i++)
{
int a = sc.nextInt();sc.nextLine();
String b = sc.nextLine();
int c = sc.nextInt();sc.nextLine();
double d = sc.nextDouble();sc.nextLine();
m[i] = new Music(a,b,c,d);
}
int num = sc.nextInt();sc.nextLine();
double dur = sc.nextDouble(); sc.nextLine();
int ans1 = findAvg(m,num);
if(ans1!=0)
{
System.out.println(ans1);
}
else
{
System.out.println("No playlist found");
}
String[] ans2 = SortDur(m, dur);
if(ans2!=null)
{
for(int i=0; i<ans2.length; i++)
{
System.out.println(ans2[i]);
}
}
else
{
System.out.println("No playlist found with mentioned attribute");
}
}
public static int findAvg(Music[] m, int num)
{
int k =0, sum=0;
for(int i=0; i<m.length; i++)
{
if(m[i].getCount()>num)
{
sum = sum+m[i].getCount();
k++;
}
}
if(k>0)
{
int avg = sum/k;
return avg;
}
else
{
return 0;
}
}
public static String[] SortDur(Music[] m, double d)
{
String[] t = new String[0];
double[] du = new double[0];
for(int i=0; i<m.length; i++)
{
if(m[i].getDuration()>d)
{
du = Arrays.copyOf(du, du.length+1);
du[du.length-1] = m[i].getDuration();
Arrays.sort(du);
}
}
for(int i=0; i<du.length; i++)
{
for (int j = 0; j < m.length; j++)
{
if(m[j].getDuration()==du[i])
{
t = Arrays.copyOf(t, t.length+1);
t[t.length-1]=m[j].getType();
}
}
}
if(t.length>0)
{
return t;
}
else
{
return null;
}
}
}
class Music
{
int pNo, count;
String type;
double duration;

public Music(int pNo, String type, int count, double duration)
{
this.pNo = pNo;
this.type = type;
this.count = count;
this.duration = duration;
}

public int getPNo()
{
return pNo;
}
public void setPNo(int pNo)
{
this.pNo = pNo;
}
public String getType()
{
return type;
}
public void setType(String type)
{
this.type = type;
}
public int getCount()
{
return count;
}
public void setCount(int count)
{
this.count = count;
}
public double getDuration()
{
return duration;
}
public void setDuration(double duration)
{
this.duration = duration;
}
}
102 changes: 102 additions & 0 deletions IPA31/Music_IPA.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
Create a class Music with below attributes:

playListNo - int

type -String

count - int

duration(minutes) -double.



The above attributes should be private.Write Getter and Setter and parametrized constructor as required.

Create class Solution with main method.

****************************************************************************

Implement two static methods: findAvgOfCount and sortTypeByDuration in Solution Class.



findAvgOfCount Method:
----------------------------------------
This method will take an array of Music objects and an int value as input parameters.The method will find out Average
(as int) of count for those objects whose count is more than the given Count(int parameter passed).This method will return
average if found.If there is no Type that matches then the method should return 0.

for this method- main method should print average ,if the returned value is not 0.If the returned value is 0 then main method
should print "No playlist found".

sortTypeByDuration method:
-----------------------------------------
This method will take an array of Music objects and an int value as input parameters.This method should return an array of
Music objects in an ascending order of their duration which are more than the given duration (int parameter passed) value.
If there are no such objects ,then the method should return null.

for this method-The main method should print the type from the returned Music object array if the returned value is not null.
If the returned value is null then the main method should print "No playlist found with mentioned attribute".

****************************************************************************

Consider the below input and output:

input1:
------------
111
WorkOut
10
15.2
321
Dance Party
20
55.500
721
Childhood Jams
6
50.60
521
Chill
30
78.89
15
20


output1:
--------------------
25
Childhood Jams
Dance Party
Chill



input2:
-----------------------
111
Oldies but Goodies
17
55
321
Guilty Pleasures
27
27
721
night drive
21
345
521
Rainy day
34
21
50
5000


output 2:
-----------------------
No playlist found.
No playlist found with mentioned attribute.

0 comments on commit 501f0d1

Please sign in to comment.