1 Use a sentinel controlled loop to sum up a series of price

1) Use a sentinel controlled loop to sum up a series of prices input by the user. Exit the loop when the user enters -99. Do not add -99 to the total. b) After the loop is complete, display a bill with the output lined up in columns and using two decimal places. The bill should include the total, the tax on that total (assume 7% for the tax rate), and a grand total including tax.

Solution

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chegg;

import java.util.ArrayList;
import java.util.Scanner;

public class TestBill {


public static void main(String[] args)
{
ArrayList<Double> prices = new ArrayList<>();
Scanner input = new Scanner(System.in);
double price;
  
while(true)
{
System.out.println(\"Enter a price or enter -99 to exit : \");
price = input.nextDouble();
if(price==-99)
break;
else
prices.add(price);
}
  
if(prices.size()>0)
{
double sum = 0,tax,total;
int i=1;
  
for(double p : prices)
{
System.out.println(\"Item \"+i+ \" : \"+String.format(\"%.2f\",p));
sum = sum+p;
i++;
}
  
tax = 0.07*sum;
total = tax+sum;
  
System.out.println(\"Sum is : \"+sum);
System.out.println(\"Tax is : \"+tax);
System.out.println(\"Total is : \"+total);
}
}
  
}

1) Use a sentinel controlled loop to sum up a series of prices input by the user. Exit the loop when the user enters -99. Do not add -99 to the total. b) After

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site