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);
}

}``````

Line 19, you use nextInt, which reads integer values (eg 123), but you want to read a char 'V' or 'N'. You could use next() to get the input as a String, then get the first char from that String.

SoniaC...
What is someone enters "v" or "n" instead of "V" or "N"?

SoniaC...
What is someone enters "v" or "n" instead of "V" or "N"?

That's the thing. I am just going on the instructions of my professor. She said she wants us to use V and N instead of 1 and 2. I got it to run wonderfully with 1 or 2 but the V and N is giving me trouble. It did cross my mind with the uppercase and lowercase issue but its what she asked us to do. So i dont know.

Line 19, you use nextInt, which reads integer values (eg 123), but you want to read a char 'V' or 'N'. You could use next() to get the input as a String, then get the first char from that String.

I tried that but still got an error

If you don't say exactly what the error was, nobody can help you fix it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.