Skip to content

Commit c0c3d6f

Browse files
committed
Footwear (IPA-35)
1 parent 58696d7 commit c0c3d6f

2 files changed

Lines changed: 234 additions & 0 deletions

File tree

IPA2/Footwear.txt

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
create a class Footwear which consists of the below attributes.
2+
footwearId=int
3+
footwearName=String
4+
footwearType=String
5+
price =int
6+
7+
the above attributes should be private.
8+
write getter and setter and parametrised constructor as required.
9+
10+
create the class footwearProgrammm with the main method.
11+
implement the 2 static methods.getCountByType and
12+
getSecondHighestPriceByBrand in the Solution class.
13+
14+
15+
getCountByType method:
16+
this method will take two input parameters.
17+
array of the Footwear objects and string parameter footwear type.
18+
this method will return the count of the footwears from array of the
19+
footwear objects for the given type of footwear.
20+
if no footwear with the given footwear type is found in the
21+
array of footwear abjects,then the method should return 0.
22+
23+
24+
25+
getSecondHighestPriceByBrand method:
26+
this method will take 2 input parameters-array of footwear objects and string parameter inputFootwearName.the method
27+
will return the second highest footwear objects based on the price from the array of the Footwear objects
28+
29+
30+
whose brand name matches with the input string parameter.
31+
32+
33+
if no footwear with the given brand is present in the array of the footwear objects,the the method
34+
should return null.
35+
36+
NOTE: no two footwear objects would have the same footwearId.All the searches should be case insensitive.
37+
the above mentioned static methods should be called from the main method.
38+
39+
for getCountByType method- the main method should print the count of the footwears ,if the returned value
40+
is greater than zero. or it should print "Footwear not available";
41+
42+
for getSecondHighestPriceByBrand method-The main method should print price from the returned footwear objects
43+
44+
45+
if the returned footwear object is not null.else it should print "Brand not available".
46+
for example.
47+
112
48+
ABC
49+
25555
50+
where 112 is the footwear id,ABC is brand name,25555 is price.
51+
52+
consider the sample input and output.
53+
100
54+
Sketchers
55+
sneekers
56+
12345
57+
103
58+
Puma
59+
running shoes
60+
10099
61+
102
62+
reebok
63+
Running shoes
64+
5667
65+
101
66+
Reebok
67+
running shoes
68+
5656
69+
99
70+
reebok
71+
floaters
72+
5666
73+
Running shoes
74+
reebok
75+
76+
Sample output:
77+
3
78+
99
79+
reebok
80+
5666
81+
82+
Sample input2:
83+
84+
100
85+
Puma
86+
sneekers
87+
12345
88+
101
89+
Puma
90+
sneekers
91+
10099
92+
102
93+
Puma
94+
sneekers
95+
5000
96+
102
97+
Reebok
98+
sneekers
99+
8000
100+
104
101+
Puma
102+
floaters
103+
2000
104+
running shoes
105+
bata
106+
107+
Sample output:
108+
Footwear not available
109+
Brand not available

IPA2/footwearProgram.java

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
package IPA2;
2+
import java.util.*;
3+
public class footwearProgram
4+
{
5+
public static void main(String[]args)
6+
{
7+
Scanner sc = new Scanner(System.in);
8+
Footwear[] ft = new Footwear[5];
9+
for(int i=0; i<5; i++)
10+
{
11+
int a = sc.nextInt();sc.nextLine();
12+
String b = sc.nextLine();
13+
String c = sc.nextLine();
14+
int d = sc.nextInt();sc.nextLine();
15+
16+
ft[i]=new Footwear(a,b,c,d);
17+
}
18+
19+
String ftType = sc.nextLine();
20+
String ftName = sc.nextLine();
21+
int count = getCountByType(ft,ftType);
22+
if(count>0)
23+
{
24+
System.out.println(count);
25+
}
26+
else
27+
{
28+
System.out.println("Footwear not avaliable");
29+
}
30+
31+
Footwear obj = getSecondHighestPriceByBrand(ft, ftName);
32+
if(obj!=null)
33+
{
34+
System.out.println(obj.getId());
35+
System.out.println(obj.getName());
36+
System.out.println(obj.getPrice());
37+
}
38+
else
39+
{
40+
System.out.println("Brand not available");
41+
}
42+
43+
}
44+
45+
public static int getCountByType(Footwear[] ft, String t)
46+
{
47+
int count = 0;
48+
for(int i=0; i<ft.length; i++)
49+
{
50+
if(ft[i].getType().equalsIgnoreCase(t))
51+
{
52+
count++;
53+
}
54+
}
55+
if (count>0)
56+
{
57+
return count;
58+
}
59+
else
60+
{
61+
return 0;
62+
}
63+
}
64+
65+
public static Footwear getSecondHighestPriceByBrand(Footwear[] ft, String name)
66+
{
67+
for(int i =0; i<ft.length; i++)
68+
{
69+
if(ft[i].getName().equalsIgnoreCase(name))
70+
{
71+
return ft[i];
72+
}
73+
}
74+
return null;
75+
}
76+
}
77+
78+
class Footwear
79+
{
80+
private int id;
81+
private String name;
82+
private String type;
83+
private int price;
84+
85+
public Footwear(int id, String name, String type, int price)
86+
{
87+
this.id=id;
88+
this.name = name;
89+
this.type = type;
90+
this.price = price;
91+
}
92+
93+
public int getId()
94+
{
95+
return id;
96+
}
97+
public void setId(int id)
98+
{
99+
this.id = id;
100+
}
101+
public String getName()
102+
{
103+
return name;
104+
}
105+
public void setName(String name)
106+
{
107+
this.name=name;
108+
}
109+
public String getType()
110+
{
111+
return type;
112+
}
113+
public void setType(String type)
114+
{
115+
this.type = type;
116+
}
117+
public int getPrice()
118+
{
119+
return price;
120+
}
121+
public void setPrice(int price)
122+
{
123+
this.price = price;
124+
}
125+
}

0 commit comments

Comments
 (0)