Java中的ArrayList输入和输出

Java中的ArrayList输入和输出,java,Java,我有一个程序需要满足这些规范: •销售人员将继续获得每年50000.00美元的固定工资。目前每位销售人员的销售目标是每年120000.00美元。   •只有达到80%的销售目标,销售激励才会开始。目前的佣金占总销售额的7.5%。   •如果销售人员超过销售目标,佣金将根据加速系数增加。加速度系数为1.25。   •应用程序应要求用户输入年度销售额,并应显示年度薪酬总额。   •应用程序还应显示销售人员可能获得的潜在年度总薪酬表,以高于销售人员年度销售额5000美元的增量递增,直至达到销售人员年度

我有一个程序需要满足这些规范: •销售人员将继续获得每年50000.00美元的固定工资。目前每位销售人员的销售目标是每年120000.00美元。   •只有达到80%的销售目标,销售激励才会开始。目前的佣金占总销售额的7.5%。   •如果销售人员超过销售目标,佣金将根据加速系数增加。加速度系数为1.25。   •应用程序应要求用户输入年度销售额,并应显示年度薪酬总额。   •应用程序还应显示销售人员可能获得的潜在年度总薪酬表,以高于销售人员年度销售额5000美元的增量递增,直至达到销售人员年度销售额50%以上

• The application will now compare the total annual compensation of at least two salespersons.
 
• It will calculate the additional amount of sales that each salesperson must achieve to match or exceed the higher of the two earners.
 
• The application should ask for the name of each salesperson being compared. 
• The application should have at least one class, in addition to the application’s controlling class.
• The source code must demonstrate the use of conditional and looping structures.
• The source code must demonstrate the use of Array or ArrayList.
源代码中应该有适当的文档

我能够用while循环构造表。我现在的问题是数组或ArrayList。我用Salesperson类构建了一个ArrayList,但它并没有输出getName。我做错了什么?下面是我的代码

/*
 * Program: Salesperson.java
 * Written by: Amy Morin
 * This program will calculate total annual compensation for a salesperson.
 * Business requirements include:
 * Fixed salary = $50,000, sales target = $120,000,
 * sales incentive at 80% of sales,
 * Commission 7.5% of sales, if sales target is exceeded 1.25% increased 
 * accelorated factor.
 * This program will also be the foundation to
 * compare two or more salespersons.
 */

public class Salesperson
{   
    //Declares and initalizes fixed salary.
    private final double Fix_Sal = 50000;
    //Declares and initalizes commission.
    private final double Comm = 7.5;
    //Declares and initalizes acceleration factor.
    private final double Accel_Factor = 1.25;
    //Declares and initializes sales target.
    double target = 120000;         
    //Declares and initializes sales incentive threshold.
    double thresh = .80;

    String spName;    //holds the salesperson's name
    double annSales;   // Holds value for annual sales
    double commRate;  //holds calculated commission rate.  
    double commEarned;  //holds calculated commission earned.   
    double totalAnnComp; //Holds calculated total annual commission

    //Default Constructor
    public Salesperson()
    {
        spName = "Unknown";
        annSales = 0.0;
    }

    ////parameterized constructor
    public Salesperson(String name, double sales)
    {
        spName = name;
        annSales = sales;
    }

    //The setName method will set the name of salesperson
    public void setName(String name)
    {
        name = spName;
    }

    //The getName method will ruturn the name of salesperson
    public String getName()
    {
        return spName;
    }

    //The setSales method will set the annual sales
    public void setSales(double sales)
    {
        annSales = sales;
    }

    //The getSales method returns the value stored in annualSales
    public double getSales()
    {
        return annSales;
    }

    //The getComm method will calculate and return commission earned
    public double getComm()
    {
    //Check if sale are greater than or equal to 80% of target. 
    if (annSales >= (target * thresh))
    {
            if (annSales > target) //Checks if annual sales exceed target.
            {   
            //Gets commission rate.
                commRate = (Comm * Accel_Factor)/100;
        commEarned = commRate * annSales;
            }
            else
            {
        commRate = Comm/100;
        commEarned = commRate * annSales;
            }
    }
    else
        {
        commRate = 0;
        commEarned = 0;
    }
    return commEarned;
    }

    /*
     * The getAnnComp method will calculate and return the total 
     * annual compensation.
     */ 
    public double getAnnComp ()
    {
    totalAnnComp = Fix_Sal + commEarned;
    return totalAnnComp;
    }
}


/*
 * Program: SalespersonComparison
 * Written by: Amy Morin
 * This program will compare the total annual compensation 
 * of at least two salespersons. It will also calculate the additional 
 * amount of sales that each salesperson must achieve to match or 
 * exceed the higher of the two earners.
 */

import java.util.ArrayList; //Needed for ArrayList
import java.util.Scanner;  //Needed for Scanner class
import java.text.DecimalFormat; //Needed for Decimal formatting

public class SalespersonComparison
{
   public static void main(String[] args)
   {         
       final double Fix_Sal = 50000; //Declares and initiates fixed salary
       double sales; // hold annual sales

       //Create new ArrayList
       ArrayList<Salesperson> cArray = new ArrayList<>();

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

       //Lets user know how to end loop
       System.out.println("Press \'Enter\' to continue or type \'done\'"
               + " when finished.");

       //blank line
       System.out.println();

       //Loop for setting name and annual sales of salesperson
       do
       {   
           //Create an Salesperson object
           Salesperson sPerson = new Salesperson();

           //Set salesperson's name
           System.out.println("Enter salesperson name");
           String name = keyboard.nextLine();
           sPerson.setName(name);

           //End while loop
           if (name.equalsIgnoreCase("Done"))
               break;                     

           //Set annual sales for salesperson
           System.out.println("Enter annual sales for salesperson");
           sales = keyboard.nextDouble();
           sPerson.setSales(sales);          

           //To add Salesperson object to ArrayList
           cArray.add(sPerson);

           //Consume line
           keyboard.nextLine();     
       }
       while (true);

       //Display ArrayList

       DecimalFormat arrayL = new DecimalFormat("#,##0.00");
       for (int index = 0; index < cArray.size(); index++)
       {
           Salesperson sPerson = (Salesperson)cArray.get(index);
           System.out.println();
           System.out.print("Salesperson " + (index + 1) +
                            "\n Name: " + sPerson.getName() +
                            "\n Sales: " + (arrayL.format(sPerson.getSales())) +
                            "\n Commission Earned: " + 
                            (arrayL.format(sPerson.getComm())) +
                            "\n Total Annual Compensation: " 
                            + (arrayL.format(sPerson.getAnnComp())) + "\n\n");



       }
   }
}      

Output
Press 'Enter' to continue or type 'done' when finished.

Enter salesperson name
amy
Enter annual sales for salesperson
100000
Enter salesperson name
marty
Enter annual sales for salesperson
80000
Enter salesperson name
done

Salesperson 1
 Name: Unknown
 Sales: 100,000.00
 Commission Earned: 7,500.00
 Total Annual Compensation: 57,500.00


Salesperson 2
 Name: Unknown
 Sales: 80,000.00
 Commission Earned: 0.00
 Total Annual Compensation: 50,000.00

BUILD SUCCESSFUL (total time: 20 seconds)
/*
*程序:Salesperson.java
*作者:艾米·莫林
*该程序将计算销售人员的年度总薪酬。
*业务要求包括:
*固定工资=50000美元,销售目标=120000美元,
*80%销售额的销售激励,
*如果销售额增长超过1.25%,佣金为销售额的7.5%
*加速因子。
*这个程序也将是基础
*比较两个或两个以上的销售人员。
*/
公开课销售员
{   
//声明并初始化固定工资。
私人最终双重固定=50000;
//宣布并启动委员会。
专用最终双通信=7.5;
//声明并初始化加速因子。
私人最终双加速系数=1.25;
//声明并初始化销售目标。
双目标=120000;
//声明并初始化销售激励阈值。
双阈值=.80;
String spName;//保存销售人员的姓名
double annSales;//保存年度销售额的值
double commRate;//保存计算的佣金率。
double CommLearn;//保存计算所得的佣金。
double totalAnnComp;//保存计算的年度佣金总额
//默认构造函数
公共销售人员()
{
spName=“未知”;
平均销售额=0.0;
}
////参数化构造函数
公共销售人员(字符串名称,双重销售)
{
spName=名称;
销售=销售;
}
//setName方法将设置销售人员的姓名
公共void集合名(字符串名)
{
name=spName;
}
//getName方法将返回销售人员的姓名
公共字符串getName()
{
返回spName;
}
//setSales方法将设置年度销售额
公开销售(双倍销售)
{
销售=销售;
}
//getSales方法返回存储在annualSales中的值
公开销售()
{
退货和销售;
}
//getComm方法将计算并返回获得的佣金
公共双getComm()
{
//检查销售额是否大于或等于目标的80%。
如果(annSales>=(目标*thresh))
{
if(annSales>target)//检查年销售额是否超过目标。
{   
//收取佣金。
通信速率=(通信*加速系数)/100;
CommLearn=commRate*销售;
}
其他的
{
通信速率=通信/100;
CommLearn=commRate*销售;
}
}
其他的
{
commRate=0;
CommLearn=0;
}
返回已获得的信息;
}
/*
*getAnnComp方法将计算并返回总数
*年薪。
*/ 
公共双getAnnComp()
{
totalAnnComp=固定+通信;
返回totalAnnComp;
}
}
/*
*课程:销售人员比较
*作者:艾米·莫林
*该计划将比较年度薪酬总额
*至少有两名销售人员。它还将计算额外的成本
*每个销售人员必须达到的销售额,以匹配或
*超过两个收入者中较高的一个。
*/
导入java.util.ArrayList//ArrayList需要
导入java.util.Scanner//扫描器类需要
导入java.text.DecimalFormat//需要十进制格式
公共级销售人员比较
{
公共静态void main(字符串[]args)
{         
最终双倍固定工资=50000;//声明并启动固定工资
双重销售;//保持年度销售
//创建新的ArrayList
ArrayList cArray=新的ArrayList();
//创建扫描仪对象以读取输入。
扫描仪键盘=新扫描仪(System.in);
//让用户知道如何结束循环
System.out.println(“按“回车”继续或键入“完成”)
+“完成时。”);
//空行
System.out.println();
//用于设置销售人员姓名和年销售额的循环
做
{   
//创建Salesperson对象
Salesperson sPerson=新销售人员();
//设置销售人员的姓名
System.out.println(“输入销售人员姓名”);
字符串名称=keyboard.nextLine();
sPerson.setName(name);
//边结束边循环
if(name.equalsIgnoreCase(“完成”))
打破
//为销售人员设定年度销售额
System.out.println(“输入销售人员的年度销售额”);
sales=键盘.nextDouble();
销售人员(销售);
//将Salesperson对象添加到ArrayList的步骤
加上(斯佩森);
//消费线
keyboard.nextLine();
}
while(t
//The setName method will set the name of salesperson
public void setName(String name)
{
    name = spName;
}
//The setName method will set the name of salesperson
public void setName(String name)
{
    spName = name;
}
public void setName(String name) {
    name = spName;
}
public void setName(String name) {
    this.spName = name;
}