我正在学习使用数组,我很困惑如何让我的输出列出:人名和姓或只是他们在比较两个薪水的结尾的名字。截至目前,它使用一名员工的名字和姓氏,就好像他们是两名独立员工的名字一样。此外,这种编码或您看到的任何可以改进的内容是否有任何问题?请理解,我只在第4周学习Java。
package salesmanweek4;
import java.util.Scanner;
/**
*
* @author Big Werd
*/
public class SalesmanWeek4 extends Nameofsalesman {
public static void main(String[] args) {
String[] stringArray = {"",""};
double[] doubleArray;
doubleArray = new double[2];
// constructor to take keyboard input
Scanner keyboard = new Scanner(System.in);
//constructor to instantiate employees
Nameofsalesman compare = new Nameofsalesman();
// for loop to populate employeeArray
System.out.print("What is the first name of the employee?:");
compare.firstName = keyboard.next();
stringArray[0] = compare.firstName;
System.out.print ("What is the last name of the employee?");
compare.lastName = keyboard.next();
stringArray[0] = compare.lastName;
System.out.print("What was this employees total annual compensation?:");
compare.grossPay = keyboard.nextDouble();
doubleArray[0] = compare.grossPay;
System.out.print("What is the next employees first name?:");
compare.firstName = keyboard.next();
stringArray[1] = compare.firstName;
System.out.print ("What is the last name of the employee?");
compare.lastName = keyboard.next();
stringArray[1] = compare.lastName;
System.out.print("What was this employees total annual compensation?:");
compare.grossPay = keyboard.nextDouble();
doubleArray[1] = compare.grossPay;
double difference;
if (doubleArray[0] > doubleArray[1]){
difference = doubleArray[0] - doubleArray[1];
System.out.print( stringArray[0] + " Earned more compensation " + stringArray[1] + ".");
System.out.println("\n");
System.out.print( stringArray[1] + " will need to make more sales in the amount of " + difference );
}
else if ( doubleArray[0] < doubleArray[1]){
difference = doubleArray[1] - doubleArray[0];
System.out.println( stringArray[1] + " earned more than " + stringArray[0] + ".");
System.out.println( stringArray[0] + " will need to make more sales in the amount of " + difference );
}
else {
System.out.println(stringArray[0] + " wow, you both earned the same! " + stringArray[1] + ".");
}
}
}