Skip to main content

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 from the array of the Footwear objects
whose brand name matches with the input string parameter.
if no footwear with the given brand is present in the array of the footwear objects,the the method
should return null.

NOTE: no two footwear objects would have the same footwearId.All the searches should be case insensitive.
the above mentioned static methods should be called from the main method.

for getCountByType method- the main method should print the count of the footwears ,if the returned value
is greater than zero. or it should print "Footwear not available";

for getSecondHighestPriceByBrand method-The main method should print price from the returned footwear objects
if the returned footwear object is not null.else it should print "Brand not available".
for example.
112
ABC
25555
  where 112 is the footwear id,ABC is brand name,25555 is price.

consider the sample input and output.
100
Sketchers
sneekers
12345
103
Puma
running shoes
10099
102
reebok
Running shoes
5667
101
Reebok
running shoes
5656
99
reebok
floaters
5666
Running shoes
reebok

Sample output:
3
99
reebok
5666

Sample input2:

100
Puma
sneekers
12345
101
Puma
sneekers
10099
102
Puma
sneekers
5000
102
Reebok
sneekers
8000
104
Puma
floaters
2000
running shoes
bata

Sample output:
Footwear not available
Brand not available





SOLUTION:


import java.util.Scanner;
import java.util.Arrays;



public class footwearProgram {


    public static void main(String[] args) {
        Footwear[] footwears=new Footwear[5];
        Scanner sc=new Scanner(System.in);
        for (int i = 0; i < 5; i++) {


        int a=sc.nextInt();sc.nextLine();
        String b=sc.nextLine();
        String c=sc.nextLine();
        int d=sc.nextInt();
        sc.nextLine();

        footwears[i]=new Footwear(a,b,c,d);
        }
      String inputFootwearType=sc.nextLine();
        String inputFootwearBrand=sc.nextLine();
     int count   =getCountByType(footwears,inputFootwearType);
         if(count==0)
         {
             System.out.println("Footwear not available");
         }
         else
         {
             System.out.println(count);
         }

        Footwear obj=getSecondHighestPriceByBrand(footwears,inputFootwearBrand);
          if(obj==null)
          {
              System.out.println("Brand not available");
          }
          else
          {
              System.out.println(obj.footwearId);
              System.out.println(obj.footwearName);
              System.out.println(obj.price);
          }


    }





    private static Footwear getSecondHighestPriceByBrand(Footwear[] footwears, String inputFootwearBrand) {

        int arrofprice[]=new int[0];
        for (int i = 0; i <5 ; i++) {
            if(footwears[i].footwearName.equalsIgnoreCase(inputFootwearBrand))
            {
                arrofprice=Arrays.copyOf(arrofprice,arrofprice.length+1);
                arrofprice[arrofprice.length-1]=footwears[i].price;
            }
        }
        Arrays.sort(arrofprice);
            if(arrofprice.length>0)
            {
                int x = arrofprice[arrofprice.length - 2];
                for (int i = 0; i < footwears.length; i++) {
                    if (footwears[i].price == x) {
                        return footwears[i];
                    }
                }
            }

        return null;
    }







    public static int  getCountByType(Footwear[] footwears,String type)
   {
       int count=0;
       for (int i = 0; i < 5; i++) {
           if(footwears[i].footwearType.equalsIgnoreCase(type))
           {
               count+=1;
           }
       }
       if(count>0)
       {
           return count;
       }


       return 0;
   }






}
class Footwear{
    int footwearId;
    String footwearName;
    String footwearType;
    int price;

    //constructor


    public Footwear(int footwearId, String footwearName, String footwearType, int price) {
        this.footwearId = footwearId;
        this.footwearName = footwearName;
        this.footwearType = footwearType;
        this.price = price;
    }

    //getter and setter


    public int getFootwearId() {
        return footwearId;
    }

    public void setFootwearId(int footwearId) {
        this.footwearId = footwearId;
    }

    public String getFootwearName() {
        return footwearName;
    }

    public void setFootwearName(String footwearName) {
        this.footwearName = footwearName;
    }

    public String getFootwearType() {
        return footwearType;
    }

    public void setFootwearType(String footwearType) {
        this.footwearType = footwearType;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }
}





















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