0% found this document useful (1 vote)
2K views

Tax Calculation Using Switch Case in Java

This Java program uses a switch case statement to calculate taxes and bills for different appliances purchased. The program prompts the user to select an appliance, then reads in the price and quantity and calculates the tax rate and total bill based on the appliance selected. Tax rates are 8% for motors, 12% for fans, 5% for tubelights, 7.5% for wires, and 3% for other items. The program displays the final bill amount for each appliance purchase.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
2K views

Tax Calculation Using Switch Case in Java

This Java program uses a switch case statement to calculate taxes and bills for different appliances purchased. The program prompts the user to select an appliance, then reads in the price and quantity and calculates the tax rate and total bill based on the appliance selected. Tax rates are 8% for motors, 12% for fans, 5% for tubelights, 7.5% for wires, and 3% for other items. The program displays the final bill amount for each appliance purchase.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Tax Calculation using Switch Case in java

import java.io.*;

class shop

public static void main(String arg[])

int ch,num;

float price;

double tax,bill;

DataInputStream dts=new DataInputStream(System.in);

System.out.println("Please enter your choice to buy an appliance;");

System.out.println("1. Motor\n2. Fan\n3. Tubelight\n4. Wires\n5. Other”);

try

ch=Integer.parseInt(dts.readLine());

switch (ch)

case 1:

System.out.println("Please enter price for motor:");

price=Float.parseFloat(dts.readLine());

System.out.println("Enter no. of motor(s) you want to buy:");

num=Integer.parseInt(dts.readLine());

tax=((price*num)*8)/100;

bill=Math.round((price*num)+tax);

System.out.println("******************");
System.out.println("The bill for motor(s) are :"+bill);

break;

case 2:

System.out.println("Please enter price for fan:");

price=Float.parseFloat(dts.readLine());

System.out.println("Enter no. of fan(s) you want to buy:");

num=Integer.parseInt(dts.readLine());

tax=((price*num)*12)/100;

bill=Math.round((price*num)+tax);

System.out.println("************************");

System.out.println("The bill for motor(s) are :"+bill);

break;

case 3:

System.out.println("Please enter price for tubelight:");

price=Float.parseFloat(dts.readLine());

System.out.println("Enter no. of tubelight(ss) you want to buy:");

num=Integer.parseInt(dts.readLine());

tax=((price*num)*5)/100;

bill=Math.round((price*num)+tax);

System.out.println("******************************");

System.out.println("The bill for tubelight(s) are :"+bill);

break;

case 4:

System.out.println("Please enter price for wires:");


price=Float.parseFloat(dts.readLine());

System.out.println("Enter no. of wires you want to buy:");

num=Integer.parseInt(dts.readLine());

tax=((price*num)*7.5)/100;

bill=Math.round((price*num)+tax);

System.out.println("***************************");

System.out.println("The bill for wire(s) are :"+bill);

break;

case 5:

System.out.println("Please enter price for others:");

price=Float.parseFloat(dts.readLine());

System.out.println("Enter no. of others you want to buy:");

num=Integer.parseInt(dts.readLine());

tax=((price*num)*3)/100;

bill=Math.round((price*num)+tax);

System.out.println("*************************");

System.out.println("The bill for other(s) are :"+bill);

break;

default:

System.out.println("Sorry no such item");

catch(Exception e)

System.out.println(e.getMessage());
}

System.out.println("***************************************");

System.out.println("*********Thanks for your visit*********");

System.out.println("***************************************");

You might also like