Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.text.DecimalFormat;
- public class Main
- {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- DecimalFormat df = new DecimalFormat("###,###.##");
- int numMen=0;
- int numSales=0;
- double temp, total=0, avg=0, max;
- System.out.print("How many Salesperson?: ");
- numMen = sc.nextInt();
- String[] names = new String[numMen];
- for(int i=0; i<numMen; i++){
- System.out.print("Enter the Salesperson name ["+(i+1)+"]: ");
- names[i] = sc.next();
- }
- System.out.print("\nSalesperson are:\n");
- for(int i=0; i<numMen; i++){
- System.out.println(names[i]);
- }
- System.out.print("\nEnter number of Sales amount you want to store: ");
- numSales = sc.nextInt();
- System.out.print("Enter the value of the Sales Amount:\n");
- double[] sales = new double[numSales];
- for(int j=0; j<numSales; j++){
- sales[j] = sc.nextDouble();
- }
- //Sorting the array to ascending order
- for (int i = 0; i < numSales; i++)
- {
- for (int j = i + 1; j < numSales; j++)
- {
- if (sales[i] > sales[j])
- {
- temp = sales[i];
- sales[i] = sales[j];
- sales[j] = temp;
- }
- }
- }
- System.out.print("\nSales Amount are the following:\n");
- for (int i = 0; i < numSales - 1; i++)
- {
- System.out.print(sales[i] + "\n");
- }
- System.out.print(sales[numSales - 1]);
- //To get the total amount of sales
- for(int x=0; x<numMen; x++){
- total+=sales[x];
- }
- System.out.print("\nSales Amount Total: "+df.format(total));
- //to get the Average of the value
- avg = total/numSales;
- System.out.print("\nAverage Sales: "+df.format(avg));
- //To get the Highest value
- max = sales[0];
- for(int a = 0; a < numSales; a++) {
- if(max < sales[a]) {
- max = sales[a];
- }
- }
- System.out.print("\nHighest Sales Amount: "+max);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment