【问题标题】:How to fix "Method in class cannot be applied to given types" error?如何修复“类中的方法不能应用于给定类型”错误?
【发布时间】:2016-10-19 23:00:20
【问题描述】:
class WageCalculator_1 {

    public static void main(String[] args) {
       WagecalculatorApp WageCalculatorObject = new WagecalculatorApp(); 
    }

    private double baseRate;
    private double overtimeMultiplier;
    private int hours;
    private int overtime;
    private int overtimeHours;
    private int wages;
    private String multi;

    Scanner keyboard = new Scanner(System.in);

    public WageCalculator_1(double baseRate, int hours) 
    {
       this(baseRate, 1.5, hours);
    }

    public WageCalculator_1(double baseRate, double overtimeMultiplier, int hours) {
       System.out.print("Enter your base rate: ");
       baseRate = keyboard.nextDouble();

       WageCalculatorObject.wagecalc(baseRate);
       System.out.print("Enter your hours: ");
       hours = keyboard.nextInt();

       WageCalculatorObject.wagecalc(hours);
       System.out.print("Would you like to enter an overtime multiplier (yes/no)? ");
       multi = keyboard.next();

       if (hours > 40) {  
           System.out.print("what is the overtime multiplier? ");
           overtimeMultiplier = keyboard.nextInt();
       } else if (hours <= 40) { 
           wages = (int) (hours * baseRate);
           overtimeMultiplier = 0;    
       } else {   
           wages = (int) (40 * baseRate);       
           overtimeHours = hours - 40;
           overtime = (int) (overtimeHours * ( 1.5 * baseRate));   
           wages += overtime;              
       }   
    }
}

我在使用 WageCalculatorObject 时遇到问题。当我尝试使用它时,它一直给我这个错误。我一直在为此苦苦挣扎,不知道还能做什么。它给了我no error message

【问题讨论】:

  • Edit 你的帖子包含你遇到的实际错误,当你这样做时,让你的代码看起来好像你会为此感到自豪。
  • 我不知道该怎么做。我以前从未使用过这个网站。我有一个问题,因为我无法弄清楚。我解释了我在标题中遇到的确切错误,我不认为这有什么大不了的。
  • WageCalculatorObject 的代码是什么?工资计算器App?这里有多个课程,这真的让你想做什么感到困惑。您遇到什么错误?
  • 找不到什么符号?它在错误消息中。你在这里没有帮助任何人,尤其是你自己。
  • @Koryba 如果您以前从未使用过此网站,那么请做好准备,因为您没有提供足够的信息,您的每一个问题都会被投反对票。您很快就会了解到,其他人不可能在不投反对票的情况下提供建设性的反馈。

标签: java methods getter


【解决方案1】:

您没有 WageCalculatorApp 对象。具体来说,除非您提供更多代码,否则在初始化 WageCalculatorObject 对象时,您永远不会调用它,因此您调用的任何方法都不会返回任何内容,因为什么都不存在(当然,除非您没有显示 WageCalculatorApp 的代码)。除非您创建 WageCalculatorApp 对象,否则无法从中返回任何内容,因为它不存在。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-21
    • 2019-09-30
    • 2018-07-18
    相关资源
    最近更新 更多