Skip to main content

20 March,2022 CPA java Solution.

 

Create the class Flowers with below attribute:

flowerId-int;

flowerName-String;

price-int;

rating-int;

type-String;


The above attributes must be private,write getters and setters and 

parametrized constructor as well.


Create class MyClass with main method.


Implement one static method:findMinPriceByType in MyClass class.


findMinPriceByType Method:

    This method will take two input parameters:Array of Flower objects and

String parameter.

    This method will return the minimum priced flower object from  array 

of Flower objects for the given type(String parameter),only if the rating 

is greater than 3.If no Flowers with the above conditions are present in 

the array of the flower objects,then the method will return null.


for this method-The main method  should print the flowerId from the returned

object if the returned value is not null.else it should print "There is no

flower with given type".



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

input1:

123

Yellow trout lilly

3000

5

ephemerals

345

snowdrop

2500

4

ephemerals

321

Yarrow

1000

4

perennials

213

red trillium

2250

4

ephemerals

ephemerals


output:

213



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

input2:

123

Yellow trout lilly

3000

5

ephemerals

345

snowdrop

2500

4

ephemerals

321

Yarrow

1000

4

perennials

213

red trillium

2250

4

ephemerals

Biennial


output2:

There is no flower with given type.


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



code is given below:



import java.util.Scanner;


public class MyClass {

    public static void main(String[] args) {

            Scanner sc=new Scanner(System.in);

            Flowers[] flowers=new Flowers[4];


        for (int i = 0; i <4 ; i++) {

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

          String b=sc.nextLine();

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

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

          String e=sc.nextLine();

           flowers[i]  = new Flowers(a,b,c,d,e);

        }


        String input=sc.nextLine();

       int ans= findMinPriceByType(flowers,input);

       if(ans==0)

       {

           System.out.println("There is no flower with given type");

       }

       else

       {

           System.out.println(ans);

       }

    }


   public static int findMinPriceByType(Flowers[] flowers,String input)

    {

         int idd=Integer.MAX_VALUE;

         int min=Integer.MAX_VALUE;


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

            if(flowers[i].getType().equalsIgnoreCase(input) && flowers[i].getRating()>3 && flowers[i].getPrice()<min)

            {

                min=flowers[i].getPrice();

                idd=flowers[i].getFlowerId();

            }


        }



         if(min!=Integer.MAX_VALUE)

         {

             return idd;

         }

         return 0;


    }


}



class Flowers

{

   private int flowerId;

  private  String flowerName;

   private int price;

   private int rating;

   private String type;


   //parametrized constructor



    public Flowers(int flowerId, String flowerName, int price, int rating, String type) {

        this.flowerId = flowerId;

        this.flowerName = flowerName;

        this.price = price;

        this.rating = rating;

        this.type = type;

    }


//getter and Setters



    public int getFlowerId() {

        return flowerId;

    }


    public void setFlowerId(int flowerId) {

        this.flowerId = flowerId;

    }


    public String getFlowerName() {

        return flowerName;

    }


    public void setFlowerName(String flowerName) {

        this.flowerName = flowerName;

    }


    public int getPrice() {

        return price;

    }


    public void setPrice(int price) {

        this.price = price;

    }


    public int getRating() {

        return rating;

    }


    public void setRating(int rating) {

        this.rating = rating;

    }


    public String getType() {

        return type;

    }


    public void setType(String type) {

        this.type = type;

    }

}

Comments

  1. Hi
    I want to talk to you. Please contact me rpoins9889@gmail.com

    ReplyDelete

Post a Comment

Popular posts from this blog

How to Introduce Yourself to project team and client when you join a new project as fresher in service based company ?

Question:     How to Introduce Yourself to project team /client  when you join a new project as fresher ? Answer:  Hii Everyone,    Today I will be talking about how we can introduce ourselves to a team  when we join a new project in any servicebased company as a fresher.     After I completed my Engineering ,I got placed into TCS.I got allocated  into a project.I introduced myself to a team.So I will be telling about how   exactly I introduced myself to the team.The impressive introduction is  necessary if you want team members to treat you better in this work from  home period.If you fail to impress team members ,If your introduction is not  impressive ,then probably your team members will ignore you.    Before I tell you about how exactly I introduced myself,I would like  to talk about the points that you should remember before giving your  introduction. .start your introduction with Hii Ev...

Automating Infrastructure on Google Cloud with Terraform: Challenge Lab

As more and more organizations move to the cloud, the need for powerful infrastructure automation tools has never been greater. That's where Terraform comes in, a cutting-edge tool that allows you to automate the deployment, management, and scaling of your infrastructure with ease. With Terraform, you can define your entire infrastructure as code, making it easy to maintain, version, and reproduce. Whether you're deploying infrastructure to AWS, Google Cloud, or another cloud provider, Terraform provides a powerful and flexible platform for automating your workflows. In this blog post, we'll take a look at how to automate infrastructure on google cloud with terraform. Task A. Create the configuration files  Task B. Import infrastructure  Task C.Configure a remote backend  Task D. Modify and update infrastructure  Task E.Destroy resources  Task F. Use a module from the Registry  Task G. Configure a firewall ......................................................

TCS IRA 13 DECEMBER JAVA CODING QUESTION SOLUTION.

Create a class newspaper with below attributes. regNo-int name-String publicationYear-int price-int Write parametrised constructor as required. Create class Solution with main method. Implement 2 static methods findTotalPriceByPublicationYear and  searchNewspaperByName in solution class. findTotalPriceByPublicationYear method:    This method will take array of the Newspaper objects and int parameter type.This method will return the total price of newspapers from array of  Newspaper objects,If the publication year attribute matches with the int  parameter passed .If no Newspaper with the given publication year is present  in the array ,then the method should return 0. The main method should print total price if the returned value is greater  than 0.Else it should print "No Newspaper found with the mentioned attribute". searchNewspaperByName method :    This method will take the array of the Newspaper objects and the String  parameter type...