Ask coding questions

← Back to all posts
I am having problem to use array(in currencyconverter.java) for calcultaion
rafiurrahmanrah (2)

private void convertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_convertActionPerformed
{
if(from.getSelectedIndex()==0 || second.getSelectedIndex()==0 ||
third.getSelectedIndex()==0 || fourth.getSelectedIndex()==0
||fromtext.getText().equals(""))
JOptionPane.showMessageDialog(null,"You must select atleast two currency .One is from (from box) and another from other 4 box","Hakuna Matata",
JOptionPane.INFORMATION_MESSAGE);

    try
    {
        BufferedReader in = new BufferedReader(new FileReader(new File("Untitled Document 1.txt")));
        System.out.println("File open successful!");

        int line = 0;
        double[] tempArray2 = new double[300];
        String[] tempArray = new String[300];
        try {
            for (String x = in.readLine(); x != null; x = in.readLine())
            {
                String[] tokens = x.split("=");
line++;
tempArray[line] = tokens[0];
tempArray2[line] = Double.parseDouble(tokens[1]);

                
            }
        } catch (IOException ex) {
            Logger.getLogger(currencyconver.class.getName()).log(Level.SEVERE, null, ex);
        }
    double amountchange = Double.parseDouble(fromtext.getText());
    double amountpound =0.0;
    switch(from.getSelectedItem().toString()){
        case "USA": amountpound=amountchange/ tempArray2[4];
        break;
        case "Bangladesh": amountpound=amountchange/tempArray2[1];
        break;
        case "India": amountpound=amountchange/tempArray2[2];
        break;
        case "Pakistan": amountpound=amountchange/tempArray2[3];
        break;
        case "Europe": amountpound=amountchange/tempArray2[5];
Commentshotnewtop
Vandesm14 (2572)

Could you put your code into a repl? I can't really help you if it's just copy+pasted.