Closed. This question is not reproducible or was caused by typos。它当前不接受答案。
                            
                        
                    
                
            
                    
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        5年前关闭。
                    
                
        

所以我想做的是用ArrayLists创建食物菜单。我的任务是完成静态方法利润的以下定义,该方法输入MenuItems的ArrayList项并返回双精度数组。输出中的每个条目都是价格和项目相应元素成本之间的差。我必须使用静态方法roundMoney处理涉及金钱的每个计算的结果。

    public class MenuItem
    {
      private String myName;

      private double myPrice,
                     myCost;

      private int    myCode;

      private boolean myAvailability;

      public MenuItem( String name, double price, double cost, int code, boolean available )
      {
        myName = name;
        myPrice = price;
        myCost = cost;
        myCode = code;
        myAvailability = available;
      }

      public String getName() { return myName; }
      public double getPrice() { return myPrice; }
      public double getCost() { return myCost; }
      public int getCode() { return myCode; }
      public boolean available() { return myAvailability; }


      public String menuString()
        {
            return getName() + " ($" + getPrice() + ")";
        }


      public static double roundMoney( double amount )
      {
        return (int)(100 * amount + 0.5) / 100.0;
      }

      public static String printAmount( double d )
      {
        String s = "" + d;
        int k = s.indexOf( "." );
        if ( k < 0 )
          return s + ".00";
        if ( k + 1 == s.length() )
          return s + "00";
        if ( k + 2 == s.length() )
          return s + "0";
        else
          return s;
      }
    }
       //***********************************************************************
    public static double[] Profits(ArrayList<MenuItem> items)
    {
        double[] profits = new double[items.size()];
        for (int i = 0; i < profits.length; i++)
         {
            profits[i] = roundMoney (items.get(i).getPrice() - items.get(i).getCost());
         }
        return profits;
    }
     //***********************************************************************
public static void main( String[] args )
{
    ArrayList<MenuItem> items1 = new ArrayList<MenuItem>();
    items1.add( new MenuItem("Stir Fry",5.43,0.45,1,true) );
    items1.add( new MenuItem("Nachos",3.49,0.15,0,false) );
    items1.add( new MenuItem("Mud Pie",6.50,1.25,2,true) );
    items1.add( new MenuItem("Jerk Chicken",8.99,3.20,1,false) );

    double[] t = profits( items1 );

    for ( double d : t )
      System.out.print( printAmount( d ) + " " );
}


我的预期结果是:4.98 3.34 5.25 5.79,但我不断收到错误:TC1.java:30:错误:找不到符号

double [] t =利润(items1);
有人可以帮我找出问题所在吗?谢谢!

最佳答案

您用大写字母“ P”定义函数profits

public static double[] Profits(ArrayList<MenuItem> items)


更改带有错误的行以匹配函数的名称:

double[] t = Profits( items1 );

09-10 07:13
查看更多