Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Help! I've fallen and can't get up.

Help! I've fallen and can't get up.

Scheduled Pinned Locked Moved C#
helpcsharpsecuritysalesquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JMOdom
    wrote on last edited by
    #1

    :sigh::((I have been trying to learn C# in a classroom situation. I was given a problem that is supposed to be an OOP program.(I don't know enough to be sure.) The problem says that I'm to get an employee's name and the weekly sales amount. From that I need to figure out the gross pay, net pay, taxes, social security deduction and the retirement contribution. The only input is whats listed above. The other figures are based on constants. I would appreciate any help in steering me in the right direction. Supposedly the code I've written will work, I've based it on what is in the textbook. My CLASS I've called Deductions. I've listed it below. using System; using System.Collections.Generic; using System.Text; namespace Exercise_9_Chapter_4 { public class Deduction { public string name; public double weeklySales; public double fedTax; public double socSec; public double retireAcct; public double grossPay; public double netPay; public double weeklySalesAmount; const double GROSS_WEEKLY_PAY = .07; const double FEDERAL_TAX = .18; const double SOCIAL_SECURITY = .06; const double RETIRE_ACCT = .10; //CONSTRUCTORS: // default public Deduction() { } public Deduction(string empName, double weeklySales) { name = empName; weeklySalesAmount = weeklySales; } //MUTATORS: public double SetGrossPay(double weeklySales) { grossPay = weeklySales * GROSS_WEEKLY_PAY; return grossPay; } public void SetFedTax(double grossPay) { fedTax = grossPay * FEDERAL_TAX; } public void SetSocSec(double grossPay) { socSec = grossPay * SOCIAL_SECURITY; } public void SetRetireAcct(double grossPay) { retireAcct = grossPay * RETIRE_ACCT; } public void SetNetPay() { netPay = grossPay - (fedTax + socSec + retireAcct); } //PROPERTIES: public double NetPay { get { return netPay; } set { netPay = value; } } public double GrossPay { get { return grossPay; } set

    H M 2 Replies Last reply
    0
    • J JMOdom

      :sigh::((I have been trying to learn C# in a classroom situation. I was given a problem that is supposed to be an OOP program.(I don't know enough to be sure.) The problem says that I'm to get an employee's name and the weekly sales amount. From that I need to figure out the gross pay, net pay, taxes, social security deduction and the retirement contribution. The only input is whats listed above. The other figures are based on constants. I would appreciate any help in steering me in the right direction. Supposedly the code I've written will work, I've based it on what is in the textbook. My CLASS I've called Deductions. I've listed it below. using System; using System.Collections.Generic; using System.Text; namespace Exercise_9_Chapter_4 { public class Deduction { public string name; public double weeklySales; public double fedTax; public double socSec; public double retireAcct; public double grossPay; public double netPay; public double weeklySalesAmount; const double GROSS_WEEKLY_PAY = .07; const double FEDERAL_TAX = .18; const double SOCIAL_SECURITY = .06; const double RETIRE_ACCT = .10; //CONSTRUCTORS: // default public Deduction() { } public Deduction(string empName, double weeklySales) { name = empName; weeklySalesAmount = weeklySales; } //MUTATORS: public double SetGrossPay(double weeklySales) { grossPay = weeklySales * GROSS_WEEKLY_PAY; return grossPay; } public void SetFedTax(double grossPay) { fedTax = grossPay * FEDERAL_TAX; } public void SetSocSec(double grossPay) { socSec = grossPay * SOCIAL_SECURITY; } public void SetRetireAcct(double grossPay) { retireAcct = grossPay * RETIRE_ACCT; } public void SetNetPay() { netPay = grossPay - (fedTax + socSec + retireAcct); } //PROPERTIES: public double NetPay { get { return netPay; } set { netPay = value; } } public double GrossPay { get { return grossPay; } set

      H Offline
      H Offline
      Harini N K
      wrote on last edited by
      #2

      Hi 1. You have declared the statement inside the main() method and the variable 'employee' is local.

      Deduction employee = new Deduction(empName, wkSales);

      2. Declare this variable outside main() method

      static Deduction employee;

      and inside it should be chnaged to

      employee = new Deduction(empName, wkSales);

      3. Another mistake is that

      employee.netPay = GetNetPay();
      employee.grossPay = SetGrossPay();
      employee.fedTax = SetFedTax();
      employee.socSec = SetSocSec();
      employee.retireAcct = SetRetireAcct();

      Here remove brackets. You cannot assign use 'Set' on the right hand side as Set methods return type is void. Check your code again and correct it

      Harini

      1 Reply Last reply
      0
      • J JMOdom

        :sigh::((I have been trying to learn C# in a classroom situation. I was given a problem that is supposed to be an OOP program.(I don't know enough to be sure.) The problem says that I'm to get an employee's name and the weekly sales amount. From that I need to figure out the gross pay, net pay, taxes, social security deduction and the retirement contribution. The only input is whats listed above. The other figures are based on constants. I would appreciate any help in steering me in the right direction. Supposedly the code I've written will work, I've based it on what is in the textbook. My CLASS I've called Deductions. I've listed it below. using System; using System.Collections.Generic; using System.Text; namespace Exercise_9_Chapter_4 { public class Deduction { public string name; public double weeklySales; public double fedTax; public double socSec; public double retireAcct; public double grossPay; public double netPay; public double weeklySalesAmount; const double GROSS_WEEKLY_PAY = .07; const double FEDERAL_TAX = .18; const double SOCIAL_SECURITY = .06; const double RETIRE_ACCT = .10; //CONSTRUCTORS: // default public Deduction() { } public Deduction(string empName, double weeklySales) { name = empName; weeklySalesAmount = weeklySales; } //MUTATORS: public double SetGrossPay(double weeklySales) { grossPay = weeklySales * GROSS_WEEKLY_PAY; return grossPay; } public void SetFedTax(double grossPay) { fedTax = grossPay * FEDERAL_TAX; } public void SetSocSec(double grossPay) { socSec = grossPay * SOCIAL_SECURITY; } public void SetRetireAcct(double grossPay) { retireAcct = grossPay * RETIRE_ACCT; } public void SetNetPay() { netPay = grossPay - (fedTax + socSec + retireAcct); } //PROPERTIES: public double NetPay { get { return netPay; } set { netPay = value; } } public double GrossPay { get { return grossPay; } set

        M Offline
        M Offline
        mike montagne
        wrote on last edited by
        #3

        Whenever something "doesn't exist in the current context," it has not been declared within or is not accessible to the scope which tries to access it. You should be able to press F1 when you get the error message, or even see further explanation in intellisense/code completion, which should steer you to documentation that will give you examples of how something declared in one place may not be accessible to another. You may have declared a private or protected variable in the wrong class for instance, or maybe you wrote one of these methods in the wrong clas -- from which its trying to access data in the class it belongs in. So this is how they teach? You get the code, and then you're supposed to do something with it? What you're missing out on is the process of building all this. You can't be familiar with it if you can't build it, and if you can't build it, you aren't going to be any more effective than a poet with C# syntax. Don't cheat yourself. This is work. Believe it. The only way to make this simple for yourself is to find every answer you can by yourself. Believe me, in the end that's the fastest way. You are typing this stuff out without even thinking about it. In the end, what your project tasks amount to, is calling methods which are already written for you. That can't be very hard, can it? (But I'm afraid it's really insulating you from what you need to get from this.)

        J 1 Reply Last reply
        0
        • M mike montagne

          Whenever something "doesn't exist in the current context," it has not been declared within or is not accessible to the scope which tries to access it. You should be able to press F1 when you get the error message, or even see further explanation in intellisense/code completion, which should steer you to documentation that will give you examples of how something declared in one place may not be accessible to another. You may have declared a private or protected variable in the wrong class for instance, or maybe you wrote one of these methods in the wrong clas -- from which its trying to access data in the class it belongs in. So this is how they teach? You get the code, and then you're supposed to do something with it? What you're missing out on is the process of building all this. You can't be familiar with it if you can't build it, and if you can't build it, you aren't going to be any more effective than a poet with C# syntax. Don't cheat yourself. This is work. Believe it. The only way to make this simple for yourself is to find every answer you can by yourself. Believe me, in the end that's the fastest way. You are typing this stuff out without even thinking about it. In the end, what your project tasks amount to, is calling methods which are already written for you. That can't be very hard, can it? (But I'm afraid it's really insulating you from what you need to get from this.)

          J Offline
          J Offline
          JMOdom
          wrote on last edited by
          #4

          Is there some place that has a better more detailed explaination on some of these error codes. (My 2 cents) :rolleyes: I believe that MS should add to their error information an example of a common fix to the problem.:| I know there are people who might disagree, but for someone who is trying to learn, it would be helpful. For example, I'm now getting a 'Exer10Ch4.SchoolFigures.DetermineName(string)' must declare a body because it is not marked abstract or extern in my error list. I thought that I had declared the DetermineName(string)when I wrote the program. When I went to the help section all I was seeing was a defination of the error. If there had been an example of a fix for the problem it might have helped more. Anyway, my thanks to everyone who has taken time, and pity :((, on me to answer.

          M 1 Reply Last reply
          0
          • J JMOdom

            Is there some place that has a better more detailed explaination on some of these error codes. (My 2 cents) :rolleyes: I believe that MS should add to their error information an example of a common fix to the problem.:| I know there are people who might disagree, but for someone who is trying to learn, it would be helpful. For example, I'm now getting a 'Exer10Ch4.SchoolFigures.DetermineName(string)' must declare a body because it is not marked abstract or extern in my error list. I thought that I had declared the DetermineName(string)when I wrote the program. When I went to the help section all I was seeing was a defination of the error. If there had been an example of a fix for the problem it might have helped more. Anyway, my thanks to everyone who has taken time, and pity :((, on me to answer.

            M Offline
            M Offline
            mike montagne
            wrote on last edited by
            #5

            You are really getting what you want here. What you need to do is ponder the error message for just a minute. Once you get used to *thinking* (relatively hard I suppose) about what messages express, you can interpret them relatively easily. Get used to thinking hard if you want to write software. You are going to have to develop cleaner thinking habits than "normal" people. ("Dirty thinking people,' in C# nomenclature.) :-) The message tells you what your declaration is, and it is trying to tell you (no more cryptically than practical) how your declaration errs. You have declared "Exer10Ch4.SchoolFigures.DetermineName(string)" The term "body" must refer to a pair of braces {}. I had to figure that out myself as well (as I haven't got such an error in a long long while). So, what the error is saying that if your declaration doesn't have a body, it must refer to an external declaration somewhere, for which case you have to declare it with the extern keyword:

            extern Exer10Ch4.SchoolFigures.DetermineName(string);
            

            This probably isn't the error (but possibly it is). The compiler is telling you that it would also accept this statement if it were marked as abstract:

            abstract Exer10Ch4.SchoolFigures.DetermineName(string);
            

            The other condition it is telling you it would accept is that you declare a body:

            Exer10Ch4.SchoolFigures.DetermineName(string)
                 {
                 }
            

            The compiler is trying (all it can, really) to help you be a clean thinking person. You need to pay attention to the rules of the core language to interpret the message (easily, and cleanly). :cool:

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups