# Please give me the code for the below problem

vidya
Please give me the code for the below problem
1 Answer(s)      7 years ago
Posted in : Java Interview Questions

November 16, 2009 at 3:31 PM

Hi Friend,

Try the following code:

import java.util.*;
class Tax{
int qty = 0;
String prodName = null;
float price = 0.0f;
boolean imported = false;
boolean exempted = false;
float tax = 0.0f;

void calculateSalesTax() {
float totalTax = 0.0f;
if(imported)
totalTax = 0.05f;
if(!exempted)
totalTax = .1f;
if((imported)&&(!exempted))
totalTax = .15f;
tax = totalTax * price;
}

public String toString() {
float p=price+tax;
return qty+" "+prodName+" at "+p;
}
}
public class SalesTax{
public static void main(String [] args) throws Exception{
SalesTax st = new SalesTax();
Scanner input = new Scanner(System.in);
ArrayList<Tax> list = new ArrayList<Tax>();
int no = 1;
while(true){
Tax tax = new Tax();
System.out.print("Quantity: ");
int qty = input.nextInt();
tax.qty = qty;
System.out.print("Product prodName: ");
String prod = input.next();
tax.prodName = prod;
System.out.print("Price: ");
float p = input.nextFloat();
tax.price = p;
System.out.print("Is it Imported[y/n]: ");
String imp =input.next();
if(imp.toLowerCase().equals("y"))
tax.imported = true;
System.out.print("Is it Exempted[y/n]: ");
String exe = input.next();
if(exe.toLowerCase().equals("y"))
tax.exempted = true;
tax.calculateSalesTax();
no++;
System.out.print("Add More Products [y/n]: ");
String add = input.next();
break;
}
float tp = 0.0f;
float tt = 0.0f;
for(int i=0; i<list.size(); i++) {
Tax tax = list.get(i);
tp += tax.price;
tt += tax.tax;
System.out.println(tax);
}

System.out.println("Sales Taxes:"+tt);
System.out.println("Total: "+(tp+tt));

}

}

Thanks

Related Tutorials/Questions & Answers:
Please give me the code for the below problem - Java Interview Questions
Please give me the code for the below problem  PROBLEM : SALES TAXES Basic sales tax is applicable at a rate of 10% on all goods, except books... Vidya  Hi Friend, Try the following code: import java.util.
Give me the source code for this problem
Give me the source code for this problem  Ram likes skiing a lot. That's not very surprising, since skiing is really great. The problem with skiing... is connected to another if it's at left, at right, above or below it. In the sample
please help me to give code  Write a function, sliding(word, num)that behaves as follows. It should print out each slice of the original word having length num, aligned vertically as shown below. A call to sliding(examples, 4
Please tell me the code to generate the below structure
Please tell me the code to generate the below structure  1 2 3 4 5 6 7 8 9 1 2 3 4 6 7 8 9 1 2 3 7 8 9 1 2 8 9 1 9 1 2 8 9 1 2 3 7 8 9 1 2 3 4 6 7 8 9 1 2 3
please help me to give code  Write a function with a signature cheerlead(word) that prints a typical cheer as follows. The word robot: Gimme an R Gimme an O Gimme a B Gimme an O Gimme a T What did you give me? ROBOT
please help me to give code  Write a program that prints an n-level stair case made of text. The user should choose the text character and the number of stairs in the stair case * ** *** ****   Hi friend
please help me to give code  Write a program that uses loops to generate an n x n times table. The program should get n from the user. As a model here is a 4 x4 version: | 1 2 3 4
please help me to give code  Write a program that reads a file named famous.txt and prints out the line with the longest length. In the case of a tie, you may print out only one of them. For example in the file: Alan Turing
how to send email please give me details with code in jsp,servlet
how to send email please give me details with code in jsp,servlet  how to send email please give me details with code in jsp,servlet
"int a=08 or 09" its giving compile time error why   "int a=08 or 09" its giving compile time error why ? can any one give me the answer of this please
Please give me coding for this..
Please give me coding for this..  Write an application that inputs one number consisting of five digits from the user.separates the number ibto its individual digits and prints the digits separated from one another by three
please help me to this problem..  i wrote a program like keyboard... inside the JTextField) but i want to make this program to let me write where i clicked (i.e allows me to write any thing at the field where i clicked
please help me to overcome this problem  how to make it easy to write java code. can u please give me suggestions
please give me an idea to develop a program for this question?
please give me an idea to develop a program for this question?  How to enter a text or number from keyboard without using InputStreamReader method in java
Plz give me code for this question
Plz give me code for this question  Program to find depth of the file in a directory and list all files those are having more number of parent directories
please give me a java program for the following question
please give me a java program for the following question  Write...; In the previous code, we forget to add an icon to button. So we are sending the updated code. import java.awt.*; import javax.swing.*; import
verify the code and give me the code with out errors
verify the code and give me the code with out errors   import...(); } } when i run this program... it shows the given below errors.pls clear the errors and give me correct tutorial for my knowledge improving.pls anyone
please give me an example about shopping cart using spring and hibernate
please give me an example about shopping cart using spring and hibernate  who can give me an ex about shoppingcart using spring and hibernate intergration ? thanks alot
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Body Mass Index(BMI) is a measure of health on weight. It can be calculated by taking... Interpretation Below 16 seriously
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a program that displays the following table (note that 1 mile is 1.609 kilometers). Miles Kilometers
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a program that prompts the user to enter the number of students and each studentā??s name and score, and finally displays the name of the students
problem in writing coding. Please help me.  Hi sir, my name is Logeswaran. I have problem in writing JSP coding for my university assigments... like? I'm really stuck on this. Please help me. By the way, I'm using Access
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a program that reads in investment amount, annual interest rate, and number of years, and displays the future investment value using the following formula
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Suppose that the tuition for a university is RM10,000 this year and increases 5% every year. Write a program that computes the tuition in ten years and the total cost
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a function called ChangeToNext that take in an uppercase character parameter ch. The function returns the next uppercase character if ch is between 'A' and 'Y
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a class that contains the following two methods: /* converts from inches to centimeters */ Public static double inchToCentimeter(double in) /* converts from
hello sir, please give me answer - Java Beginners
hello sir, please give me answer  Write a program in Java that calculates the sum of digits of an input number, prints... ways in java? so , sir please tell me full solution of this program   Here is your complete
Hi Every One , please give me some idia to opning audio File . please Help ..
Hi Every One , please give me some idia to opning audio File . please Help ..  hi Dear Friend , please give me a program to opening audio file... me .please Help
please help me to write a code for this program
please help me to write a code for this program   1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
please help me to write a code for this program
please help me to write a code for this program   1 1 1 1 2 2 1 1 3 4 3 1 1 4 7 7 4 1
please convert for me this code to GUI - Swing AWT
please convert for me this code to GUI    THE CODES ARE BELOW...; } else screen.displayMessageLine( "\nInvalid account Nummber or PIN, Please...; screen.displayMessageLine("\n Your cash has been"+ "dispensed. please take your cash