473,511 Members | 15,178 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pls suggest a way to simplify this program without afffecting the validation steps

3 New Member
Need suggestions to improve this program.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2.  
  3. namespace CalculateWage
  4. {
  5.  
  6.     class GetEmployeeDetails
  7.     {
  8.       public string LastName, FirstName;
  9.  
  10.       public int NumberofHours;
  11.  
  12.       public  int WagesforaWeek, HourlyRate;
  13.  
  14.       public  int Medical, UnionFee;
  15.  
  16.       public int TotalDeduction, FederalTax;
  17.  
  18.       public  int Netpay;
  19.  
  20.     }
  21.  
  22.  
  23.         class Wage
  24.         {
  25.  
  26.  
  27.  
  28.       static void Main(string[] args)
  29.             {
  30.  
  31.                 GetEmployeeDetails GED = new GetEmployeeDetails();
  32.  
  33.                 Getinteger I = new Getinteger();
  34.  
  35.                 Getstring S = new Getstring();
  36.  
  37.  
  38.                 GED.FirstName = S.GetString("\nEnter ur First Name: ", "");
  39.  
  40.                 GED.LastName = S.GetString("\nEnter ur Last Name: ", "");
  41.  
  42.                 GED.NumberofHours = I.GetInteger("\nEnter no of hours worked: ", 0);
  43.  
  44.                 GED.HourlyRate = I.GetInteger("\nEnter hourly rate:", 0);
  45.  
  46.                 GED.WagesforaWeek = ((GED.NumberofHours * GED.HourlyRate) * 7);
  47.  
  48.  
  49.                 Console.WriteLine("\nwages for a week:{0}", GED.WagesforaWeek);
  50.  
  51.                 Console.ReadLine();
  52.  
  53.  
  54.                 GED.FederalTax = (GED.WagesforaWeek * (18 / 100));
  55.                 GED.Medical = (GED.WagesforaWeek * (5 / 100));
  56.                 GED.UnionFee = 8;
  57.                 GED.TotalDeduction = (GED.FederalTax + GED.Medical + GED.UnionFee);
  58.                 GED.Netpay = (GED.WagesforaWeek - GED.TotalDeduction);
  59.  
  60.  
  61.                 Console.WriteLine("\nName:{0}", GED.LastName);
  62.  
  63.                 Console.WriteLine("\nThe gross pay of {0} is {1}", GED.LastName, GED.WagesforaWeek);
  64.  
  65.                 Console.WriteLine("\nThe total deduction is:{0}", GED.TotalDeduction);
  66.  
  67.                 Console.WriteLine("\nThe net pay of {0} is: {1}", GED.LastName, GED.Netpay);
  68.  
  69.                 Console.ReadLine();
  70.             }
  71.  
  72.  
  73.  
  74.         }
  75.     }
  76.  
  77.  
  78. class Getstring
  79. {
  80.  
  81.     public string GetString(string Prompt, string FirstName)
  82.     {
  83.  
  84.         Console.Write(Prompt);
  85.  
  86.  
  87.         FirstName = (Console.ReadLine());
  88.  
  89.         if (Regex.IsMatch(FirstName, "^[a-zA-Z'.]{1,40}$"))
  90.         {
  91.         }
  92.         else
  93.         {            
  94.             Console.WriteLine("\nThe input should be a string!");
  95.  
  96.             Console.Write(Prompt);
  97.  
  98.             FirstName = (Console.ReadLine());
  99.  
  100.             if (Regex.IsMatch(FirstName, "^[a-zA-Z'.]{1,40}$"))
  101.             {
  102.             }
  103.             else
  104.             {
  105.                 Console.WriteLine("\nYou entered invalid input twice. The program will terminate");
  106.  
  107.                 System.Threading.Thread.Sleep(3000);
  108.  
  109.                 System.Diagnostics.Process.GetCurrentProcess().Kill();
  110.  
  111.             }
  112.         }
  113.  
  114.  
  115.  
  116.         return FirstName;
  117.     }
  118.  
  119.  
  120. }
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127. public  class Getinteger
  128. {
  129.  
  130.     public int GetInteger(string Prompt, int num1)
  131.     {
  132.  
  133.         Console.Write(Prompt);
  134.  
  135.         num1++;
  136.  
  137.         try
  138.         {
  139.             num1 = int.Parse(Console.ReadLine());
  140.  
  141.             if (num1 < 0)
  142.             {
  143.                 Console.WriteLine("\nEnter +ve number");
  144.  
  145.                 Console.Read();
  146.  
  147.                 if (num1 < 2)
  148.                 {
  149.                     num1 = GetInteger(Prompt, num1);
  150.  
  151.                     return num1;
  152.                 }
  153.                 else
  154.                 {
  155.                     Console.WriteLine("\nYou entered invalid input twice. The program will terminate");
  156.  
  157.                     System.Threading.Thread.Sleep(3000);
  158.  
  159.                     System.Diagnostics.Process.GetCurrentProcess().Kill();
  160.                 }
  161.             }
  162.         }
  163.  
  164.         catch
  165.         {
  166.  
  167.             Console.WriteLine("\nThe input should be an integer!");
  168.  
  169.  
  170.             if (num1 < 2)
  171.             {
  172.                 num1 = GetInteger(Prompt, num1);
  173.             }
  174.             else
  175.             {
  176.                 Console.WriteLine("You entered invalid input twice. The program will terminate");
  177.  
  178.                 System.Threading.Thread.Sleep(3000);
  179.  
  180.                 System.Diagnostics.Process.GetCurrentProcess().Kill();
  181.             }
  182.         }
  183.  
  184.         return num1;
  185.     }
  186.  
  187. }
  188.  
Mar 13 '07 #1
4 1255
pms
3 New Member
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Configuration.Assemblies;
  5.  
  6.  
  7.  
  8. namespace CalculateWage
  9. {
  10.  
  11.     class GetEmployeeDetails
  12.     {
  13.       public string LastName, FirstName;
  14.  
  15.       public int NumberofHours;
  16.  
  17.       public  int WagesforaWeek, HourlyRate;
  18.  
  19.       public  int Medical, UnionFee;
  20.  
  21.       public int TotalDeduction, FederalTax;
  22.  
  23.       public  int Netpay;
  24.  
  25.     }
  26.  
  27.  
  28.         class Wage
  29.         {
  30.  
  31.  
  32.  
  33.       static void Main(string[] args)
  34.             {
  35.  
  36.                 GetEmployeeDetails GED = new GetEmployeeDetails();
  37.  
  38.                 Getinteger I = new Getinteger();
  39.  
  40.                 Getstring S = new Getstring();
  41.  
  42.  
  43.                 GED.FirstName = S.GetString("\nEnter ur First Name: ", "");
  44.  
  45.                 GED.LastName = S.GetString("\nEnter ur Last Name: ", "");
  46.  
  47.                 GED.NumberofHours = I.GetInteger("\nEnter no of hours worked: ", 0);
  48.  
  49.                 GED.HourlyRate = I.GetInteger("\nEnter hourly rate:", 0);
  50.  
  51.                 GED.WagesforaWeek = ((GED.NumberofHours * GED.HourlyRate) * 7);
  52.  
  53.  
  54.                 Console.WriteLine("\nwages for a week:{0}", GED.WagesforaWeek);
  55.  
  56.                 Console.ReadLine();
  57.  
  58.  
  59.                 GED.FederalTax = (GED.WagesforaWeek * (18 / 100));
  60.                 GED.Medical = (GED.WagesforaWeek * (5 / 100));
  61.                 GED.UnionFee = 8;
  62.                 GED.TotalDeduction = (GED.FederalTax + GED.Medical + GED.UnionFee);
  63.                 GED.Netpay = (GED.WagesforaWeek - GED.TotalDeduction);
  64.  
  65.  
  66.                 Console.WriteLine("\nName:{0}", GED.LastName);
  67.  
  68.                 Console.WriteLine("\nThe gross pay of {0} is {1}", GED.LastName, GED.WagesforaWeek);
  69.  
  70.                 Console.WriteLine("\nThe total deduction is:{0}", GED.TotalDeduction);
  71.  
  72.                 Console.WriteLine("\nThe net pay of {0} is: {1}", GED.LastName, GED.Netpay);
  73.  
  74.                 Console.ReadLine();
  75.             }
  76.  
  77.  
  78.  
  79.         }
  80.     }
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88. using System;
  89. using System.Collections.Generic;
  90. using System.Text;
  91. using System.Configuration.Assemblies;
  92.  
  93.  
  94.  
  95. namespace CalculateWage
  96. {
  97.  
  98.     class GetEmployeeDetails
  99.     {
  100.       public string LastName, FirstName;
  101.  
  102.       public int NumberofHours;
  103.  
  104.       public  int WagesforaWeek, HourlyRate;
  105.  
  106.       public  int Medical, UnionFee;
  107.  
  108.       public int TotalDeduction, FederalTax;
  109.  
  110.       public  int Netpay;
  111.  
  112.     }
  113.  
  114.  
  115.         class Wage
  116.         {
  117.  
  118.  
  119.  
  120.       static void Main(string[] args)
  121.             {
  122.  
  123.                 GetEmployeeDetails GED = new GetEmployeeDetails();
  124.  
  125.                 Getinteger I = new Getinteger();
  126.  
  127.                 Getstring S = new Getstring();
  128.  
  129.  
  130.                 GED.FirstName = S.GetString("\nEnter ur First Name: ", "");
  131.  
  132.                 GED.LastName = S.GetString("\nEnter ur Last Name: ", "");
  133.  
  134.                 GED.NumberofHours = I.GetInteger("\nEnter no of hours worked: ", 0);
  135.  
  136.                 GED.HourlyRate = I.GetInteger("\nEnter hourly rate:", 0);
  137.  
  138.                 GED.WagesforaWeek = ((GED.NumberofHours * GED.HourlyRate) * 7);
  139.  
  140.  
  141.                 Console.WriteLine("\nwages for a week:{0}", GED.WagesforaWeek);
  142.  
  143.                 Console.ReadLine();
  144.  
  145.  
  146.                 GED.FederalTax = (GED.WagesforaWeek * (18 / 100));
  147.                 GED.Medical = (GED.WagesforaWeek * (5 / 100));
  148.                 GED.UnionFee = 8;
  149.                 GED.TotalDeduction = (GED.FederalTax + GED.Medical + GED.UnionFee);
  150.                 GED.Netpay = (GED.WagesforaWeek - GED.TotalDeduction);
  151.  
  152.  
  153.                 Console.WriteLine("\nName:{0}", GED.LastName);
  154.  
  155.                 Console.WriteLine("\nThe gross pay of {0} is {1}", GED.LastName, GED.WagesforaWeek);
  156.  
  157.                 Console.WriteLine("\nThe total deduction is:{0}", GED.TotalDeduction);
  158.  
  159.                 Console.WriteLine("\nThe net pay of {0} is: {1}", GED.LastName, GED.Netpay);
  160.  
  161.                 Console.ReadLine();
  162.             }
  163.  
  164.  
  165.  
  166.         }
  167.     }
  168. class Getstring
  169. {
  170.  
  171.     public string GetString(string Prompt, string FirstName)
  172.     {
  173.  
  174.         Console.Write(Prompt);
  175.  
  176.  
  177.         FirstName = (Console.ReadLine());
  178.  
  179.         if (Regex.IsMatch(FirstName, "^[a-zA-Z'.]{1,40}$"))
  180.         {
  181.         }
  182.         else
  183.         {            
  184.             Console.WriteLine("\nThe input should be a string!");
  185.  
  186.             Console.Write(Prompt);
  187.  
  188.             FirstName = (Console.ReadLine());
  189.  
  190.             if (Regex.IsMatch(FirstName, "^[a-zA-Z'.]{1,40}$"))
  191.             {
  192.             }
  193.             else
  194.             {
  195.                 Console.WriteLine("\nYou entered invalid input twice. The program will terminate");
  196.  
  197.                 System.Threading.Thread.Sleep(3000);
  198.  
  199.                 System.Diagnostics.Process.GetCurrentProcess().Kill();
  200.  
  201.             }
  202.         }
  203.  
  204.  
  205.  
  206.         return FirstName;
  207.     }
  208.  
  209.  
  210. }
  211.  
  212.  
  213.  
  214. public  class Getinteger
  215. {
  216.  
  217.     public int GetInteger(string Prompt, int num1)
  218.     {
  219.  
  220.         Console.Write(Prompt);
  221.  
  222.         num1++;
  223.  
  224.         try
  225.         {
  226.             num1 = int.Parse(Console.ReadLine());
  227.  
  228.             if (num1 < 0)
  229.             {
  230.                 Console.WriteLine("\nEnter +ve number");
  231.  
  232.                 Console.Read();
  233.  
  234.                 if (num1 < 2)
  235.                 {
  236.                     num1 = GetInteger(Prompt, num1);
  237.  
  238.                     return num1;
  239.                 }
  240.                 else
  241.                 {
  242.                     Console.WriteLine("\nYou entered invalid input twice. The program will terminate");
  243.  
  244.                     System.Threading.Thread.Sleep(3000);
  245.  
  246.                     System.Diagnostics.Process.GetCurrentProcess().Kill();
  247.                 }
  248.             }
  249.         }
  250.  
  251.         catch
  252.         {
  253.  
  254.             Console.WriteLine("\nThe input should be an integer!");
  255.  
  256.  
  257.             if (num1 < 2)
  258.             {
  259.                 num1 = GetInteger(Prompt, num1);
  260.             }
  261.             else
  262.             {
  263.                 Console.WriteLine("You entered invalid input twice. The program will terminate");
  264.  
  265.                 System.Threading.Thread.Sleep(3000);
  266.  
  267.                 System.Diagnostics.Process.GetCurrentProcess().Kill();
  268.             }
  269.         }
  270.  
  271.         return num1;
  272.     }
  273.  
  274. }
Mar 13 '07 #2
sicarie
4,677 Recognized Expert Moderator Specialist
Moved to C# forum.
Mar 13 '07 #3
pms
3 New Member
Moved to C# forum.
couldn't get ur reply
Mar 14 '07 #4
kenobewan
4,871 Recognized Expert Specialist
Please don't repost your questions, it is against site rules. This isn't really the place to optimize your code. If you have a problem or error post that and we will have a look. Thanks.
Mar 14 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
3644
by: ben | last post by:
i have a bit of code, that works absolutely fine as is, but seems over complicated/long winded. is there anyway to shorten/simplify it? the code is below. description of it: it's like strcpy in...
6
3692
by: Nedu N | last post by:
Hi, I want to have confirmation(Yes/No) on a button of the webform in which there are many validation controls. I want all the validation controls to be triggered first and then Yes/No...
2
2883
by: pv | last post by:
Hi everyone, I need help with following scenario, please: Users are accessing same web server from intranet (users previously authenticated in Active Dir) and from extranet (common public...
2
2707
by: csharpwanderer | last post by:
Hello, I am spending too much time trying to sort out what I think should be simple. So here it is. I have a wizard, with five steps. <wizard1> <wizardstep1><componant1></wizardstep1>...
43
3382
by: davidkoree | last post by:
I mean not about cookie. Does it have something to do with operating system or browser plugin? I appreciate any help.
2
1548
by: sudhashekhar30 | last post by:
hi all i have textbox in step in wizard control(step-10). there are 10 steps. so i want validation on every page and user can't move to other step without completing all correct entry. when i...
3
4132
by: tshad | last post by:
I have dataGrid that I am filling from a List Collection and need to sort it by the various columns. So I need to be able to sort the Collection and found that you have to set up your own...
4
5306
by: slapsh0t11 | last post by:
Hello! I need help with a program that I believe I am nearly done with. However, there seems to be a few details that preclude me from success. Here is my assignment: Here is my class file...
0
7237
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7417
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5063
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4734
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3219
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
445
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.