Tracking Sales - 很简单的一个java

来源:百度知道 编辑:UC知道 时间:2024/04/27 15:35:26
22号中午前的回答的答案才有效``过了22号11点半``就没用了``
在源文件的基础上写

The file contains a Java program that prompts for and reads in the sales for each of 5 salespeople in a company. It then prints out the ID and amount of sales for each salesperson and the total sales. Study the code, then compile and run the program to see how it works. Now modify the program as follows:
1.Compute and print the average sale.

2.Find and print the maximum sale. Print both the ID of the salesperson with the maximum sale and the amount of the sale, e.g., "Salesperson 3 had the highest sale with $4500."

3.Do the same for the minimum sale.

4.The salespeople object to having an ID of 0 — no one wants that designation. Modify your program so that the IDs run from 1-5 instead of 0-4. Do not modify the array — just make the information for salesperson 1 reside in array location 0, and so on (Hint: use subtraction).

5.Instead of always reading in 5 sales am

//不足之处 自己改改

import java.util.Arrays;
import java.util.Scanner;

public class TrackingSales {

static Scanner san = new Scanner(System.in);

public static void main(String[] args) {
System.out.print("Enter the numbers of salers: ");
int len = san.nextInt();
Saler[] sls = new Saler[len];
int sum = 0;
for(int i = 0; i < len; i ++) {
System.out.print("Input Saler " + (i + 1) + " 's sale amount($) : ");
int a = san.nextInt();
sls[i] = new Saler((i +1 ), a);
sum += a;
}
Arrays.sort(sls);
System.out.println("Salesperson " + sls[0].getId() + " had the highest sale with $" + sls[0].getSalNum());
System.out.println("Salesperson " + sls[sls.length -1].getId() + " had the lowest sale with $" + sls[sls.length -1].getSalNum());
System.out.printf("average is $" +