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;
}
}
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...
Comments
Post a Comment