Answer to Question #256976 in Java | JSP | JSF for Chakalaka

Question #256976

The customer should be able to buy items and get a receipts with all details of items bought, remember this is an advanced vending machine hence one can buy more than one items. The printed receipt contains the following details: the item name, quantity, price and total, it should also give a description of the change given out (see below example) Your change is disbursed as follows: N$100 X 1, N$10X1, N$5X1 ,N$1X3,10centsX3 and 5centsX1 4 |PRG510S – Namibia University of Science and Technology Please note the change is linked to the amount of cash in the machine that is if there are no hundreds then the user gets 2 x 50, and that should be recorded to indicate the remaining 50s in the machine has decreased. The same applies to when a customer pays with a 100 then the count for 100s in the machine increases.


1
Expert's answer
2021-10-27T00:26:39-0400
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
	    int n;
	    System.out.println("Enter number of items");
		Scanner in=new Scanner(System.in);
		n=in.nextInt();
		String [] names=new String [n];
		int [] quantities=new int [n];
		double [] price=new double [n];
		double [] total_price=new double [n];
		
		for(int i=0;i<n;i++){
		    System.out.println("Enter details of item "+(i+1)+": ");
		    System.out.println("Name: ");
		    names[i]=in.next();
		    System.out.println("Quantity: ");
		    quantities[i]=in.nextInt();
		    System.out.println("Price: ");
		    price[i]=in.nextDouble();
		    total_price[i]=price[i]*quantities[i];
		    
		}
		double sum=0;
		System.out.println("***********Receipt*************************");
		for(int i=0;i<n;i++){
		    System.out.println("Item "+(i+1)+": ");
		    System.out.println("Quantity: "+quantities[i]);
		    System.out.println("Price: "+price[i]);
		    System.out.println("Total price: "+total_price[i]);
		    sum+=total_price[i];
		}
		
		System.out.println("Grand total price = "+sum);
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS