-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
29 lines (25 loc) · 998 Bytes
/
Main.java
File metadata and controls
29 lines (25 loc) · 998 Bytes
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
public class Main {
public static void printManufacturerFirstLetters(Product[] productArray) {
for (Product product : productArray) {
System.out.println(product.getManufacturer().charAt(0));
}
}
public static float calcAverage(Product[] productArray) {
int divisore = productArray.length;
int sum = 0;
for (Product product : productArray) {
sum += product.getQuantity();
}
float average = (float) sum / divisore;
return average;
}
public static void main(String[] args) {
Product[] productArray = new Product[]{
new Product("telefono", "samsung", 123456, 2),
new Product("automobile", "Fiat", 456789, 1),
new Product("televisore", "LG", 123789, 3),
};
printManufacturerFirstLetters(productArray);
System.out.println("The average quantity is: " + calcAverage(productArray));
}
}