A food-delivery kitchen records the number of orders received from different delivery zones over several consecutive days. The manager wants to analyze the records to understand the demand in each zone.
Create a program where rows (2 ≤ Z ≤ 5) represent zones and columns (5 ≤ D ≤ 15) represent days. Store the order count for each zone and day and perform the following task:
- Highest Total Orders: Find the zone with the highest total number of orders over all the days. Display the zone and its total orders.
- High Demand Days: For each zone, calculate the average daily orders. Display the days on which the number of orders is above average.
- Increase in Orders: For each zone, find the days on which the number of orders is higher than the previous day. Display the zone and day for each such day.
Example 1
INPUT:
Number of zones: 3
Number of days: 6
4 6 3 7 5 2
2 3 5 4 6 5
5 4 6 3 2 4
OUTPUT:
Highest Total Orders:
Zone 1: 27 orders
High Demand Days:
Zone 1: Day 2, Day 4, Day 5
Zone 2: Day 3, Day 5, Day 6
Zone 3: Day 1, Day 3
Increase in Orders:
Zone 1: Day 2, Day 4
Zone 2: Day 2, Day 3, Day 5
Zone 3: Day 3, Day 6
Example 2
INPUT:
Number of zones: 2
Number of days: 5
4 4 4 4 4
2 2 2 2 2
OUTPUT:
Highest Total Orders:
Zone 1: 20 orders
High Demand Days:
Zone 1: None
Zone 2: None
Increase in Orders:
Zone 1: None
Zone 2: None
Example 3
INPUT:
Number of zones: 6
Number of days: 6
OUTPUT:
INVALID ZONE
Example 4
INPUT:
Number of zones: 4
Number of days: 3
OUTPUT:
INVALID DAYS
import java.util.Scanner;
class FoodDelivery{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.print("Number of zones: ");
int z = in.nextInt();
System.out.print("Number of days: ");
int d = in.nextInt();
if(z < 2 || z > 5){
System.out.println("INVALID ZONES");
return;
}
if(d < 5 || d > 15){
System.out.println("INVALID DAYS");
return;
}
int a[][] = new int[z][d];
int highest = 0;
String names = "";
System.out.println("Enter order count zone-wise:");
for(int i = 0; i < z; i++){
System.out.println("Zone " + (i + 1));
int sum = 0;
for(int j = 0; j < d; j++){
a[i][j] = in.nextInt();
sum += a[i][j];
}
if(sum > highest){
highest = sum;
names += "Zone " + (i + 1) + " ";
}
}
System.out.println("Highest Total Orders:");
System.out.println(names + ": " + highest + " orders");
System.out.println("High Demand Days:");
for(int i = 0; i < z; i++){
int count = 0;
double sum = 0;
System.out.print("Zone " + (i + 1) + ": ");
for(int j = 0; j < d; j++){
sum += a[i][j];
}
for(int j = 0; j < d; j++){
double avg = sum / d;
if(a[i][j] > avg){
if(count == 0)
System.out.print("Day " + (j + 1));
else
System.out.print(", Day " + (j + 1));
count++;
}
}
if(count == 0)
System.out.println("None");
else
System.out.println();
}
System.out.println("Increase in Orders:");
for(int i = 0; i < z; i++){
int count = 0;
System.out.print("Zone " + (i + 1) + ": ");
for(int j = 0; j < d - 1; j++){
if(a[i][j] < a[i][j + 1]){
if(count == 0)
System.out.print("Day " + (j + 2));
else
System.out.print(", Day " + (j + 2));
count++;
}
}
if(count == 0)
System.out.println("None");
else
System.out.println();
}
}
}