Respuesta :
Answer:
public static double cashier(int c){
double totalCost = 0.0;
for(int i = 0; i<c; i++){
System.out.println("Enter the price for the "+(i+1)+" item");
Scanner in = new Scanner(System.in);
double price = in.nextDouble();
System.out.println("Enter the tax for the "+(i+1)+" item");
double taxRate = in.nextDouble();
double tax = (taxRate/100)*price;
totalCost = totalCost+(price+tax);
}
return totalCost;
}
Explanation:
Find the complete java code that prompts user for number of items below:
import java.util.Scanner;
public class VendingTest {
public static void main(String[] args) {
System.out.println("How many Items did you buy");
Scanner input = new Scanner(System.in);
int c = input.nextInt();
//Calling the method cashier()
double returnedTotal = cashier(c);
System.out.println("Total price: "+returnedTotal);
}
public static double cashier(int c){
double totalCost = 0.0;
for(int i = 0; i<c; i++){
System.out.println("Enter the price for the "+(i+1)+" item");
Scanner in = new Scanner(System.in);
double price = in.nextDouble();
System.out.println("Enter the tax for the "+(i+1)+" item");
double taxRate = in.nextDouble();
double tax = (taxRate/100)*price;
totalCost = totalCost+(price+tax);
}
return totalCost;
}
}