Skip to main content

28 february IRA JAVA solution.

Question: 


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.




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


code:






import java.util.Arrays;

import java.util.Scanner;



public class Solution {

    public static void main(String[] args) {

     Scanner sc=new Scanner(System.in);

     Music[] musics=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();

           musics[i] =new Music(a,b,c,d);

        }


       int  input1=sc.nextInt();sc.nextLine();

          int  input2=sc.nextInt();sc.nextLine();


       int ans1 =findAvgOfCount(musics,input1);

       if(ans1==0)

       {

           System.out.println("No playlist found");

       }

       else

       {

           System.out.println(ans1);

       }


       Music[] ans2= sortTypeByDuration(musics,input2);

       if(ans2==null)

       {

           System.out.println("No playlist found with mentioned attribute");

       }

       else

       {

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

               System.out.println(ans2[i].getType());

           }

       }


    }


   public static int  findAvgOfCount(Music[] musics,int input1)

    {

        int count=0;

        int sum=0;

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

            if(musics[i].getCount()>input1)

            {

                count+=1;

              sum+=musics[i].getCount();

            }

        }



        if(count>0)

        {

            return sum/count;

        }


        return 0;

    }


   public static Music[] sortTypeByDuration(Music[] musics,int input2)

    {



      Music[]  help=new Music[0];

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

            if(musics[i].getDuration()>input2)

            {

                help=Arrays.copyOf(help,help.length+1);

                help[help.length-1]=musics[i];

            }

        }


        //bubble sort


        for (int i = 0; i < help.length-1; i++) {

            for (int j = 0; j <help.length-i-1 ; j++) {

                if(help[j].getDuration()>help[j+1].getDuration())

                {

                    Music temp=help[j+1];

                    help[j+1]=help[j];

                    help[j]=temp;

                }

            }

        }


        if(help.length>0)

        {

            return help;

        }


        return null;

    }




}



class Music

{

 private int playlistNo;

private String type;

private int count;

private double duration;


//parametrized constructor



    public Music(int playlistNo, String type, int count, double duration) {

        this.playlistNo = playlistNo;

        this.type = type;

        this.count = count;

        this.duration = duration;

    }


    //getter and setter



    public int getPlaylistNo() {

        return playlistNo;

    }


    public void setPlaylistNo(int playlistNo) {

        this.playlistNo = playlistNo;

    }


    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;

    }

}


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

Comments

Popular posts from this blog

Travel_Agencies

  Problem Statement Create a class TravelAgencies with below attributes: regNo – int agencyName – String pakageType – String price – int flightFacility – boolean Write getters, setters for the above attributes . Create constructor which takes parameter in the above sequence. Create class Solution with main method. Implement two static methods – findAgencyWithHighestPackagePrice and agencyDetailsforGivenIdAndType in Solution class. findAgencyWithHighestPackagePrice method: This method will take array of TravelAgencies objects as an input parameter and return the highest package price from the given array of objects. agencyDetailsForGivenldAndType method: This method will take three input parameters -array of TravelAgencies objects, int parameter regNo and String parameter packageType. The method will return the TravelAgencies object based on below conditions. FlightFacility should be available. The input parameters(regNo and packageType) should matched with the regNo

December 23 java coding question PRA solution

23 dec pra java coding question solution. Question: Create the class Student with below attributes. id-int name-String marks-int age-int write getters and setters and parametrized constructor in Student class. Create class Solution with main method. implement 2 static methods-findStudentWithMaximumAge and searchStudentById in Solution class. findStudentWithMaximumAge method:     This method will take the Array of the Students objects as input and  returns the Student object having maximum Age.   For this method,the main method should print the student object details with maximum age as it is.    searchStudentById method:     This method will take 2 input parameters.Array of the Students objects and an int value  id.and returns the Student object having the mentioned id  if found, else return null if not found.   For this method ,main method should print the details of Student objects  as it is,if the returned value is not null. or it should print  "No Student found with mentioned

TCS XPLORE CAMERA PROCTORED ASSESSMENT EXAM JAVA CODING SOLUTION 10 MAY,2021. FOOTWEAR PROBLEM.

 create a class Footwear which consists of the below attributes.   footwearId=int   footwearName=String   footwearType=String   price =int the above attributes should be private. write getter and setter and parametrised constructor as required. create the class footwearProgrammm with the main method. implement the 2 static methods.getCountByType and getSecondHighestPriceByBrand in the Solution class. getCountByType method:    this method will take two input parameters. array of the Footwear objects and string parameter footwear type. this method will return the count of the footwears from array of the footwear objects for the given type of footwear. if no footwear with the given footwear type is found in the array of footwear abjects,then the method should return 0. getSecondHighestPriceByBrand method:   this method will take 2 input parameters-array of footwear objects and string parameter inputFootwearName.the method will return the second highest footwear objects based on the price