Kulas_Code20

Untitled

Mar 28th, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.10 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.text.DecimalFormat;
  3. public class Main
  4. {
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.         DecimalFormat df = new DecimalFormat("###,###.##");
  8.         int numMen=0;
  9.         int numSales=0;
  10.         double temp, total=0, avg=0, max;
  11.        
  12.         System.out.print("How many Salesperson?: ");
  13.         numMen = sc.nextInt();
  14.         String[] names = new String[numMen];
  15.         for(int i=0; i<numMen; i++){
  16.             System.out.print("Enter the Salesperson name ["+(i+1)+"]: ");
  17.             names[i] = sc.next();
  18.         }
  19.         System.out.print("\nSalesperson are:\n");
  20.         for(int i=0; i<numMen; i++){
  21.             System.out.println(names[i]);
  22.         }
  23.        
  24.         System.out.print("\nEnter number of Sales amount you want to store: ");
  25.         numSales = sc.nextInt();
  26.         System.out.print("Enter the value of the Sales Amount:\n");
  27.         double[] sales = new double[numSales];
  28.         for(int j=0; j<numSales; j++){
  29.             sales[j] = sc.nextDouble();
  30.         }
  31.         //Sorting the array to ascending order
  32.         for (int i = 0; i < numSales; i++)
  33.         {
  34.             for (int j = i + 1; j < numSales; j++)
  35.             {
  36.                 if (sales[i] > sales[j])
  37.                 {
  38.                     temp = sales[i];
  39.                     sales[i] = sales[j];
  40.                     sales[j] = temp;
  41.                 }
  42.             }
  43.         }
  44.         System.out.print("\nSales Amount are the following:\n");
  45.         for (int i = 0; i < numSales - 1; i++)
  46.         {
  47.             System.out.print(sales[i] + "\n");
  48.         }
  49.         System.out.print(sales[numSales - 1]);
  50.        
  51.         //To get the total amount of sales
  52.         for(int x=0; x<numMen; x++){
  53.             total+=sales[x];
  54.         }
  55.        
  56.         System.out.print("\nSales Amount Total: "+df.format(total));
  57.         //to get the Average of the value
  58.         avg = total/numSales;
  59.         System.out.print("\nAverage Sales: "+df.format(avg));
  60.         //To get the Highest value
  61.         max = sales[0];
  62.         for(int a = 0; a < numSales; a++) {
  63.             if(max < sales[a]) {
  64.                 max = sales[a];
  65.             }
  66.         }
  67.         System.out.print("\nHighest Sales Amount: "+max);    
  68.     }
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment