这个循环来修改基于字符串的arraylist的数字的arraylist是不起作用的

时间:2015-11-12 03:35:15

标签: arrays arraylist

因此,在我的程序中,您输入员工信息,您输入的薪水取决于您输入的名称。如果是暂时的,你可以输入他们每小时赚多少钱,如果是永久性的,你输入他们每年所做的。最后,你可以选择按工资排序,所以如果他们选择那个,那么我必须将临时每小时乘以一组数字(1920),以便将它转换为他们每年所做的数量。我尝试了这个,但我收到了消息 “表达式的类型必须是数组类型,但它解析为java.util.ArrayList” 和“表达式的类型必须是一个数组类型,但它解析为java.util.ArrayList”,我得到了第二个两次。

public static void main(String[] args)
  {
    Scanner in = new Scanner(System.in);
    String Continue = "y";
int Count = 0;
int SortingChoice;
ArrayList<String> Names       = new ArrayList<String>();
ArrayList<String> Department  = new ArrayList<String>();
ArrayList<String> Designation = new ArrayList<String>();
ArrayList<Float>  Salary      = new ArrayList<Float>();

//******************************************************//

do
{
   System.out.println("Enter Employee Name: ");
   String x = in.next();
   Names.add(x);

   System.out.println("Enter Employee Designation ('temporary or permanent'): ");
   String y = in.next();
   Designation.add(y);

   System.out.println("Enter Employee Department: ");
   String z = in.next();
   Department.add(z);

   System.out.println("Enter Employee Salary: ");
   float i = in.nextFloat();
   Salary.add(i);

   System.out.println("Do you wish to add another employee? ('y'/'n'): ");
   Continue = in.next();

   Count = Count + 1;
}
while(Continue.equals("y"));

//***********************************************************************//

System.out.println("Enter sorting Criterion Number: 1. Name, 2.Department, 3. Salary. ");
SortingChoice = in.nextInt();

if(SortingChoice == 1)
{
  Collections.sort(Names);
     for(int i=0; i<Names.size(); i++)
     {
        System.out.println(Names.get(i));
     }
}

if(SortingChoice == 2)
{
  Collections.sort(Department);
     for(int i=0; i<Department.size(); i++)
     {
        System.out.println(Department.get(i));
     }
}

if(SortingChoice == 3)
{
  for(int k=0; k<Salary.size(); k++)
  {
    if(Designation[k].equals("temporary"))
      {
         Salary[k] = Salary[k]*1920;
      }
  }


  Collections.sort(Salary);
     for(int i=0; i<Salary.size(); i++)
     {
        System.out.println(Salary.get(i));
     }
}
  }

如果if(SortingChoice == 3)

下的循环,我最担心的是什么

0 个答案:

没有答案