Supposing you are operating a warehouse that receives and issues out items daily,
and at the end of each day, you take stock of the transactions. Answer the following
based on your knowledge in Java Programming.
a) Provide a suitable name for your warehouse.
b) Suggest the type of item you are dealing with and the cost of each item (e.g.
bags of cement at 50 cedis per bag).
c) Write a Java programme named transactions.java that takes input from you in the
form of: positive integers representing the number of items brought in each time,
and negative integers representing the number of items issued out each time.
The programme will then calculate and print out the total number of items
received and issued out, as well as their corresponding total costs. Your
programme ends when the input is zero (0).
Source code
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("Enter the name of the warehouse: ");
String name=input.nextLine();
System.out.println("Enter the type of item: ");
String item=input.nextLine();
System.out.println("Enter the cost of each item: ");
double cost=input.nextDouble();
int n;
int item_received=0;
int item_issued=0;
while(true){
System.out.println("Enter an integer: ");
n=input.nextInt();
if (n>0){
item_received+=n;
}
else if (n<0){
item_issued+=(-n);
}
else if (n==0){
break;
}
}
System.out.println(name+" warehouse report");
System.out.println("Item name: "+item+"\tCost per item: "+cost);
System.out.println("******************************************************************************");
double total_cost_for_received=item_received*cost;
double total_cost_for_issued=item_issued*cost;
System.out.println("Total number of items received: "+item_received+"\tCost: "+total_cost_for_received);
System.out.println("Total number of items issued: "+item_issued+"\tCost: "+total_cost_for_issued);
}
}
Output
Comments
Leave a comment