Enjoy an ad free experience by logging in. Not a member yet?
Register .
02-20-2013, 02:33 PM
PM User |
#1
New to the CF scene
Join Date: Feb 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Hi can you help
i am actualy struggling java swing windows builder i am trying to car Insurance which calculates insurance premium base on the driver age,Gender, No Claims,Licence type, Car Value,and Engine size and i have asked to hand over the program soon please help as iam not very familier with java i know this these not sound good but i don't what to do and i am stuck here as my program can't do the calculation that i want here it's any way i am also new to the site as this is my first time come in here, i would really appreciated if you could help me thank you for advance
here it's my program
PHP Code:
import java . awt . EventQueue ; public class MyProject { private JFrame frame ; private JTabbedPane tabbedPane ; private JPanel Mainpanel ; private JPanel Homepanel ; private JLabel lblEnterYourName ; private JTextField textFieldName ; private JLabel lblYourAge ; private JTextField textFieldAge ; private JLabel lblGender ; private JRadioButton rdbtnMale ; private JRadioButton rdbtnFemale ; private JLabel lblNoClaimsBonus ; private JComboBox comboBoxNoclaims ; private JLabel lblLicenceType ; private JComboBox comboBoxLicence ; private JLabel lblWhereYouLive ; private JComboBox comboBoxArea ; private JLabel lblCarEngineSize ; private JComboBox comboBoxEngine ; private JLabel lblCarValue ; private JTextField textFieldValue ; private JLabel labelValue ; private JCheckBox chckbxTickToConfirm ; private JButton btnGetQuote ; private JLabel lblInsuranceCoverFor ; private JComboBox comboBoxCover ; private JLabel lblPeriodOfThe ; private JComboBox comboBoxPeriod ; private JLabel lblEstimate ; private JLabel lblIsTheProperty ; private JLabel lblIsThisPolicy ; private JRadioButton rdbtnYes ; private JRadioButton rdbtnNo ; private JCheckBox chckbxTickToConfirm_1 ; private JButton btnGetQuote_1 ; private JLabel label & #8364;; private JTextField textFieldCost ; private JPanel Displaypanel ; private JTextArea textAreaDisplay ; private JButton btnReturn ; private JRadioButton rdbtnYes_1 ; private JRadioButton rdbtnNo_1 ; private ButtonGroup buttonGroupAlarm = new ButtonGroup (); private ButtonGroup buttonGroupJointNames = new ButtonGroup (); private ButtonGroup buttonGroupGender = new ButtonGroup (); private JLabel lblNewLabel ; private JLabel lblHomeInsurance ; private JLabel laberror ; private int num ; private JLabel labelLetter ; int age ; public double BasePremium , CalculatedPremium , LicenseDiscount , NoClaimsDiscount , SexDiscount , TotalDiscount , AdditionalCharge , CarValue , CarValueCharge ; private JLabel GenderError ; /** * Launch the application. */ public static void main ( String [] args ) { EventQueue . invokeLater (new Runnable () { public void run () { try { MyProject window = new MyProject (); window . frame . setVisible ( true ); } catch ( Exception e ) { e . printStackTrace (); } } }); } /** * Create the application. */ public MyProject () { initialize (); } /** * Initialize the contents of the frame. */ private void initialize () { frame = new JFrame (); frame . setBounds ( 100 , 100 , 580 , 520 ); frame . setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE ); frame . getContentPane (). setLayout ( null ); tabbedPane = new JTabbedPane ( JTabbedPane . TOP ); tabbedPane . setBounds ( 0 , 0 , 570 , 482 ); frame . getContentPane (). add ( tabbedPane ); Mainpanel = new JPanel (); Mainpanel . setBackground ( SystemColor . textHighlight ); tabbedPane . addTab ( "Car Insurance" , null , Mainpanel , null ); Mainpanel . setLayout ( null ); lblEnterYourName = new JLabel ( "Enter Your Name:" ); lblEnterYourName . setBounds ( 10 , 74 , 100 , 14 ); Mainpanel . add ( lblEnterYourName ); textFieldName = new JTextField (); textFieldName . addKeyListener (new TextFieldNameKeyListener ()); textFieldName . setBounds ( 120 , 71 , 311 , 20 ); Mainpanel . add ( textFieldName ); textFieldName . setColumns ( 10 ); lblYourAge = new JLabel ( "Your Age:" ); lblYourAge . setBounds ( 10 , 125 , 100 , 14 ); Mainpanel . add ( lblYourAge ); textFieldAge = new JTextField (); textFieldAge . addKeyListener (new TextFieldAgeKeyListener ()); textFieldAge . setBounds ( 132 , 122 , 105 , 17 ); Mainpanel . add ( textFieldAge ); textFieldAge . setColumns ( 10 ); lblGender = new JLabel ( "Gender:" ); lblGender . setBounds ( 10 , 167 , 46 , 14 ); Mainpanel . add ( lblGender ); rdbtnMale = new JRadioButton ( "Male" ); buttonGroupGender . add ( rdbtnMale ); rdbtnMale . setBounds ( 132 , 158 , 109 , 23 ); Mainpanel . add ( rdbtnMale ); rdbtnFemale = new JRadioButton ( "Female" ); buttonGroupGender . add ( rdbtnFemale ); rdbtnFemale . setBounds ( 265 , 158 , 109 , 23 ); Mainpanel . add ( rdbtnFemale ); lblNoClaimsBonus = new JLabel ( "No Claims Bonus:" ); lblNoClaimsBonus . setBounds ( 10 , 213 , 100 , 14 ); Mainpanel . add ( lblNoClaimsBonus ); comboBoxNoclaims = new JComboBox (); comboBoxNoclaims . addActionListener (new ComboBoxNoclaimsActionListener ()); comboBoxNoclaims . setBounds ( 132 , 198 , 132 , 29 ); comboBoxNoclaims . setModel (new DefaultComboBoxModel (new String [] { "None" , "1Year" , "2Years" , "3Years" , "4Years" , "5Years+" })); Mainpanel . add ( comboBoxNoclaims ); lblLicenceType = new JLabel ( "Licence Type:" ); lblLicenceType . setBounds ( 289 , 213 , 85 , 14 ); Mainpanel . add ( lblLicenceType ); comboBoxLicence = new JComboBox (); comboBoxLicence . addActionListener (new ComboBoxLicenceActionListener ()); comboBoxLicence . setBounds ( 390 , 198 , 125 , 29 ); comboBoxLicence . setModel (new DefaultComboBoxModel (new String [] { "Full Irish" , "Full UK" , "Full Eu" , "International" , "Provisional Irish " , "Provisional UK" })); Mainpanel . add ( comboBoxLicence ); lblWhereYouLive = new JLabel ( "Where You Live:" ); lblWhereYouLive . setBounds ( 10 , 268 , 100 , 14 ); Mainpanel . add ( lblWhereYouLive ); comboBoxArea = new JComboBox (); comboBoxArea . setBounds ( 132 , 253 , 132 , 29 ); comboBoxArea . setModel (new DefaultComboBoxModel (new String [] { "Co.Dublin" , "Co.Kildare" , "Co.Limerick" , "Co.Cork" , "Co.Sligo" , "Co.Wexford" , "Co.Tipparay" })); Mainpanel . add ( comboBoxArea ); lblCarEngineSize = new JLabel ( "Car Engine Size:" ); lblCarEngineSize . setBounds ( 289 , 268 , 100 , 14 ); Mainpanel . add ( lblCarEngineSize ); comboBoxEngine = new JComboBox (); comboBoxEngine . setBounds ( 390 , 253 , 125 , 29 ); comboBoxEngine . setModel (new DefaultComboBoxModel (new String [] { "1.0" , "1.1" , "1.2" , "1.3" , "1.4" , "1.5" , "1.6" , "1.8" })); Mainpanel . add ( comboBoxEngine ); lblCarValue = new JLabel ( "Car value:" ); lblCarValue . setBounds ( 10 , 313 , 85 , 14 ); Mainpanel . add ( lblCarValue ); textFieldValue = new JTextField (); textFieldValue . setBounds ( 241 , 310 , 132 , 20 ); Mainpanel . add ( textFieldValue ); textFieldValue . setColumns ( 10 ); labelValue = new JLabel ( "\u20AC" ); labelValue . setBounds ( 207 , 313 , 25 , 14 ); Mainpanel . add ( labelValue ); chckbxTickToConfirm = new JCheckBox ( "Tick to confirm you comply with the quote Assumptions& accept the Terms of Business" ); // chckbxTickToConfirm.addActionListener(new // ChckbxTickToConfirmActionListener()); chckbxTickToConfirm . setBackground ( SystemColor . textHighlight ); chckbxTickToConfirm . setBounds ( 10 , 366 , 505 , 23 ); Mainpanel . add ( chckbxTickToConfirm ); btnGetQuote = new JButton ( "Get Quote" ); btnGetQuote . addActionListener (new BtnGetQuoteActionListener ()); btnGetQuote . setBackground ( Color . WHITE ); btnGetQuote . setBounds ( 10 , 408 , 89 , 23 ); Mainpanel . add ( btnGetQuote ); lblNewLabel = new JLabel ( " Car Insurance:" ); lblNewLabel . setFont (new Font ( "Tahoma" , Font . BOLD , 25 )); lblNewLabel . setBounds ( 10 , 23 , 448 , 20 ); Mainpanel . add ( lblNewLabel ); laberror = new JLabel ( "" ); laberror . setBounds ( 247 , 125 , 214 , 23 ); Mainpanel . add ( laberror ); labelLetter = new JLabel ( "" ); labelLetter . setBounds ( 117 , 97 , 257 , 14 ); Mainpanel . add ( labelLetter ); GenderError = new JLabel ( "" ); GenderError . setBounds ( 385 , 161 , 170 , 20 ); Mainpanel . add ( GenderError ); Homepanel = new JPanel (); Homepanel . setBackground ( Color . GREEN ); tabbedPane . addTab ( "HomeInsurance" , null , Homepanel , null ); Homepanel . setLayout ( null ); lblInsuranceCoverFor = new JLabel ( "Insurance cover for: " ); lblInsuranceCoverFor . setBounds ( 10 , 39 , 123 , 20 ); Homepanel . add ( lblInsuranceCoverFor ); comboBoxCover = new JComboBox (); comboBoxCover . setModel (new DefaultComboBoxModel (new String [] { "House" , "Appartments" , "Flat" , "Studio Flat" })); comboBoxCover . setBounds ( 178 , 39 , 160 , 20 ); Homepanel . add ( comboBoxCover ); lblPeriodOfThe = new JLabel ( "Period of the Insurance:" ); lblPeriodOfThe . setBounds ( 10 , 87 , 137 , 20 ); Homepanel . add ( lblPeriodOfThe ); comboBoxPeriod = new JComboBox (); comboBoxPeriod . setModel (new DefaultComboBoxModel (new String [] { "3Monts" , "6Months" , "12Months" , "18Months" , "24Months" })); comboBoxPeriod . setBounds ( 178 , 87 , 160 , 20 ); Homepanel . add ( comboBoxPeriod ); lblEstimate = new JLabel ( "\r\nEstimate Cost" ); lblEstimate . setBounds ( 10 , 142 , 111 , 14 ); Homepanel . add ( lblEstimate ); lblIsTheProperty = new JLabel ( "Is the property fitted alarm?" ); lblIsTheProperty . setBounds ( 10 , 191 , 154 , 14 ); Homepanel . add ( lblIsTheProperty ); lblIsThisPolicy = new JLabel ( "Is this house in joint names?" ); lblIsThisPolicy . setBounds ( 10 , 256 , 154 , 20 ); Homepanel . add ( lblIsThisPolicy ); rdbtnYes = new JRadioButton ( "Yes" ); buttonGroupJointNames . add ( rdbtnYes ); rdbtnYes . setBounds ( 178 , 255 , 86 , 23 ); Homepanel . add ( rdbtnYes ); rdbtnNo = new JRadioButton ( "No" ); buttonGroupJointNames . add ( rdbtnNo ); rdbtnNo . setBounds ( 296 , 255 , 94 , 23 ); Homepanel . add ( rdbtnNo ); chckbxTickToConfirm_1 = new JCheckBox ( "Tick to confirm you agree with the quote Assumptions & accept the Terms of Business " ); chckbxTickToConfirm_1 . setBounds ( 10 , 325 , 485 , 23 ); Homepanel . add ( chckbxTickToConfirm_1 ); btnGetQuote_1 = new JButton ( "Get Quote" ); // btnGetQuote_1.addActionListener(new BtnGetQuote_1ActionListener()); btnGetQuote_1 . setBounds ( 10 , 386 , 89 , 23 ); Homepanel . add ( btnGetQuote_1 ); label & #8364; = new JLabel("\u20AC"); label & #8364;.setBounds(178, 142, 22, 14); Homepanel . add ( label & #8364;); textFieldCost = new JTextField (); textFieldCost . setBounds ( 210 , 139 , 128 , 20 ); Homepanel . add ( textFieldCost ); textFieldCost . setColumns ( 10 ); rdbtnYes_1 = new JRadioButton ( "Yes" ); buttonGroupAlarm . add ( rdbtnYes_1 ); rdbtnYes_1 . setBounds ( 178 , 187 , 109 , 23 ); Homepanel . add ( rdbtnYes_1 ); rdbtnNo_1 = new JRadioButton ( "No" ); buttonGroupAlarm . add ( rdbtnNo_1 ); rdbtnNo_1 . setBounds ( 296 , 187 , 109 , 23 ); Homepanel . add ( rdbtnNo_1 ); lblHomeInsurance = new JLabel ( " Home Insurance:" ); lblHomeInsurance . setFont (new Font ( "Tahoma" , Font . BOLD , 25 )); lblHomeInsurance . setBounds ( 10 , 8 , 448 , 20 ); Homepanel . add ( lblHomeInsurance ); Displaypanel = new JPanel (); Displaypanel . setBounds ( 0 , 0 , 563 , 482 ); frame . getContentPane (). add ( Displaypanel ); Displaypanel . setLayout ( null ); textAreaDisplay = new JTextArea (); textAreaDisplay . setBounds ( 22 , 66 , 513 , 319 ); Displaypanel . add ( textAreaDisplay ); btnReturn = new JButton ( "Return" ); btnReturn . addActionListener (new BtnReturnActionListener ()); btnReturn . setBounds ( 22 , 396 , 89 , 23 ); Displaypanel . add ( btnReturn ); } public static JRadioButton getSelected ( ButtonGroup group ) { for ( Enumeration e = group . getElements (); e . hasMoreElements ();) { JRadioButton b = ( JRadioButton ) e . nextElement (); if ( b . getModel () == group . getSelection ()) { return b ; } } return null ; } // this KeyListner prevents the users to input number instead of letter private class TextFieldNameKeyListener extends KeyAdapter { @ Override public void keyTyped ( KeyEvent KeyEvent ) { if ( KeyEvent . getKeyChar () >= '0' && KeyEvent . getKeyChar () <= '9' ) { KeyEvent . consume (); labelLetter . setText ( "you Must Enter letters" ); } else { super . keyTyped ( KeyEvent ); labelLetter . setText ( "" ); } } } // this KeyListner prevents the users to input Letters instead of Numbers private class TextFieldAgeKeyListener extends KeyAdapter { @ Override public void keyTyped ( KeyEvent KeyEvent ) { if ( KeyEvent . getKeyChar () >= '0' && KeyEvent . getKeyChar () >= '9' ) { // discard the key typed. KeyEvent . consume (); laberror . setText ( "You need to enter a number" ); } else { // performe action... super . keyTyped ( KeyEvent ); } if ( num >= 18 && num <= 70 ) { laberror . setText ( "" ); } else { if ( num <= 18 && num > 70 ) { laberror . setText ( "You must be between 18 to 70" ); } } } } private class BtnGetQuoteActionListener implements ActionListener { public void actionPerformed ( ActionEvent e ) { String Custumername = textFieldName . getText (); BasePremium = 700 ; tabbedPane . setVisible ( false ); Displaypanel . setVisible ( true ); double CarValue = Double . parseDouble ( textFieldValue . getText ()); int age = Integer . parseInt ( textFieldAge . getText ()); TotalDiscount = LicenseDiscount + NoClaimsDiscount + SexDiscount ; double CalculatedPremium ; DecimalFormat df = new DecimalFormat (); if(! rdbtnMale . isSelected () && ! rdbtnFemale . isSelected ()){ GenderError . setText ( "Please select your Gender" ); tabbedPane . setVisible ( true ); Displaypanel . setVisible ( false ); } if ( age < 20 || age >= 75 ) { textAreaDisplay . setText ( "Sorry, we can't insure you" ); } else { if( age >= 20 || age <= 29 ){ BasePremium =- 0.02 ; } else if( age >= 30 || age <= 44 ){ BasePremium = - 0.05 ; } else if ( age >= 45 ){ BasePremium = - 0.05 ; } if ( CarValue >= 4000 ) { BasePremium = - 0.05 ; } else if ( CarValue > 8000 ) { BasePremium = - 0.10 ; } CalculatedPremium = BasePremium + CarValueCharge - TotalDiscount ; textAreaDisplay . setText ( "" + CalculatedPremium ); } } } private class ComboBoxNoclaimsActionListener implements ActionListener { public void actionPerformed ( ActionEvent e ) { if ( comboBoxNoclaims . getSelectedIndex () <= 0 ) { NoClaimsDiscount = 0 ; }else if ( comboBoxNoclaims . getSelectedIndex () <= 1 ){ NoClaimsDiscount = BasePremium * .95 ; } else if ( comboBoxNoclaims . getSelectedIndex () <= 2 ){ NoClaimsDiscount = BasePremium * .90 ; } else if ( comboBoxNoclaims . getSelectedIndex () <= 3 ){ NoClaimsDiscount = BasePremium * .85 ; }else if ( comboBoxNoclaims . getSelectedIndex () <= 4 ){ NoClaimsDiscount = BasePremium * .80 ; } else if ( comboBoxNoclaims . getSelectedIndex () <= 5 ){ NoClaimsDiscount = BasePremium * .75 ; } } } private class ComboBoxLicenceActionListener implements ActionListener { public void actionPerformed ( ActionEvent e ) { if ( comboBoxLicence . getSelectedIndex () <= 0 ) { LicenseDiscount = BasePremium * .95 ; }else if ( comboBoxLicence . getSelectedIndex () <= 1 ){ LicenseDiscount = BasePremium * .95 ; } else if ( comboBoxLicence . getSelectedIndex () <= 2 ){ LicenseDiscount = BasePremium * .95 ; } else if ( comboBoxLicence . getSelectedIndex () <= 3 ){ LicenseDiscount = BasePremium + 0.07 ; }else if ( comboBoxLicence . getSelectedIndex () <= 4 ){ LicenseDiscount = BasePremium + 0.07 ; } } } private class BtnReturnActionListener implements ActionListener { public void actionPerformed ( ActionEvent arg0 ) { tabbedPane . setVisible ( true ); Displaypanel . setVisible ( false ); } } }
Last edited by Fou-Lu; 02-21-2013 at 01:53 PM ..
02-21-2013, 02:34 PM
PM User |
#2
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Make sure you wrap your code in [php][/php] or [code][/code] tags. Also, a more suitable subject title would be better.
So what is the actual problem you are having? What algorithm do you intend to use for the calculations?
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer:
http://php.net/manual/en/mysqlinfo.api.choosing.php
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 08:29 PM .
Advertisement
Log in to turn off these ads.