lundi 3 avril 2017

Java Tax & NI GUI Calculator

I'm trying to calculate a Tax and NI calculator. I managed to write the code for it but can't seem to get the GUI working. i have tried to implement many different examples but they seem to give out errors. I just want to keep it simple and i even tried message dialog and a normal GUI screen with a OK button

Code for Calculator: (User enters their income and it calculates the tax etc.)

package netincome;

import java.io.*;


public class NetIncome {

    int pan;
    String name;
    double taxableincome;
    double tax;
    double taxpermonth;
    double annualNIpayments;
    double NIpermonth;
    double netmonthlyincome;

    void input() throws IOException {
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.println("Enter taxable income:");
        taxableincome = Double.parseDouble(br.readLine());
    }

    void computeData() {
        if (taxableincome <= 11000) {
            tax = 0;
            taxpermonth = tax/12;
            annualNIpayments = 0 * 0.00;
            NIpermonth = annualNIpayments/12;
            netmonthlyincome = ((taxableincome - tax - annualNIpayments)/12);
        } else if (taxableincome > 11001 && taxableincome <= 43000) {
            tax = (taxableincome * 0.20);
            taxpermonth = tax / 12;
            annualNIpayments = taxableincome * 0.12;
            NIpermonth = annualNIpayments / 12.0;
            netmonthlyincome = ((taxableincome - tax - annualNIpayments)/12);
        } else if (taxableincome > 43001 && taxableincome <= 150000) {
            tax = (taxableincome * 0.40);
            taxpermonth = tax / 12.0;
            annualNIpayments = taxableincome * 0.02;
            NIpermonth = annualNIpayments / 12.0;
            netmonthlyincome = ((taxableincome - tax - annualNIpayments)/12);
        } else if (taxableincome > 150001) {
            tax = (taxableincome * 0.45);
            taxpermonth = tax / 12.0;
            annualNIpayments = taxableincome * 0.02;
            NIpermonth = annualNIpayments / 12.0;
            netmonthlyincome = ((taxableincome - tax - annualNIpayments)/12);
        }
    }

    void displayData() {
          
        System.out.println("Taxable Income =" + taxableincome);
        System.out.println("Annual Tax Paid =" + tax);
        System.out.println("Monthly Tax Paid ="+ taxpermonth);
        System.out.println("Annual NI =" + annualNIpayments);
        System.out.println("Monthly NI =" + NIpermonth);
        System.out.println("Net Monthly Income =" + netmonthlyincome);
       
    }

    public static void main(String args[]) throws IOException {
        NetIncome ob = new NetIncome();
        ob.input();
        ob.computeData();
        ob.displayData();
    }
}

For example i used this website to get the dialog but can't seem to make the if statement to work on it: Message Dialog Code

The other ones were a GUI screen. Thanks in advance. i know my code isn't amazing but i'm only a beginner.

Aucun commentaire:

Enregistrer un commentaire