-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproductProblem.java
More file actions
72 lines (60 loc) · 1.62 KB
/
productProblem.java
File metadata and controls
72 lines (60 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import java.util.*;
class Product{
private int id;
private String name;
private int availability;
private double price;
public Product(int id, String name, int availability , double price){
this.id = id;
this.name = name;
this.availability = availability;
this.price = price;
}
public int getId(){
return id;
}
public String getName(){
return name;
}
public int getAvailability(){
return availability;
}
public double getPrice(){
return price;
}
}
public class productProblem {
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Product[]arr = new Product[n];
for(int i =0; i<n; i++){
int a = sc.nextInt();
sc.nextLine();
String b = sc.nextLine();
int c = sc.nextInt();
double d = sc.nextDouble();
arr[i] = new Product(a, b, c, d);
}
double ans1 = averagePriceOfAvailability(arr);
if(ans1!=0){
System.out.println(ans1);
}else{
System.out.println("No available product found");
}
}
public static double averagePriceOfAvailability(Product[]arr ){
double average =0;
double count=0;
for(int i =0; i<arr.length;i++){
if(arr[i].getAvailability()>0){
average+=arr[i].getPrice();
count++;
}
}
return average/count;
}
public static Product findTheProduct(Prodcut[]arr , ){
return null;
}
}