does anyone know where there is an example of how to write code for tax added on to the subtotal to equal price? I looked in the tutorials but didnt see anything like it, and I dont just want people to do my work for me because I want to learn how to write code myself. I am a beginner just to let you know
6 3007 Ganon11 3,652
Recognized Expert Specialist
If you have the tax rate (a.k.a. 5%) and the subtotal (e.g. $10.00), you can multiply the subtotal by the percentage to determine the amount of tax to add - then add that amount to the subtotal to find the total.
The tax rate will either be held as a decimal (a.k.a. 5% would be 0.05) or as an integer (a.k.a. 5% would be 5), and your calculations will have to differ accordingly - if you hold it as a decimal, you can multiply straight away, but if you hold it as an integer, you will have to divide by 100.0 before multiplying.
could someone please help, I have been working on this the last couple days trying to figure out why this wont accept the Tax code I put in there,
/*
* Order1.java
*
* Created on December 18, 2006, 6:16 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author test
*/
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.lang.NumberFormatException;
public class Order1
{
public static void main(String[] args)
{
MyOrder1 myFrame = new MyOrder1() ;
myFrame.setVisible(true) ;
}
}
class MyOrder1 extends JFrame implements ActionListener
{
private static final int WIDTH = 200 ;
private static final int HEIGHT = 200 ;
private static final int X_ORIGIN = 400 ;
private static final int Y_ORIGIN = 200 ;
// create new buttons and label them
private JButton Total ;
private JButton Reset ;
private JTextField ChickenField ;
private JTextField PorkField ;
private JTextField CattleField ;
private JTextField TotalField ;
private JTextField TaxField;
private Component Tax;
//creates new label icons for my items
public MyOrder1()
{
String Response = new String() ;
JLabel Chicken = new JLabel("Chicken: $1.19 LB ") ;
JLabel Pork = new JLabel (" Pork: $2.17 LB ") ;
JLabel Cattle = new JLabel(" Cattle: $3.27 LB ") ;
JLabel tax = new JLabel(" Tax: ") ;
JLabel total = new JLabel(" Total : ");
ChickenField = new JTextField(5) ;
PorkField = new JTextField(5) ;
CattleField = new JTextField(5) ;
TaxField = new JTextField(5) ;
TotalField = new JTextField(5) ;
ChickenField.setText("0") ;
PorkField.setText("0") ;
CattleField.setText("0") ;
TotalField.setText("") ;
Total = new JButton("Total") ;
Total.addActionListener(this) ;
Reset = new JButton("Reset") ;
Reset.addActionListener(this) ;
// get the content pane
Container contentPane = getContentPane() ;
// create a new layout manager for the pane
FlowLayout aLayout = new FlowLayout() ;
// assign the new layout manager to the content pane
contentPane.setLayout(aLayout) ;
// add the "Exit" button to the content pane
contentPane.add(Chicken) ;
contentPane.add(ChickenField) ;
contentPane.add(Pork) ;
contentPane.add(PorkField) ;
contentPane.add(Cattle) ;
contentPane.add(CattleField) ;
contentPane.add(Tax) ;
contentPane.add(TaxField) ;
contentPane.add(total) ;
contentPane.add(TotalField) ;
contentPane.add(Total) ;
contentPane.add(Reset) ;
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(X_ORIGIN, Y_ORIGIN, WIDTH, HEIGHT) ;
}
public void actionPerformed(ActionEvent e)
{
String chicken, pork, cattle;
float ayam=0, babi=0, sapi=0;
int i;
Object source = e.getSource() ;
if (source == Reset)
{
ChickenField.setText("0") ;
PorkField.setText("0") ;
CattleField.setText("0") ;
TotalField.setText("0") ;
}
else if (source == Total)
{
i = 0;
try
{
chicken = ChickenField.getText();
ayam = Float.valueOf(chicken).floatValue();
}
catch (Exception d)
{
JOptionPane.showMessageDialog(null, "Quantity of Chicken is not valid...", "Error",
JOptionPane.ERROR_MESSAGE);
i=1;
}
try
{
pork = PorkField.getText();
babi = Float.valueOf(pork).floatValue();
}
catch (Exception d)
{
JOptionPane.showMessageDialog(null, "Quantity of Pork is not valid...", "Error",
JOptionPane.ERROR_MESSAGE);
i=1;
}
try
{
cattle = CattleField.getText();
sapi = Float.valueOf(cattle).floatValue();
}
catch (Exception d)
{
JOptionPane.showMessageDialog(null, "Quantity of Cattle is not valid...", "Error",
JOptionPane.ERROR_MESSAGE);
i=1;
}
if (i==0)
{
float total = ayam * 1.19f + babi * 2.17f + sapi * 3.27f ;
String tot= String.valueOf(total);
TotalField.setText(tot) ;
double tax = 0;
tax = (total * 0.08);
String setTax = "" + Tax;
JLabel tax.setText("setTax") ;
total = total + tax;
can someone please help
Sorry most people had been away.
Is this what you want - /*
-
* Order1.java
-
*
-
* Created on December 18, 2006, 6:16 PM
-
*
-
* To change this template, choose Tools | Template Manager
-
* and open the template in the editor.
-
*/
-
-
/**
-
*
-
* @author test
-
*/
-
import java.awt.*;
-
import java.awt.event.ActionEvent;
-
import java.awt.event.ActionListener;
-
import javax.swing.*;
-
import java.lang.NumberFormatException;
-
-
public class Order1 {
-
public static void main(String[] args) {
-
MyOrder1 myFrame = new MyOrder1() ;
-
myFrame.setVisible(true) ;
-
}
-
-
}
-
-
class MyOrder1 extends JFrame implements ActionListener {
-
private static final int WIDTH = 200 ;
-
private static final int HEIGHT = 200 ;
-
private static final int X_ORIGIN = 400 ;
-
private static final int Y_ORIGIN = 200 ;
-
-
// create new buttons and label them
-
private JButton Total ;
-
private JButton Reset ;
-
private JTextField ChickenField ;
-
private JTextField PorkField ;
-
private JTextField CattleField ;
-
private JTextField TotalField ;
-
private JTextField TaxField;
-
-
private Component Tax;
-
JLabel tax;
-
//creates new label icons for my items
-
public MyOrder1() {
-
String Response = new String() ;
-
JLabel Chicken = new JLabel("Chicken: $1.19 LB ") ;
-
JLabel Pork = new JLabel (" Pork: $2.17 LB ") ;
-
JLabel Cattle = new JLabel(" Cattle: $3.27 LB ") ;
-
tax = new JLabel(" Tax: ") ;
-
JLabel total = new JLabel(" Total : ");
-
ChickenField = new JTextField(5) ;
-
PorkField = new JTextField(5) ;
-
CattleField = new JTextField(5) ;
-
TaxField = new JTextField(5) ;
-
TotalField = new JTextField(5) ;
-
ChickenField.setText("0") ;
-
PorkField.setText("0") ;
-
CattleField.setText("0") ;
-
TotalField.setText("") ;
-
-
Total = new JButton("Total") ;
-
Total.addActionListener(this) ;
-
-
Reset = new JButton("Reset") ;
-
Reset.addActionListener(this) ;
-
-
-
-
-
// get the content pane
-
Container contentPane = getContentPane() ;
-
-
// create a new layout manager for the pane
-
FlowLayout aLayout = new FlowLayout() ;
-
-
// assign the new layout manager to the content pane
-
contentPane.setLayout(aLayout) ;
-
-
// add the "Exit" button to the content pane
-
contentPane.add(Chicken) ;
-
contentPane.add(ChickenField) ;
-
contentPane.add(Pork) ;
-
contentPane.add(PorkField) ;
-
contentPane.add(Cattle) ;
-
contentPane.add(CattleField) ;
-
contentPane.add(tax) ;
-
contentPane.add(TaxField) ;
-
contentPane.add(total) ;
-
contentPane.add(TotalField) ;
-
contentPane.add(Total) ;
-
contentPane.add(Reset) ;
-
-
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
setBounds(X_ORIGIN, Y_ORIGIN, WIDTH, HEIGHT) ;
-
}
-
public void actionPerformed(ActionEvent e) {
-
String chicken, pork, cattle;
-
float ayam=0, babi=0, sapi=0;
-
int i;
-
-
Object source = e.getSource() ;
-
-
if (source == Reset) {
-
ChickenField.setText("0") ;
-
PorkField.setText("0") ;
-
CattleField.setText("0") ;
-
TotalField.setText("0") ;
-
}
-
else if (source == Total) {
-
i = 0;
-
try {
-
chicken = ChickenField.getText();
-
ayam = Float.valueOf(chicken).floatValue();
-
}
-
catch (Exception d) {
-
JOptionPane.showMessageDialog(null, "Quantity of Chicken is not valid...", "Error",
-
JOptionPane.ERROR_MESSAGE);
-
i=1;
-
}
-
try {
-
pork = PorkField.getText();
-
babi = Float.valueOf(pork).floatValue();
-
}
-
catch (Exception d) {
-
JOptionPane.showMessageDialog(null, "Quantity of Pork is not valid...", "Error",
-
JOptionPane.ERROR_MESSAGE);
-
i=1;
-
}
-
try {
-
cattle = CattleField.getText();
-
sapi = Float.valueOf(cattle).floatValue();
-
}
-
catch (Exception d) {
-
JOptionPane.showMessageDialog(null, "Quantity of Cattle is not valid...", "Error",
-
JOptionPane.ERROR_MESSAGE);
-
i=1;
-
}
-
if (i==0) {
-
double total = ayam * 1.19 + babi * 2.17 + sapi * 3.27 ;
-
double taxAmount = 0.0;
-
taxAmount = (total * Double.parseDouble(TaxField.getText()));
-
String setTax = "" + taxAmount;
-
tax.setText("Tax:"+setTax) ;
-
total = total + taxAmount;
-
String tot= String.valueOf(total);
-
TotalField.setText(tot);
-
}
-
}
-
}
-
}
thanks that was what I was looking for
thanks that was what I was looking for
Welcome. Hope to see you around asking or helping others as well.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Phil Powell |
last post by:
Relevancy scores are normally defined by a MySQL query on a table that
has a fulltext index. The rules for relevancy scoring will exclude
certain words due to their being too short (minimum...
|
by: Building Blocks |
last post by:
Hi,
All I need is a simle calculate form script which contains this:
A script that can handle text input, radio buttons, checkboxes, and
dropdowns. Each one of these variables will contain a...
|
by: Gálos Zsuzsa |
last post by:
Hi all,
I need to calculate Formulas.
For example:
dim strFormula as string="25*(12-6)"
I ned a DotNet Function to calculate this Formula (25*(12-6)=150):
dim dblValue as double = 150
|
by: Robert de Ridder |
last post by:
I use an asp page to display pages, where the dynamic content is in an
iframe.
To calculate the height of the iframe I use the calcheight function. However
when trying to do this with external...
|
by: Jan Szymczuk |
last post by:
I'm creating an MS Access 2000 database where I have a number of people
entered using simple basic fields, Surname: SMITH
Forenames: John
DoB: 09/09/1958
Age:...
| |
by: Ladislau S. |
last post by:
Dear reader,
I am an occasional user of MS Access 2000 running on Windows 98. My hobby is
ship model building so I made a database for things that I want to buy.
After two strokes I bin unable...
|
by: charliewest |
last post by:
Can someone pls point me to or recommend the easiest way to calculate
someone´s age using the TimeSpan object, in .NET CF?
Isn´t there a simple way to use the TimeSpan object to calculate the...
|
by: Libber39 |
last post by:
Hi everyone,
Have a query on how to calculate the amount of weeks and days contained in a number in an access query. ie: the difference in days between 2 dates amounts to 17 days. I want to now...
|
by: SuzK |
last post by:
I am trying to calculate in VBA in Access 2002 a moving average and update a table with the calculations. Fields in my WeeklyData table are
Week Ending (date)
ItemNbr (double)
Sales Dollars...
|
by: rrstudio2 |
last post by:
I am using the following vba code to calculate the median of a table
in MS Access:
Public Function MedianOfRst(RstName As String, fldName As String) As
Double
'This function will calculate the...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |