-1

I'm trying to figure whats wrong with my code. When I compile it says variable checkfee might not have been initialized.

import javax.swing.JOptionPane;

public class BankCharge  {
    public static void main (String [] args) {
        int check, basefee;
        String temp;
        double checkfee; 
        double totalfee;
        basefee = 10;
        totalfee = checkfee + basefee;


        temp = JOptionPane.showInputDialog("Enter the number of checks");
        check = Integer.parseInt(temp);

        if (check < 20) {
            checkfee = .10 * check;
            JOptionPane.showMessageDialog(null, "Your amount for the month is " + totalfee);
        }
        if (check >= 20 && check <= 39) {
            checkfee = .08 * check;
            JOptionPane.showMessageDialog(null, "Your amount for the month is " + totalfee);
        }
        if (check >= 40 && check <= 59) {
            checkfee = .06 * check;
            JOptionPane.showMessageDialog(null, "Your amount for the month is " + totalfee);
        }
    }
}
toadzky
  • 3,806
  • 1
  • 15
  • 26

2 Answers2

1

Because the initialization of checkfee variable is always done in conditional stament (if), it's not guaranteed to be initialized.

Crazyjavahacking
  • 9,343
  • 2
  • 31
  • 40
0

This warning is not important. You can write double checkfee=0; to remove it. What do you do if check >60 ??