我是編程新手,希望對這個問題有所幫助:計算財務援助金額的計劃。如果家庭年收入在30000美元至40000美元之間,家庭至少有3個孩子,則每個孩子的收入爲1000美元。如果家庭年收入在20000美元至30000美元之間,家庭至少有3個孩子,則每個孩子的收入爲1500美元。如果家庭年收入低於20000美元,則每個孩子的收入爲2000美元。我必須實現一個方法並使用-1作爲標記值。這是我的計劃,到目前爲止財務援助計算器
public static void main(String[] args) {
// **METHOD** //
Scanner in = new Scanner(System.in);
System.out.println("What is the annual household income?");
double income = in.nextDouble();
System.out.println("How many children are in the household?");
int children = in.nextInt();
System.out.println("The financial assistance for this household is: "
+ assistance(income, children));
}
//**TEST PROGRAM**//
public static double assistance(double income, int children)
{
if(income >= 30000 && income < 40000 && children >= 3)
{
assistance = children * 1000; //says that it cannot find the symbol
}
else if(income >= 20000 && income < 30000 && children >= 2)
{
assistance = children * 1500;
}
else if(income < 20000)
{
assistance = children * 2000;
}
else
{
assistance = 0.0;
}
return assistance;
}
}
你在哪裏申報援助? –
我可以在哪裏申報援助?它會在if語句之前嗎? – DragonAge99
@ DragonAge99你有沒有爲方法和變量使用相同的名字? – amudhan3093