|
| 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