AlphaPenguino

ICTN05C

Sep 20th, 2024
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.20 KB | None | 0 0
  1. using System;
  2. using System.ComponentModel;
  3. using System.Reflection.Emit;
  4.  
  5. public class Employee
  6. {
  7.     public String name;
  8.     public double hourlyWage;
  9.     public double hoursPerDay;
  10.     public double daysPerMonth;
  11.  
  12.     public Employee(String name, double hourlyWage, double hoursPerDay, double daysPerMonth)
  13.     {
  14.         this.name = name;
  15.         this.hourlyWage = hourlyWage;
  16.         this.hoursPerDay = hoursPerDay;
  17.         this.daysPerMonth = daysPerMonth;
  18.     }
  19.     public double CalculateMonthlySalary()
  20.     {
  21.         return (hourlyWage * hoursPerDay) * daysPerMonth;
  22.     }
  23.     public double CalculateAnnualSalary()
  24.     {
  25.         return ((hourlyWage * hoursPerDay) * daysPerMonth) * 12;
  26.     }
  27.     public void DisplayInfo()
  28.     {
  29.         Console.WriteLine($"------------------------------\nEmployee Name: {name}");
  30.         Console.WriteLine($"Hourly Wage: {hourlyWage}\nHours Per Day: {hoursPerDay}\nDays Per Month: {daysPerMonth}");
  31.         double monthlysalary = CalculateMonthlySalary();
  32.         Console.WriteLine($"{name}'s Salary per month is PHP{monthlysalary}");
  33.         double annualsalary = CalculateAnnualSalary();
  34.         Console.WriteLine($"{name}'s Salary per year is PHP{annualsalary}\n------------------------------");
  35.     }
  36. }
  37. public class program
  38. {
  39.     public static void Main(String[] args)
  40.     {
  41.         Console.WriteLine("Enter the number of Employees: ");
  42.         int NumEmployee = int.Parse(Console.ReadLine());
  43.  
  44.         Employee[] employee = new Employee[NumEmployee];
  45.  
  46.         for (int i = 0; i < NumEmployee;i++) {
  47.             string Name;
  48.             double HourlyWage;
  49.             double HoursPerDay;
  50.             double DaysPerMonth;
  51.  
  52.             bool valid = false;
  53.  
  54.             Console.WriteLine($"Enter Employee #{i+1} name");
  55.             Name = Console.ReadLine();
  56.            
  57.  
  58.             repeat:
  59.             Console.Write("Enter Hourly Wage: ");
  60.             if (!double.TryParse(Console.ReadLine(), out HourlyWage))
  61.                 {
  62.                 bumalik:
  63.                 Console.WriteLine("Invalid input!, Continue or Re-enter? (c / r)");
  64.                 string input = Console.ReadLine();
  65.                 switch (input.ToLower())
  66.                 {
  67.                 case "c":
  68.                     break;
  69.                 case "r":
  70.                     goto repeat;
  71.                         break;
  72.                 default:
  73.                     Console.WriteLine("Invalid input!");
  74.                     goto bumalik;
  75.                     break;
  76.                 }
  77.                 }
  78.             repeat1:
  79.                 Console.Write("Enter Hours Per Day: ");
  80.                 if (!double.TryParse(Console.ReadLine(), out HoursPerDay))
  81.                 {
  82.                 bumalik:
  83.                     Console.WriteLine("Invalid input!, Continue or Re-enter? (c / r)");
  84.                     string input = Console.ReadLine();
  85.                     switch (input.ToLower())
  86.                     {
  87.                         case "c":
  88.                             break;
  89.                         case "r":
  90.                             goto repeat1;
  91.                         default:
  92.                             Console.WriteLine("Invalid input!");
  93.                             goto bumalik;
  94.                     }
  95.                 }
  96.             repeat2:
  97.                 Console.Write("Enter Days Per Month: ");
  98.                 if (!double.TryParse(Console.ReadLine(), out DaysPerMonth))
  99.                 {
  100.                 bumalik:
  101.                     Console.WriteLine("Invalid input!, Continue or Re-enter? (c / r)");
  102.                     string input = Console.ReadLine();
  103.                     switch (input.ToLower())
  104.                     {
  105.                         case "c":
  106.                             break;
  107.                         case "r":
  108.                             goto repeat2;
  109.                         default:
  110.                             Console.WriteLine("Invalid input!");
  111.                             goto bumalik;
  112.                     }
  113.                 }
  114.             employee[i] = new Employee(Name,HourlyWage,HoursPerDay,DaysPerMonth);
  115.         }
  116.         for(int i=0;i<NumEmployee;i++)
  117.         {
  118.             employee[i].DisplayInfo();
  119.         }
  120.     }
  121. }
  122.  
  123.  
  124.  
Add Comment
Please, Sign In to add comment