Java 如何修复程序中的编译错误?
我正在为学校编写一个Java程序来解决下面的问题。每次我试图编译程序时,它都会给我一些毫无意义的编译错误。如果有人能帮我找出问题所在,我将不胜感激 问题:一个非政府组织需要一个计划来计算对贫困家庭的经济援助金额。公式如下: --如果家庭年收入在30000美元至40000美元之间,并且家庭至少有三个孩子,则每个孩子的收入为1000美元 --如果家庭年收入在2万至3万美元之间,并且家庭至少有两个孩子,则每个孩子的收入为1500美元 --如果家庭年收入低于2万美元,则为每个儿童2000美元 实现此计算的方法。编写一个程序,询问每个申请人的家庭收入和子女人数,并打印您的方法返回的金额。使用-1作为输入的前哨值 我的节目:Java 如何修复程序中的编译错误?,java,Java,我正在为学校编写一个Java程序来解决下面的问题。每次我试图编译程序时,它都会给我一些毫无意义的编译错误。如果有人能帮我找出问题所在,我将不胜感激 问题:一个非政府组织需要一个计划来计算对贫困家庭的经济援助金额。公式如下: --如果家庭年收入在30000美元至40000美元之间,并且家庭至少有三个孩子,则每个孩子的收入为1000美元 --如果家庭年收入在2万至3万美元之间,并且家庭至少有两个孩子,则每个孩子的收入为1500美元 --如果家庭年收入低于2万美元,则为每个儿童2000美元 实现此计算
import java.util.Scanner;
/**
This program computes the financial assistance that a family
can receive based on their income and the number of children.
*/
public class FinancialAidCalc
{
public static void main(String[] args)
{
/** This declares the variables
for the main method.
*/
int income = 0;
int children = 0;
int financialAid = 0;
/** This creates the method to request
the household income amount.
@param income the amount of houshold income
that the user inputs
@return the household income
*/
public static int householdIncome(int income)
{
do
{
Scanner in = new Scanner(System.in);
System.out.print("Please enter the total household income. Enter -1 to quit.");
int income = in.nextInt();
}
while (income < -1);
if (income >= 0) {return income;}
if (income = -1) {return;}
}
}
/** This creates the method to request
the number of children in the household.
@param children the number of children
in the houshold that the user inputs
@return the number of children
*/
public static int noOfHouseholdChildren(int children)
{
do
{
Scanner in = new Scanner(System.in);
System.out.print("Please enter the total number of children in the household. Enter -1 to quit.");
int children = in.nextInt();
}
while (children < -1);
if (children >= 0) {return children;}
if (children = -1) {return;}
}
/** This method uses the returned results from the householdIncome and noOfHouseholdChildren
methods in order to calculate the amount of financial assistance
that a family will receive.
@param financialAid shows the amount of financial aid that the family is eligible for
*/
public static int availableFinancialAid(int income, int children)
{
/** This determines if the household income is between
$30,000 and $40,000 with at least 3 children.
*/
if (income.isBetween(30000, 40000) && children >= 3)
{
financialAid = (children * 1000);
System.out.println("Your household income is: $" + income);
System.out.println("You have " + children + " in your household.");
System.out.println("Your household is eligible for $" + financialAid + "in financial aid.");
}
/** This determines if the household income is between
$20,000 and $30,000 with at least 2 children.
*/
if (income.isBetween(20000, 30000) && children >= 2)
{
financialAid = (children * 1500);
System.out.println("Your household income is: $" + income);
System.out.println("You have " + children + " in your household.");
System.out.println("Your household is eligible for $" + financialAid + "in financial aid.");
}
/** This determines if the household income is less than $20,000..
*/
if (income < 20000)
{
financialAid = (children * 2000);
System.out.println("Your household income is: $" + income);
System.out.println("You have " + children + " in your household.");
System.out.println("Your household is eligible for $" + financialAid + "in financial aid.");
}
/** This advises the user that they do not qualify for
financial aid if the income is over $40,000.
*/
if (income > 40000)
{
System.out.print("You do not qualify for financial aid.");
}
}
}
import java.util.Scanner;
/**
该程序计算家庭获得的经济援助
可以根据自己的收入和子女人数领取。
*/
公共类财务会计
{
公共静态void main(字符串[]args)
{
/**这声明了变量
对于主要方法。
*/
国际收入=0;
int儿童=0;
int financialAid=0;
/**这将创建要请求的方法
家庭收入总额。
@参数收入应获得的收入金额
用户输入的
@返还家庭收入
*/
公共静态内部住户收入(内部收入)
{
做
{
扫描仪输入=新扫描仪(系统输入);
系统输出打印(“请输入家庭总收入,输入-1退出”);
int收入=in.nextInt();
}
而(收入<-1);
如果(收入>=0){返回收入;}
如果(收入=-1){return;}
}
}
/**这将创建要请求的方法
家庭中孩子的数量。
@param children子对象数
在用户输入的外壳中
@返回子对象的数量
*/
公共静态int noOfHouseholdChildren(int children)
{
做
{
扫描仪输入=新扫描仪(系统输入);
System.out.print(“请输入家庭中的儿童总数。输入-1表示退出”);
int children=in.nextInt();
}
儿童<-1岁;
如果(子项>=0){返回子项;}
if(children=-1){return;}
}
/**此方法使用householdIncome和noOfHouseholdChildren返回的结果
计算资助金额的方法
一个家庭将得到的。
@param financialAid显示家庭有资格获得的经济援助金额
*/
公共静态国际可用金融援助(国际收入、国际儿童)
{
/**这决定了家庭收入是否介于
3万美元和4万美元,至少有3个孩子。
*/
如果(收入介于(3000040000)和子女之间>=3)
{
financialAid=(儿童*1000);
System.out.println(“您的家庭收入为:$”+收入);
System.out.println(“你家里有“+孩子+”);
System.out.println(“您的家庭有资格获得$”+financialAid+“经济援助”);
}
/**这决定了家庭收入是否介于
2万美元和3万美元,至少有两个孩子。
*/
如果(收入介于(20000,30000)和子女之间>=2)
{
财政援助=(儿童*1500);
System.out.println(“您的家庭收入为:$”+收入);
System.out.println(“你家里有“+孩子+”);
System.out.println(“您的家庭有资格获得$”+financialAid+“经济援助”);
}
/**这决定了家庭收入是否低于20000美元。。
*/
如果(收入<20000)
{
财政援助=(儿童*2000);
System.out.println(“您的家庭收入为:$”+收入);
System.out.println(“你家里有“+孩子+”);
System.out.println(“您的家庭有资格获得$”+financialAid+“经济援助”);
}
/**这会告知用户,他们不符合
如果收入超过40000美元,则提供经济援助。
*/
如果(收入>40000)
{
System.out.print(“您没有资格获得经济援助”);
}
}
}
您试图在方法中声明方法。仔细看看主要的方法。您没有关闭该方法,但正在声明其他方法
似乎您想要创建一个类,然后通过main方法使用它。在这种情况下,您需要以下内容:
import java.util.Scanner;
public class FinancialAidCalc {
public static void main(String[] args) {
/* code */
}
static int income = 0;
static int children = 0;
static int financialAid = 0;
public static int householdIncome(int income) {
/* code */
}
public static int noOfHouseholdChildren(int children) {
/* code */
}
public static int availableFinancialAid(int income, int children) {
/* code */
}
}
您的代码中可能还有其他编译错误,但由于混乱,我没有仔细查看。您试图在方法中声明方法。仔细看看主要的方法。您没有关闭该方法,但正在声明其他方法 似乎您想要创建一个类,然后通过main方法使用它。在这种情况下,您需要以下内容:
import java.util.Scanner;
public class FinancialAidCalc {
public static void main(String[] args) {
/* code */
}
static int income = 0;
static int children = 0;
static int financialAid = 0;
public static int householdIncome(int income) {
/* code */
}
public static int noOfHouseholdChildren(int children) {
/* code */
}
public static int availableFinancialAid(int income, int children) {
/* code */
}
}
您的代码中可能还有其他编译错误,但由于混乱,我没有仔细查看。我看到这样的行 如果(收入=-1) 我不知道你是不是真的那么想。您可以在Java中使用条件语句进行赋值,但更可能的意思是: 如果(收入==-1) 单等号是赋值,而双等号是赋值