This is the instruction:
Mrs. Rogers, the owner of "Jus' Right supermarket", has asked your consulting firm to design a program for a simple cash register system which will allow the cashiers at the shop to total the price of the items being bought by a customer, calculate the tax on each item, calculate any relevant customer discount on the total and provide the final payable amount of the bill.
POINTS TO NOTE:
1. Items belong to one of two categories - VAT (V) or Non-Vat (N), and the system must accommodate for this:
a. VAT items incur a 10% tax;
b. Non-VAT items incur no tax.
2. The cashier will enter the category (V or N) and the price of each item until all of a customer's items have been entered. (The list of items ends when the cashier enter 0 for rhe price)
3. a discount of 15% is given is the total exceeds $1000.00.
4. Things to be displayed to the screen: subtotal before tax, total tax, discount and final bill payable.
This is my code: but when i run it with the V and N I get errors, If I run it with 1 and 2 instead it runs fine.
How can I get it to work using V and N in the cases?
package AssgnII;
import java.util.*;
public class Cashregister {
public static void main(String[] args)
{
Scanner inn = new Scanner (System.in);
double Item_price=0, Vat = 0, Sub_total = 0, Total_tax = 0, Final_bill, Total = 0, Dis_cnt = 0;
int Item_cat;
char V, N;
//System.out.println("Enter 0 to end price");
System.out.println("Please enter the price of the item");
Item_price = inn.nextDouble();
while (Item_price !=0)
{
System.out.println("Please enter the category of the item - V for Vat and N for non-vat");
Item_cat = (char) inn.nextInt();
switch (Item_cat)
{
case 'V' :
{ Vat = Item_price * 0.10;
break;
}
case 'N' :
{ Vat = Item_price * 0.00;
break;
}
default : System.out.println("ERROR, ERROR, ERROR");
}
Sub_total += Item_price;
Total_tax += Vat;
Total = Sub_total + Total_tax;
System.out.println("Enter the price of the item");
Item_price = inn.nextDouble();
}
if (Total > 1000)
Dis_cnt = Total * 0.15;
Final_bill = Total - Dis_cnt;
System.out.println("The subtotal is" + Sub_total);
System.out.println("The Total Tax is"+ Total_tax);
System.out.println("The Discount is" + Dis_cnt);
System.out.println("The Final bill is" + Final_bill);
}
}