473,395 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Payment program question error??????

do
This is direction: Modifying the calculateJButtonActionPerformed 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
calculateJButtonActionPerformed

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 totalPriceJTextField with the format

"$0.00".

//Source Code

// Exercise 5 DentalPayment.java
// 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 dentalPaymentFormJLabel;

// JLabel and JTextField for patient name
private JLabel patientNameJLabel;
private JTextField patientNameJTextField;

// JCheckBox and JLabel for cleaning
private JCheckBox cleaningJCheckBox;
private JLabel cleaningPriceJLabel;

// JCheckBox and JLabel for cavity filling
private JCheckBox cavityFillingJCheckBox;
private JLabel cavityFillingPriceJLabel;

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

// JCheckBox and JLabel for fluoride
private JCheckBox fluorideJCheckBox;
private JLabel fluoridePriceJLabel;

// JCheckBox and JLabel for root canal
private JCheckBox rootCanalJCheckBox;
private JLabel rootCanalPriceJLabel;

// JCheckBox, JLabel and JTextField for other services
private JCheckBox otherJCheckBox;
private JLabel otherPriceJLabel;
private JTextField otherPriceJTextField;

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

// JButton to initiate calculation of fee
private JButton calculateJButton;

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

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

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

// set up dentalPaymentFormJLabel
dentalPaymentFormJLabel = new JLabel();
dentalPaymentFormJLabel.setBounds( 19, 19, 235, 28 );
dentalPaymentFormJLabel.setText( "Dental Payment Form" );
dentalPaymentFormJLabel.setFont(
new Font( "Default", Font.PLAIN, 22 ) );
dentalPaymentFormJLabel.setHorizontalAlignment(
JLabel.CENTER );
contentPane.add( dentalPaymentFormJLabel );

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

// set up patientNameJTextField
patientNameJTextField = new JTextField();
patientNameJTextField.setBounds( 132, 65, 117, 21 );
contentPane.add( patientNameJTextField );

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

// set up cleaningPriceJLabel
cleaningPriceJLabel = new JLabel();
cleaningPriceJLabel.setBounds( 211, 112, 38, 24 );
cleaningPriceJLabel.setText( "$35" );
cleaningPriceJLabel.setHorizontalAlignment( JLabel.RIGHT );
contentPane.add( cleaningPriceJLabel );

// set up cavityFillingJCheckBox
cavityFillingJCheckBox = new JCheckBox();
cavityFillingJCheckBox.setBounds( 16, 144, 140, 24 );
cavityFillingJCheckBox.setText( "Cavity Filling" );
contentPane.add( cavityFillingJCheckBox );

// set up cavityFillingPriceJLabel
cavityFillingPriceJLabel = new JLabel();
cavityFillingPriceJLabel.setBounds( 211, 144, 38, 24 );
cavityFillingPriceJLabel.setText( "$150" );
cavityFillingPriceJLabel.setHorizontalAlignment(
JLabel.RIGHT );
contentPane.add( cavityFillingPriceJLabel );

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

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

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

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

// set up rootCanalJCheckBox
rootCanalJCheckBox = new JCheckBox();//Line 140
rootCanalJCheckBox.setBounds(16,242,140,24);
rootCanalJCheckBox.setText("Root Canal");
contentPane.add( rootCanalJCheckBox );

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

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

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

// set up otherPriceJTextField
otherPriceJTextField = new JTextField();//line 165
otherPriceJTextField.setBounds(214,274,34,24);
otherPriceJTextField.setHorizontalAlignment( JLabel.RIGHT );
contentPane.add( otherPriceJTextField );

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

// set up totalJTextField
totalJTextField = new JTextField();
totalJTextField.setBounds( 192, 314, 56, 21 );
totalJTextField.setEditable( false );
totalJTextField.setHorizontalAlignment( JTextField.CENTER );
contentPane.add( totalJTextField );

// set up calculateJButton
calculateJButton = new JButton();
calculateJButton.setBounds( 155, 346, 94, 24 );
calculateJButton.setText( "Calculate" );
contentPane.add( calculateJButton );
calculateJButton.addActionListener(

new ActionListener() // anonymous inner class
{
// event handler called when user clicks calculateJButton
public void actionPerformed( ActionEvent event )
{
calculateJButtonActionPerformed( event );
}

} // end anonymous inner class

); // end call to addActionListener

// 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 createUserInterface

// calculate cost of patient's visit
private void calculateJButtonActionPerformed( ActionEvent event )
{
// get patient's name
String patient = patientNameJTextField.getText();

// Line 216 display error message if no name entered or no box
selected
if ( ( patient.equals( "" ) ) ||
( !cleaningJCheckBox.isSelected() &&
!cavityFillingJCheckBox.isSelected() &&
!xRayJCheckBox.isSelected() ) )
{
// display error message
JOptionPane.showMessageDialog( null,
"Please enter a name and check at least one item.",
"Missing information", JOptionPane.WARNING_MESSAGE );
}
else // otherwise, do calculations
{
double total = 0.0; // sum of all services provided

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

// if patient had cavity filled
if ( cavityFillingJCheckBox.isSelected() )
{
total += 150; // add 150 to total
}

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

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

// if patient had root canal
if ( rootCanalJCheckBox.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 calculateJButtonActionPerformed

// main method
public static void main( String[] args )
{
DentalPayment application = new DentalPayment();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

} // end method main

} // end class DentalPayment

Jul 17 '05 #1
0 1714

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

Similar topics

3
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. ...
2
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...
3
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...
3
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...
3
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...
7
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...
13
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...
1
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...
6
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
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...

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.