i am trying to write a program to input details of several products and quantities and display
them.
After all the product data has been entered (terminated by 0), print the summary totals.:
The inputs will be inputed like so:
Kellogs
Cornflakes 750g
5000127062092
123
10
and should be outputed like so:
Kellogs:Cornflakes 750g:5000127062092:123:10:1230
Transactions 1
Total quantity 10
Total value 1230
Average cost 123
if a number of product details where entered the following would be added together:
The transactions is the number of times it has been around the loop
Total quantity is the quantity added together
Total value is the Total value added together
Average cost is the Average cost added together
e.g.
Input
Kellogs:Cornflakes 750g :5000127062092:123:10:1230
Kellogs:Rice Krispies 600g:5000127053090:123:16:1968
Quaker:Puffed Wheat 160g :1000108001010:78:11:858
Output
Transactions 3
Total quantity 37
Total value 4056
Average cost 109
But im havig trouble doing the above. I think i gotta use a loop or somthing.
Here is the code i have so far:
Code:public class ProcessProduct{ public static void main(String[] argv) { int barcodeLength, quantity, price, totalPrice; String barcode, manufaturer, productName; System.out.println ("Please enter manufaturer name"); manufaturer = UserInput.readString(); System.out.println ("Please enter product name"); productName = UserInput.readString(); System.out.println ("Please enter barcode"); barcode = UserInput.readString(); barcodeLength = barcode.length(); if (barcodeLength < 13){ System.out.println ("Error, invalid entry, barcode length is less than 13 characters"); System.exit (0); } if (barcodeLength > 13){ System.out.println("Error, invalid entry, barcode length is greater than 13 characters"); System.exit(0); } System.out.println ("Please enter quantity"); quantity = UserInput.readInt(); if (quantity <= 0 ){ System.out.println ("Error,invalid entry"); System.exit (0); } System.out.println ("Please enter price"); price = UserInput.readInt(); if (price <= 0 ){ System.out.println ("Error,invalid entry"); System.exit (0); } totalPrice = quantity * price; Product a = new Product (manufaturer, productName, barcode, price); System.out.println (a);




Reply With Quote