Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Hi can you help

  1. #1
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question 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€;
        
    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 BasePremiumCalculatedPremiumLicenseDiscountNoClaimsDiscountSexDiscountTotalDiscountAdditionalChargeCarValueCarValueCharge;
        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(100100580520);
            
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            
    frame.getContentPane().setLayout(null);

            
    tabbedPane = new JTabbedPane(JTabbedPane.TOP);
            
    tabbedPane.setBounds(00570482);
            
    frame.getContentPane().add(tabbedPane);

            
    Mainpanel = new JPanel();
            
    Mainpanel.setBackground(SystemColor.textHighlight);
            
    tabbedPane.addTab("Car Insurance"nullMainpanelnull);
            
    Mainpanel.setLayout(null);

            
    lblEnterYourName = new JLabel("Enter Your Name:");
            
    lblEnterYourName.setBounds(107410014);
            
    Mainpanel.add(lblEnterYourName);

            
    textFieldName = new JTextField();
            
    textFieldName.addKeyListener(new TextFieldNameKeyListener());
            
    textFieldName.setBounds(1207131120);
            
    Mainpanel.add(textFieldName);
            
    textFieldName.setColumns(10);

            
    lblYourAge = new JLabel("Your Age:");
            
    lblYourAge.setBounds(1012510014);
            
    Mainpanel.add(lblYourAge);

            
    textFieldAge = new JTextField();
            
    textFieldAge.addKeyListener(new TextFieldAgeKeyListener());
            
            
    textFieldAge.setBounds(13212210517);
            
    Mainpanel.add(textFieldAge);
            
    textFieldAge.setColumns(10);

            
    lblGender = new JLabel("Gender:");
            
    lblGender.setBounds(101674614);
            
    Mainpanel.add(lblGender);

            
    rdbtnMale = new JRadioButton("Male");
            
    buttonGroupGender.add(rdbtnMale);
            
    rdbtnMale.setBounds(13215810923);
            
    Mainpanel.add(rdbtnMale);

            
    rdbtnFemale = new JRadioButton("Female");
            
    buttonGroupGender.add(rdbtnFemale);
            
    rdbtnFemale.setBounds(26515810923);
            
    Mainpanel.add(rdbtnFemale);

            
    lblNoClaimsBonus = new JLabel("No Claims Bonus:");
            
    lblNoClaimsBonus.setBounds(1021310014);
            
    Mainpanel.add(lblNoClaimsBonus);

            
    comboBoxNoclaims = new JComboBox();
            
    comboBoxNoclaims.addActionListener(new ComboBoxNoclaimsActionListener());
            
    comboBoxNoclaims.setBounds(13219813229);
            
    comboBoxNoclaims.setModel(new DefaultComboBoxModel(new String[] {
                    
    "None""1Year""2Years""3Years""4Years""5Years+" }));
            
    Mainpanel.add(comboBoxNoclaims);

            
    lblLicenceType = new JLabel("Licence Type:");
            
    lblLicenceType.setBounds(2892138514);
            
    Mainpanel.add(lblLicenceType);

            
    comboBoxLicence = new JComboBox();
            
    comboBoxLicence.addActionListener(new ComboBoxLicenceActionListener());
        
            
    comboBoxLicence.setBounds(39019812529);
            
    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(1026810014);
            
    Mainpanel.add(lblWhereYouLive);

            
    comboBoxArea = new JComboBox();
            
    comboBoxArea.setBounds(13225313229);
            
    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(28926810014);
            
    Mainpanel.add(lblCarEngineSize);

            
    comboBoxEngine = new JComboBox();
            
    comboBoxEngine.setBounds(39025312529);
            
    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(103138514);
            
    Mainpanel.add(lblCarValue);

            
    textFieldValue = new JTextField();
            
    textFieldValue.setBounds(24131013220);
            
    Mainpanel.add(textFieldValue);
            
    textFieldValue.setColumns(10);

            
    labelValue = new JLabel("\u20AC");
            
    labelValue.setBounds(2073132514);
            
    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(1036650523);
            
    Mainpanel.add(chckbxTickToConfirm);

            
    btnGetQuote = new JButton("Get Quote");
            
    btnGetQuote.addActionListener(new BtnGetQuoteActionListener());
            
    btnGetQuote.setBackground(Color.WHITE);
            
    btnGetQuote.setBounds(104088923);
            
    Mainpanel.add(btnGetQuote);

            
    lblNewLabel = new JLabel("                        Car Insurance:");
            
    lblNewLabel.setFont(new Font("Tahoma"Font.BOLD25));
            
    lblNewLabel.setBounds(102344820);
            
    Mainpanel.add(lblNewLabel);

            
    laberror = new JLabel("");
            
    laberror.setBounds(24712521423);
            
    Mainpanel.add(laberror);

            
    labelLetter = new JLabel("");
            
    labelLetter.setBounds(1179725714);
            
    Mainpanel.add(labelLetter);
            
            
    GenderError = new JLabel("");
            
    GenderError.setBounds(38516117020);
            
    Mainpanel.add(GenderError);

            
    Homepanel = new JPanel();
            
    Homepanel.setBackground(Color.GREEN);
            
    tabbedPane.addTab("HomeInsurance"nullHomepanelnull);
            
    Homepanel.setLayout(null);

            
    lblInsuranceCoverFor = new JLabel("Insurance cover for: ");
            
    lblInsuranceCoverFor.setBounds(103912320);
            
    Homepanel.add(lblInsuranceCoverFor);

            
    comboBoxCover = new JComboBox();
            
    comboBoxCover.setModel(new DefaultComboBoxModel(new String[] { "House",
                    
    "Appartments""Flat""Studio Flat" }));
            
    comboBoxCover.setBounds(1783916020);
            
    Homepanel.add(comboBoxCover);

            
    lblPeriodOfThe = new JLabel("Period of the Insurance:");
            
    lblPeriodOfThe.setBounds(108713720);
            
    Homepanel.add(lblPeriodOfThe);

            
    comboBoxPeriod = new JComboBox();
            
    comboBoxPeriod.setModel(new DefaultComboBoxModel(new String[] {
                    
    "3Monts""6Months""12Months""18Months""24Months" }));
            
    comboBoxPeriod.setBounds(1788716020);
            
    Homepanel.add(comboBoxPeriod);

            
    lblEstimate = new JLabel("\r\nEstimate Cost");
            
    lblEstimate.setBounds(1014211114);
            
    Homepanel.add(lblEstimate);

            
    lblIsTheProperty = new JLabel("Is the property fitted  alarm?");
            
    lblIsTheProperty.setBounds(1019115414);
            
    Homepanel.add(lblIsTheProperty);

            
    lblIsThisPolicy = new JLabel("Is this house in joint names?");
            
    lblIsThisPolicy.setBounds(1025615420);
            
    Homepanel.add(lblIsThisPolicy);

            
    rdbtnYes = new JRadioButton("Yes");
            
    buttonGroupJointNames.add(rdbtnYes);
            
    rdbtnYes.setBounds(1782558623);
            
    Homepanel.add(rdbtnYes);

            
    rdbtnNo = new JRadioButton("No");
            
    buttonGroupJointNames.add(rdbtnNo);
            
    rdbtnNo.setBounds(2962559423);
            
    Homepanel.add(rdbtnNo);

            
    chckbxTickToConfirm_1 = new JCheckBox(
                    
    "Tick to confirm you agree with the quote Assumptions & accept the Terms of Business ");
            
    chckbxTickToConfirm_1.setBounds(1032548523);
            
    Homepanel.add(chckbxTickToConfirm_1);

            
    btnGetQuote_1 = new JButton("Get Quote");
            
    // btnGetQuote_1.addActionListener(new BtnGetQuote_1ActionListener());
            
    btnGetQuote_1.setBounds(103868923);
            
    Homepanel.add(btnGetQuote_1);

            
    label€ = new JLabel("\u20AC");
            
    label€.setBounds(178, 142, 22, 14);
            
    Homepanel.add(label€);

            
    textFieldCost = new JTextField();
            
    textFieldCost.setBounds(21013912820);
            
    Homepanel.add(textFieldCost);
            
    textFieldCost.setColumns(10);

            
    rdbtnYes_1 = new JRadioButton("Yes");
            
    buttonGroupAlarm.add(rdbtnYes_1);
            
    rdbtnYes_1.setBounds(17818710923);
            
    Homepanel.add(rdbtnYes_1);

            
    rdbtnNo_1 = new JRadioButton("No");
            
    buttonGroupAlarm.add(rdbtnNo_1);
            
    rdbtnNo_1.setBounds(29618710923);
            
    Homepanel.add(rdbtnNo_1);

            
    lblHomeInsurance = new JLabel("                       Home Insurance:");
            
    lblHomeInsurance.setFont(new Font("Tahoma"Font.BOLD25));
            
    lblHomeInsurance.setBounds(10844820);
            
    Homepanel.add(lblHomeInsurance);
            
                    
    Displaypanel = new JPanel();
                    
    Displaypanel.setBounds(00563482);
                    
    frame.getContentPane().add(Displaypanel);
                    
    Displaypanel.setLayout(null);
                    
                            
    textAreaDisplay = new JTextArea();
                            
    textAreaDisplay.setBounds(2266513319);
                            
    Displaypanel.add(textAreaDisplay);
                            
                                    
    btnReturn = new JButton("Return");
                                    
    btnReturn.addActionListener(new BtnReturnActionListener());
                                    
    btnReturn.setBounds(223968923);
                                    
    Displaypanel.add(btnReturn);

        }

        public static 
    JRadioButton getSelected(ButtonGroup group) {
            for (
    Enumeration e group.getElements(); e.hasMoreElements();) {
                
    JRadioButton b = (JRadioButtone.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.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 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?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •