Programmers for a Better Tomorrow is now in partnership with
Programmers for a Better Tomorrow is now in partnership with a local Food Bank which distributes food items to people in need. People come in to a Food Bank and make their donations, and others might come in to make a request for any food item they want.
A Food Bank Management Program is used to keep track of the stock the Food Bank has (i.e., the donations), keep a record of requests that come in, fulfilling requests and printing the status report which consists of the amount of stock present in the food bank and the requests that are not yet fulfilled.
The program will require you to make at least one array. You may choose to make multiple onedimensional arrays: one to serve as a Donations Table and one to serve as a Request Table. The index of the array will represent the inventory type. The value in the array will represent the amount present or needed of that type.
You may, instead, choose to combine these to two arrays into a single two-dimensional array.
There are 5 inventory types:
0. Protein
1. Dairy
2. Grains
3. Vegetables
4. Fruits
Your program should allow the user the following options:
1. Enter a Donation
2. Enter a Request
3. Fulfill Requests
4. Print status report
5. Exit 2
Option 1: Ask the user for the inventory type and amount of the donation to be made. When the donation has been added to the donations table, the program should notify the user by printing out “Donation Added”.
Option 2: Ask the user for the inventory type and amount of the request to be made. When the request has been added to the requests table, the program should notify the user by printing out “Request Added”.
Option 3: Check each type of inventory in the Request Table. For each item that has a value in the request table, check to see if there is inventory of the same type in the donations table. If there are no donations of that type, print “ requests cannot be fulfilled.” Replace with the correct inventory type (Dairy, Fruit, etc.). If there is some inventory in the donations table, but not enough to process all requests, print “ requests will be partially fulfilled”. Reduce both the donation and request amounts based on how much of the request was able to be fulfilled. Replace with the correct inventory type (Dairy, Fruit, etc.). If there is enough inventory to fulfill the request, print “type x> requests will be fulfilled.” Reduce the appropriate amount from the Donations Table and remove the amount from the Request Table. Replace with the correct inventory type (Dairy, Fruit, etc.).
Option 4: Print both tables, indicating which is for donations and which is for requests. After options 1, 2, 3, and 4 prompt the user with the menu again.
Option 5: Print “Thank you for running our system!” and then the program exits. Do not prompt the user for any more information.
Solution
/* java programme */
import java.util.*;
import java.io.*;
class demo
{
public static void main(String[] args)
{
int donations[][]={{0,0},{1,0},{2,0},{3,0},{4,0}}; //first coummn 0,1,2,3,4 indicates inventory types(Protein,Dairy,Grains,Vegetables,Fruits,second column indicates donations stock
int requests[][]={{0,0},{1,0},{2,0},{3,0},{4,0}}; //first coummn 0,1,2,3,4 indicates inventory types(Protein,Dairy,Grains,Vegetables,Fruits,second column indicates requests stock
String name[]={\"Protein\",\"Dairy\",\"Grains\",\"Vegetables\",\"Fruits\"};
String tempname;
int invtype;
while(1==1)
{
System.out.println(\"1. Enter a Donation\ 2. Enter a Request \ 3. Fulfill Requests \ 4. Print status report \ 5. Exit \ \");
Scanner sc=new Scanner(System.in);
System.out.println(\"Enter your Choice 1 2 3 4 5 \ \");
int choice=sc.nextInt();
switch(choice)
{
case 1 :
System.out.println(\"Select Inventory type\ 0 -- > Protein\ 1 -- > Dairy\ 2 -- > Grains\ 3 -- > Vegetables4 -- > Fruits\ \");
invtype=sc.nextInt();
if(invtype<0 || invtype >4 )
{
System.out.println(\"Wrong choice : \ \");
break;
}
else
{
System.out.println(\"Enter your Choice 1 | 2 | 3| 4 | 5 \ \");
donations[invtype][1]= donations[invtype][1]+1;
System.out.println(\"Donation Added\ \");
break;
}
case 2 :
System.out.println(\"Select Inventory type\ 0 -- > Protein\ 1 -- > Dairy\ 2 -- > Grains\ 3 -- > Vegetables -- > Fruits\ \");
invtype=sc.nextInt();
if(invtype<0 || invtype >4 )
{
System.out.println(\"Wrong choice : \ \");
break;
}
else
{
System.out.println(\"Enter your Choice 1 | 2 | 3| 4 | 5 \ \");
requests[invtype][1]= requests[invtype][1]+1;
System.out.println(\"Request Added\ \");
break;
}
case 3 :
for(int i=0;i<5;i++)
{
int j=1;
tempname=name[i];
if (donations[i][j]>=requests[i][j])
{
System.out.println(tempname + \"Requests will be fulfilled\");
donations[i][j]=donations[i][j]-requests[i][j];
requests[i][j]=0;
}
else if(donations[i][j]==0 && requests[i][j]>0)
{
System.out.println(tempname+ \"Requests cannot be fulfilled\");
donations[i][j]=0;
requests[i][j]=requests[i][j]-donations[i][j];
}
else if (donations[i][j]<requests[i][j])
{
System.out.println(tempname+ \"Requests will be partially fulfilled\");
donations[i][j]=0;
requests[i][j]=requests[i][j]-donations[i][j];
}
else
{
}
}
break;
case 4 :
System.out.println(\"Donation Table\ \");
for(int i=0;i<5;i++)
{
int j=1;
tempname=name[i];
System.out.println(tempname+ \"\\t\"+donations[i][j]+\"\ \");
}
System.out.println(\"Request Table\ \");
for(int i=0;i<5;i++)
{
int j=1;
tempname=name[i];
System.out.println(tempname+ \"\\t\"+requests[i][j]+\"\ \");
}
break;
case 5 :
System.out.println(\"Thank you for running our system!\");
System.exit(0);
break;
default :
System.out.println(\"Wrong Choice!.......\");
}
}
}
}
OutPut :
C:\\Users\\Ashok\\Desktop\\ja>java demo
1. Enter a Donation
2. Enter a Request
3. Fulfill Requests
4. Print status report
5. Exit
Enter your Choice 1 2 3 4 5
1
Select Inventory type
0 -- > Protein
1 -- > Dairy
2 -- > Grains
3 -- > Vegetables4 -- > Fruits
2
Enter your Choice 1 | 2 | 3| 4 | 5
Donation Added
1. Enter a Donation
2. Enter a Request
3. Fulfill Requests
4. Print status report
5. Exit
Enter your Choice 1 2 3 4 5
3
ProteinRequests will be fulfilled
DairyRequests will be fulfilled
GrainsRequests will be fulfilled
VegetablesRequests will be fulfilled
FruitsRequests will be fulfilled
1. Enter a Donation
2. Enter a Request
3. Fulfill Requests
4. Print status report
5. Exit
Enter your Choice 1 2 3 4 5
4
Donation Table
Protein 0
Dairy 0
Grains 1
Vegetables 0
Fruits 0
Request Table
Protein 0
Dairy 0
Grains 0
Vegetables 0
Fruits 0
1. Enter a Donation
2. Enter a Request
3. Fulfill Requests
4. Print status report
5. Exit
Enter your Choice 1 2 3 4 5




