方法参数不匹配:必须为double,未传递任何参数 [英] Method parameter mismatch: Required double, no argument passed

查看:162
本文介绍了方法参数不匹配:必须为double,未传递任何参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我几乎完成了,但是在编译时出现错误类IncomeTax中的方法getUserTax无法应用于给定类型;必需为double;发现:无自变量;原因:实际和正式自变量列表的长度不同"多次检查了我的代码,而我找不到错误所在的位置.它位于"userTax = test.getUserTax();

I am almost complete but when I compile I get the error "Method getUserTax in class IncomeTax cannot be applied to given types; required double; found: no arguments; reason: actual and formal argument lists differ in length" I've gone over my code multiple times and I cannot find where the error is located. It is near the end of the code on the line "userTax = test.getUserTax();

import java.util.Scanner;  //Needed for the Scanner Class
/**
 * Write a description of class IncomeTax here.
 * 
 * @author CD
 * 11/30/2012
 * The IncomeTax class determines how much tax you owe based on taxable income.
 */
public class IncomeTax
{
    private int income;

    /** 
     * The constructor accepts an argument for the income field.
     */
    public IncomeTax(int i)
    {
        income = i;
    }
    /**
    * The setIncome method accepts an argument for the income field.
    */
    public void SetIncome(int i)
    {
        income = i;
    }
    /**
     * The getIncome method returns the income field.
     */
    public double getIncome()
    {
        return income;
    }
    /**
     * The getUserTax returns the tax for the income.
     */
    public static double getUserTax(double income)
    {
        double userTax = 0.10;
        if (income > 250000.0) {
            userTax = 0.35;
        } else if(income > 130000.0) {
            userTax = 0.33;
        } else if(income > 60000.0) {
            userTax = 0.28;
        } else if(income > 30000.0) {
            userTax = 0.25;
        } else if(income > 10000.0) {
            userTax = 0.15;
        }
    return userTax;
}
/**
 * This program uses the IncomeTax class to determine the Income tax for the user's 
income.
 */
public static void main(String [] args)
{
    int userIncome; //To hold taxable income
    double userTax; //To hold tax

    //Create a Scanner object to read input.
    Scanner keyboard = new Scanner(System.in);

    //Get the Personal Income.
    System.out.print("Enter your taxable income and" + "I will tell you the income tax:");
    userIncome = keyboard.nextInt();

    //Create an IncomeTax object with the numeric score.
    IncomeTax test = new IncomeTax(userIncome);

    //Get the income tax.
    userTax = test.getUserTax();

    //Display the income tax.
    System.out.print("Your income tax is" + test.getUserTax());
}

推荐答案

userTax = test.getUserTax();

您需要将double值作为参数传递给此调用.您将getUserTax方法定义为double类型参数.

You need to pass double value as parameter to this call. Your getUserTax method defined as double type parameter required.

public static double getUserTax(double income)

示例:

userTax = test.getUserTax(10.0);//此处仅以10.0为例.

userTax = test.getUserTax(10.0); //Here 10.0 is just for example.

这篇关于方法参数不匹配:必须为double,未传递任何参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆