Ask Question
27 March, 13:57

Write a function "cashier" that receives an int "c" for the number of items bought. The function will ask the price and task rate of each item and prints out the total cost. Sample Input Expected Output For item 1 Enter the price: 10 Enter the tax rate: 0 For item 2 Enter the price: 20 Enter the tax rate: 8 Your total price is 31.6 Sample Input 2 Expected Output 2 For item 1 Enter the price: 100 CS103 - Lab 5 Page 3 of S Enter the tax rate:8 For item 2 Enter the price: 20 Enter the tax rate: 0 For item 3 Enter the price1 40 Enter the tax rate:8 Your total price is 171.2 3406

+1
Answers (1)
  1. 27 March, 14:50
    0
    public static double cashier (int c) {

    double totalCost = 0.0;

    for (int i = 0; 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
    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;

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a function "cashier" that receives an int "c" for the number of items bought. The function will ask the price and task rate of each ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers