Advertisement
Axmaq

Untitled

Nov 14th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.54 KB | None | 0 0
  1. /* TempAgency.cs
  2. * This application is used by a temporary work agency to
  3. * set projections for sales for new hires. The program enables the
  4. * user to input salesmen's names and expected sales goals.
  5. * The sales figure is placed in a two-dimensional array
  6. * and expected sales figures for four months are added.
  7. * These projections are based on increasing sales at
  8. * least 5% each month over the four-month period.
  9. * for testing purposes, four salesmen data are entered.
  10. */
  11.  
  12. using System;
  13. using System.Collections.Generic;
  14. namespace TempAgency
  15. {
  16.     public class TempAgency
  17.     {
  18.         public static void Main(string[] args)
  19.         {
  20.             double[ , ] sales = new double[4,5];
  21.             string[ ] salesman = new string[4];
  22.            
  23.             DisplayInstructions();
  24.             GetSalesData(salesman, sales);
  25.             ProduceSalesProjectionTable(sales);
  26.             DisplaySalesProjections(salesman, sales);
  27.             Console.ReadKey();
  28.         }
  29.        
  30.         public static void DisplayInstructions()
  31.         {
  32.             Console.WriteLine("You will be asked to enter data for " +
  33.                                 "four salesmen. \nFor their name, " +
  34.                                 "enter their first " +
  35.                                 "name followed \nby a space and then " +
  36.                                 "their last name." +
  37.                                 "\n\nNext you will enter the " +
  38.                                 "expected sales for the 1st month." +
  39.                                 "\n\n\nFor testing purposes enter " +
  40.                                 "data for four (4) salesmen.\n\n");
  41.             Console.WriteLine();
  42.         }
  43.        
  44.             public static void GetSalesData(string [ ] salesman,
  45.                                             double[ , ] sales)
  46.             {
  47.                 for (int row = 0; row < salesman.Length; row++)
  48.                 {
  49.                     string fullname;
  50.                     string[ ] name = new string[3];
  51.                     Console.Write("Name of the New Salesman: ");
  52.                     salesman[row] = Console.ReadLine();
  53.                     fullname = salesman[row];
  54.                     name = fullname.Split(' ');
  55.                     Console.Write("Please enter {0}’s Initial Sales " +
  56.                     "Goal: ", name[0]);
  57.                     sales[row, 0] = double.Parse(Console.ReadLine());
  58.                     Console.Clear();
  59.                 }
  60.             }
  61.            
  62.             public static void ProduceSalesProjectionTable(double[ , ]
  63.             sales)
  64.             {
  65.                 double salesIncrease;
  66.                 DisplayHeading(sales);
  67.                 for (int row = 0; row < sales.GetLength(0); row++)
  68.                 {
  69.                     salesIncrease = 0.05;
  70.                     for (int col = 1; col < sales.GetLength(1); col++)
  71.                     {
  72.                         sales[row, col] = sales[row, col-1] *
  73.                         salesIncrease + sales[row, col-1];
  74.                         salesIncrease += 0.05;
  75.                     }
  76.                 }
  77.             }
  78.            
  79.             public static void DisplayHeading(double[ , ] sales)
  80.             {
  81.                 double inc = 0.05;
  82.                 Console.Write("{0,-20} {1,-10}", "Salesman",
  83.                 "Initial");
  84.                 for (int col = 0; col < sales.GetLength(1) - 1; col++)
  85.                 {
  86.                     Console.Write("{0,-6}{1,-1} ", "Month", col + 1);
  87.                 }
  88.             Console.WriteLine();
  89.             Console.Write("{0,-20} {1,-7}", " Name", " Sales ");
  90.             for (int col = 0; col < sales.GetLength(1) - 1; col++)
  91.             {
  92.                 Console.Write("{0, 8} ", inc.ToString("P0"));
  93.                 inc += 0.05;
  94.             }
  95.         Console.WriteLine();
  96.         }
  97.        
  98.         public static void DisplaySalesProjections(string[ ]
  99.                                         salesman, double[ , ] sales)
  100.             {
  101.                 string [ ] name = new string [3];
  102.                 Console.WriteLine();
  103.                 for (int row = 0; row < sales.GetLength(0); row++)
  104.                 {
  105.                     name = salesman[row].Split(' ');
  106.                     Console.Write("{0, -20}", (name[1] + "," + name[0]));
  107.                     for (int col = 0; col < sales.GetLength(1); col++)
  108.                     {
  109.                         Console.Write("{0, 11:N2}", sales[row, col] );
  110.                     }
  111.                 Console.WriteLine();
  112.                 }
  113.             }
  114.         }
  115.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement