473,799 Members | 3,671 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Payment program question error??????

do
This is direction: Modifying the calculateJButto nActionPerforme d method.
Modify the if statement

that starts in line 217 to check if the user has not entered a name and/or

selected any JCheckBoxes. Also add code to the
calculateJButto nActionPerforme d

method (starting in line 252) that determines whether the new JCheckBoxes

have been selected. This can be done using if statements that are similar to
the ones

already in the method. Use the if statements to update the bill amount. The
bill

amount should be displayed in the totalPriceJText Field with the format

"$0.00".

//Source Code

// Exercise 5 DentalPayment.j ava
// This application calculates the total cost of the bill for a
// patient at a dental office.
import java.awt.*;
import java.awt.event. *;
import java.text.*;
import javax.swing.*;

public class DentalPayment extends JFrame
{
// JLabel that displays header on application window
private JLabel dentalPaymentFo rmJLabel;

// JLabel and JTextField for patient name
private JLabel patientNameJLab el;
private JTextField patientNameJTex tField;

// JCheckBox and JLabel for cleaning
private JCheckBox cleaningJCheckB ox;
private JLabel cleaningPriceJL abel;

// JCheckBox and JLabel for cavity filling
private JCheckBox cavityFillingJC heckBox;
private JLabel cavityFillingPr iceJLabel;

// JCheckBox and JLabel for X-Ray
private JCheckBox xRayJCheckBox;
private JLabel xRayPriceJLabel ;

// JCheckBox and JLabel for fluoride
private JCheckBox fluorideJCheckB ox;
private JLabel fluoridePriceJL abel;

// JCheckBox and JLabel for root canal
private JCheckBox rootCanalJCheck Box;
private JLabel rootCanalPriceJ Label;

// JCheckBox, JLabel and JTextField for other services
private JCheckBox otherJCheckBox;
private JLabel otherPriceJLabe l;
private JTextField otherPriceJText Field;

// JLabel and JTextField for total fee
private JLabel totalJLabel;
private JTextField totalJTextField ;

// JButton to initiate calculation of fee
private JButton calculateJButto n;

// no-argument constructor
public DentalPayment()
{
createUserInter face();
}

// create and position GUI components; register event handlers
private void createUserInter face()
{
// get content pane for attaching GUI components
Container contentPane = getContentPane( );

// enable explicit positioning of GUI components
contentPane.set Layout( null );

// set up dentalPaymentFo rmJLabel
dentalPaymentFo rmJLabel = new JLabel();
dentalPaymentFo rmJLabel.setBou nds( 19, 19, 235, 28 );
dentalPaymentFo rmJLabel.setTex t( "Dental Payment Form" );
dentalPaymentFo rmJLabel.setFon t(
new Font( "Default", Font.PLAIN, 22 ) );
dentalPaymentFo rmJLabel.setHor izontalAlignmen t(
JLabel.CENTER );
contentPane.add ( dentalPaymentFo rmJLabel );

// set up patientNameJLab el
patientNameJLab el = new JLabel();
patientNameJLab el.setBounds( 19, 65, 91, 21 );
patientNameJLab el.setText( "Patient name:" );
contentPane.add ( patientNameJLab el );

// set up patientNameJTex tField
patientNameJTex tField = new JTextField();
patientNameJTex tField.setBound s( 132, 65, 117, 21 );
contentPane.add ( patientNameJTex tField );

// set up cleaningJCheckB ox
cleaningJCheckB ox = new JCheckBox();
cleaningJCheckB ox.setBounds( 16, 112, 140, 24 );
cleaningJCheckB ox.setText( "Cleaning" );
contentPane.add ( cleaningJCheckB ox );

// set up cleaningPriceJL abel
cleaningPriceJL abel = new JLabel();
cleaningPriceJL abel.setBounds( 211, 112, 38, 24 );
cleaningPriceJL abel.setText( "$35" );
cleaningPriceJL abel.setHorizon talAlignment( JLabel.RIGHT );
contentPane.add ( cleaningPriceJL abel );

// set up cavityFillingJC heckBox
cavityFillingJC heckBox = new JCheckBox();
cavityFillingJC heckBox.setBoun ds( 16, 144, 140, 24 );
cavityFillingJC heckBox.setText ( "Cavity Filling" );
contentPane.add ( cavityFillingJC heckBox );

// set up cavityFillingPr iceJLabel
cavityFillingPr iceJLabel = new JLabel();
cavityFillingPr iceJLabel.setBo unds( 211, 144, 38, 24 );
cavityFillingPr iceJLabel.setTe xt( "$150" );
cavityFillingPr iceJLabel.setHo rizontalAlignme nt(
JLabel.RIGHT );
contentPane.add ( cavityFillingPr iceJLabel );

// set up xRayJCheckBox
xRayJCheckBox = new JCheckBox();
xRayJCheckBox.s etBounds( 16, 178, 140, 24 );
xRayJCheckBox.s etText( "X-Ray" );
contentPane.add ( xRayJCheckBox );

// set up xRayPriceJLabel
xRayPriceJLabel = new JLabel();
xRayPriceJLabel .setBounds( 211, 178, 38, 24 );
xRayPriceJLabel .setText( "$85" );
xRayPriceJLabel .setHorizontalA lignment( JLabel.RIGHT );
contentPane.add ( xRayPriceJLabel );

// set up fluorideJCheckB ox
fluorideJCheckB ox = new JCheckBox();// Line 127
fluorideJCheckB ox.setBounds(16 ,210,140,24);
fluorideJCheckB ox.setText( "Fluoride" );
contentPane.add ( fluorideJCheckB ox );

// set up fluoridePriceJL abel
fluoridePriceJL abel = new JLabel();
fluoridePriceJL abel.setBounds( 211, 210, 38, 24 );//Line 134
fluoridePriceJL abel.setText("$ 50");
fluoridePriceJL abel.setHorizon talAlignment( JLabel.RIGHT );
contentPane.add ( fluoridePriceJL abel );

// set up rootCanalJCheck Box
rootCanalJCheck Box = new JCheckBox();//Line 140
rootCanalJCheck Box.setBounds(1 6,242,140,24);
rootCanalJCheck Box.setText("Ro ot Canal");
contentPane.add ( rootCanalJCheck Box );

// set up rootCanalPriceJ Label
rootCanalPriceJ Label = new JLabel();
rootCanalPriceJ Label.setBounds ( 211, 242, 38, 24 );//Line 148
rootCanalPriceJ Label.setText(" $225");
rootCanalPriceJ Label.setHorizo ntalAlignment( JLabel.RIGHT );
contentPane.add ( rootCanalPriceJ Label );

// set up otherJCheckBox
otherJCheckBox = new JCheckBox();//line 153
otherJCheckBox. setBounds(16,27 4,140,24);
otherJCheckBox. setText("Other" );
contentPane.add ( otherJCheckBox );

// set up otherPriceJLabe l
otherPriceJLabe l = new JLabel();//Line 159
otherPriceJLabe l .setBounds(206, 274,32,24);
otherPriceJLabe l .setText("$");
contentPane.add ( otherPriceJLabe l );

// set up otherPriceJText Field
otherPriceJText Field = new JTextField();//line 165
otherPriceJText Field.setBounds (214,274,34,24) ;
otherPriceJText Field.setHorizo ntalAlignment( JLabel.RIGHT );
contentPane.add ( otherPriceJText Field );

// set up totalJLabel
totalJLabel = new JLabel();
totalJLabel.set Bounds( 144, 314, 41, 21 );
totalJLabel.set Text( "Total:" );
contentPane.add ( totalJLabel );

// set up totalJTextField
totalJTextField = new JTextField();
totalJTextField .setBounds( 192, 314, 56, 21 );
totalJTextField .setEditable( false );
totalJTextField .setHorizontalA lignment( JTextField.CENT ER );
contentPane.add ( totalJTextField );

// set up calculateJButto n
calculateJButto n = new JButton();
calculateJButto n.setBounds( 155, 346, 94, 24 );
calculateJButto n.setText( "Calculate" );
contentPane.add ( calculateJButto n );
calculateJButto n.addActionList ener(

new ActionListener( ) // anonymous inner class
{
// event handler called when user clicks calculateJButto n
public void actionPerformed ( ActionEvent event )
{
calculateJButto nActionPerforme d( event );
}

} // end anonymous inner class

); // end call to addActionListen er

// set properties of application's window
setTitle( "Dental Payment" ); // set title bar string
setSize( 272, 409 ); // set window size
setVisible( true ); // display window

} // end method createUserInter face

// calculate cost of patient's visit
private void calculateJButto nActionPerforme d( ActionEvent event )
{
// get patient's name
String patient = patientNameJTex tField.getText( );

// Line 216 display error message if no name entered or no box
selected
if ( ( patient.equals( "" ) ) ||
( !cleaningJCheck Box.isSelected( ) &&
!cavityFillingJ CheckBox.isSele cted() &&
!xRayJCheckBox. isSelected() ) )
{
// display error message
JOptionPane.sho wMessageDialog( null,
"Please enter a name and check at least one item.",
"Missing information", JOptionPane.WAR NING_MESSAGE );
}
else // otherwise, do calculations
{
double total = 0.0; // sum of all services provided

// if patient had a cleaning
if ( cleaningJCheckB ox.isSelected() )
{
total += 35; // add 35 to total
}

// if patient had cavity filled
if ( cavityFillingJC heckBox.isSelec ted() )
{
total += 150; // add 150 to total
}

// if patient had x-ray taken
if ( xRayJCheckBox.i sSelected() )
{
total += 85; // add 85 to total
}

// Line 252 if patient had fluoride cleaning
if ( fluorideJCheckB ox.isSelected() )
{
total += 50; // add 50 to total
}

// if patient had root canal
if ( rootCanalJCheck Box.isSelected( ) )
{
total += 225; // add 225 to total
}
// if patient had other service performed
if ( otherJCheckBox. isSelected() )
{
total += ; // add 50 to total ------ ###ERROR###
}
// specify display format
DecimalFormat dollars = new DecimalFormat( "$0.00" );

// display total
totalJTextField .setText( dollars.format( total ) );

} // end else

} // end method calculateJButto nActionPerforme d

// main method
public static void main( String[] args )
{
DentalPayment application = new DentalPayment() ;
application.set DefaultCloseOpe ration( JFrame.EXIT_ON_ CLOSE );

} // end method main

} // end class DentalPayment

Jul 17 '05 #1
0 1732

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2586
by: Ron | last post by:
I searched php.net last night for a payment function with no luck. Does anyone now if this exists? Want to pass in a loan amount, rate and term to return payment. Appreciate any leads. Thanks, Ron
2
2817
by: Karen | last post by:
I inserted this statement and it worked great for the customers that have no payment history, but for the customers that have a history and an open invoice, it still used today's date in the mix and came back with screwy math. For instance, a customer who actually has an average payment of 20 days and has an open invoice 12 days old was calculated at an average of 102 days.... I'm fuzzy, but not that fuzzy! How do I tell Access to only...
3
6705
by: cameron | last post by:
Hi I am new here in this forum: I am writing a C++ program to calculate a Montly Mortgage Payment where the loan amount is 200,000.00 with a 5.75% interest rate with a term of 30 years. My program compiles fine with no errors but my calculation is not working correctly, any suggestions would be great as this assignment is due on Monday: //******************************************************* //Program: Calculations Payments //Purpose: To...
3
1665
by: davidhumphrey70 | last post by:
Hi, I am in serious need of some help PLEASE? I have a 4 tables (April data, May data, June data and July data) with numerous fields. Each of the tables has its own "Passed for payment to date" field. In a query I am trying to calculate the "Total passed for payment" which will be the sum of the "Passed for payment" fields taken from
3
2173
by: Jano | last post by:
Hi - Happy New Year! I have a web-site which accepted paypal payment for membership. No-one's buying so I want to make it free. The page which inputs the member details into the database needs verification, and I want to bypass the verification, but I can't figure it out. Can anyone help. - I have pasted the script below. Many thanks, Jano <? include("header.php"); ?> <? // read the post from PayPal system and add 'cmd' $req =...
7
1534
by: Kawaka Ku | last post by:
I need help for my payment calculation. When I applied Rate Discount into the worksheet for calculate loan amortize, the looping in interest rate, monthly payment, and remain principal balance are not continue even I setup a loop like this: For loopIndexInteger = 0 To maximumInteger SheetObj.Cells(exRow, 2) = SheetObj.Cells.Item(exRow, 4).value * (prod3disd1 / 100) / 12 SheetObj.Cells(exRow, 3) = MonthlyPmt -...
13
2490
by: Wayne | last post by:
I have just experienced my first late paying client. By "late" I mean that the invoice is now almost 2 months overdue. I don't think that the client is maliciously withholding payment - rather there has been an unfortunate series of events which has delayed the payment. The bottom line for a small time developer is still the same however. I am confident that I will receive payment for the invoice eventually but it is now a case of "once...
1
2704
by: myemail.an | last post by:
Hi all, I am a novice to Access, and was wondering if I could get some help on a problem I can't solve. I have a database with customer payments, structured like this: customer code type of payment date of payment payment amount
6
3797
by: CFFAN | last post by:
when i testing sandbox for paypal i am getting this error..i used this code for this <form target="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick-subscriptions"> <input type="hidden" name="business" value="asha@digitalmesh.com "> <input type="hidden" name="item_name" value="Membership">
0
10257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10237
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10029
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7567
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5588
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4144
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 we have to send another system
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.