CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2012
    Posts
    1

    seperating code into classes

    I need to use mutator and accessor methods and two classes but Im not sure where to start. I have the code working as is but I havent met the requirements.
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace commission
    {
        class Program
        {
           static void Main(string[] args)
            {
                decimal commission = 0.07M;
                decimal federaltax = 0.18M;
                decimal retirement = 0.10M;
                decimal socialsecurity = 0.06M;
                decimal total_amt = 0;
                decimal commission_amt = 0;
                decimal fed_t_amt = 0;
                decimal retire_amt = 0;
                decimal ss_amt = 0;
                decimal moneytakenout_amt = 0;
                decimal takehomepay = 0;
                string employeeName;
    
                Console.Write("Enter employee name: ");
                employeeName = Console.ReadLine();
                Console.Write("Enter the total sales amount for the week: ");
                total_amt = Convert.ToDecimal(Console.ReadLine());
    
                commission_amt = total_amt * commission;
                fed_t_amt = federaltax * total_amt;
                retire_amt = retirement * total_amt;
                ss_amt = socialsecurity * total_amt;
                moneytakenout_amt = retire_amt + fed_t_amt + ss_amt;
                takehomepay = total_amt - moneytakenout_amt;
    
                Console.WriteLine("Commission: " + commission_amt);
                Console.WriteLine("Federal Tax: " + fed_t_amt);
                Console.WriteLine("Retirement: " + retire_amt);
                Console.WriteLine("Social Security: " + ss_amt);
                Console.WriteLine("Take Home Pay: " + takehomepay);
    
            }
        }
    }

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: seperating code into classes

    This is obviously homework.

    It is difficult separating ytour code into separate classes after the fact. There should have been proper planning done ahead of program creation, IMHO.

  3. #3
    Join Date
    Jul 2012
    Location
    Ohio
    Posts
    13

    Re: seperating code into classes

    (People have to start somewhere)

    Start by looking through and identifying your entities. and the reason why you would want to create them into objects (classes) for example I'd like to be able to see just employees without tax information and just tax information without employee information, and possibly I could use employees somewhere else other than class information. Also you want to look at building blocks. I suggest head first into design patterns once you get each chapter concept of a beginner book. It will really teach you how to move on to interfaces. I'm not talking about the Graphic User Interface there either.

    SIMPLE ANSWER: Looks to me like Employees and Taxes would be two different entities for your classes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured