我想計算稅和NI計算器。我設法爲它編寫代碼,但似乎無法使GUI工作。我試圖實現許多不同的例子,但他們似乎給出了錯誤。我只是想保持它的簡單,我甚至試圖消息對話框,並用OK按鈕,一個正常的GUI屏幕Java稅和NI GUI計算器
代碼計算器:(用戶輸入他們的收入,並計算出稅等)
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();
}
}
例如我用這個網站獲得的對話框,但似乎無法使if語句來進行這項工作:Message Dialog Code
其他的人是一個GUI畫面。 在此先感謝。 我知道我的代碼並不好,但我只是一個初學者。
請添加有關你得到了錯誤,什麼樣的結果你期待,因爲這是,你是在下降的細節:「爲什麼不是我的代碼工作?」 SO上的題外話題。 – Berger
關於GUI的具體內容不起作用?從您的所有代碼中都不能立即明白。 – Thunderforge