Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Help with this programming problem??

  • 06-10-2009 6:42pm
    #1
    Registered Users, Registered Users 2 Posts: 3,599 ✭✭✭


    This post has been deleted.
    Tagged:


Comments

  • Registered Users, Registered Users 2 Posts: 3,945 ✭✭✭Anima


    Where are you falling down? I can see some errors but it won't help if I just tell you. You know what I mean? :)


  • Registered Users, Registered Users 2 Posts: 3,599 ✭✭✭sashafierce


    This post has been deleted.


  • Registered Users, Registered Users 2 Posts: 3,945 ✭✭✭Anima


    Well I'd start by fixing your brackets. Also you should move some of the definitions outside of the first if statement because Scanner won't work properly otherwise.


  • Registered Users, Registered Users 2 Posts: 515 ✭✭✭NeverSayDie


    This post has been deleted.

    Folks who do this kind of thing for a living are reluctant to hand out answers on a plate because a) it's only helping in the shortest possible term and we have better ways to spend our time than that, and b) we've seen the results of handing out answers on a plate - software developers who can't do their jobs, and make their own and everyone else's lives difficult.


    Re your code, for instance, (unless Java's syntax is much weirder than I think it is) comparing these two lines might reveal a problem;

    if(accountType=="A"//accountType="a")

    Scanner sc= new Scanner(System.in);//allowing keyboard input


    As Anima suggests, your brackets need looking at - if you haven't already, make sure you indent you code in each block, and put the braces on their own lines, that should make it easy enough to spot the mistakes.

    Aside from that, you need to step through your code a line at a time, and think about what it's doing, and what order it's doing it in. Writing out a line-by-line description of program closer to English than Java (that's called pseudocode) would be a good idea to figure out the order things should happen and the flow of it.


  • Registered Users, Registered Users 2 Posts: 1,071 ✭✭✭Art_Wolf


    Yeah your brackets are in need of reordering.

    Remember its

    Class
    {

    Method
    {

    if (...)
    {

    <code>
    }
    }
    }

    In terms of your variables I suggest you look up 'scope' in your notes.


  • Advertisement
  • Closed Accounts Posts: 10 jaysond


    I've included code below for calculating the tax. I put a few test cases through it and it 'seems' ok but don't start flaming me if any parts of it are wrong. If they are wrong, you should be able to fix them yourself. If not, simply give up.

    I agree with the comments of all the above authors especially the 'handing out answers on a plate' one. I know I've just done it (not fully tested!!), but I've had numerous bad experiences in the past of working with 'programmers' who constantly expected to be spoon fed solutions. They are time consuming leeches and are f**k all use around deadline time (or any time for that matter). Do yourself a favour and start solving problems yourself or at least make a serious effort doing so before you approach someone for the solution.

    Your gonna have to learn (or get use to) persevering with the problem and just as importantly, make sure that you understand the problem. In your example, variables were not declared in your listing, syntax was incorrect which would have generated numerous errors when compiled. These are very basic programming items and people really don't want to be wasting their time with this kind of stuff. Anyways, have fun and for your own sake, RTFM and if you don't understand it the first time, do it again and again until you do. Persevere and make sure you understand!!

    In the code below, your also gonna have to put in some code for reading from the keyboard and initialise the respective variables. Enjoy!

    [PHP]
    import java.util.*;

    public class TaxAssignment
    {
    public static void main(String[] args)
    {
    char cAccountType;
    double dLowerTaxBand = 0.0, dUpperTaxBand = 0.0;
    double dLowerTaxRate, dUpperTaxRate;
    double dSalary;

    cAccountType = 'A'; // catagory of tax payer
    dSalary = 50000; // salary per year

    dLowerTaxRate = 28.0 / 100.0; // tax rates same for all cases.
    dUpperTaxRate = 45.0 / 100.0;

    if(cAccountType == 'A' || cAccountType == 'a') // Single person
    {
    dLowerTaxBand = 10000;
    dUpperTaxBand = 28000;
    }
    else if(cAccountType == 'B' || cAccountType == 'b') // married single sal
    {
    dLowerTaxBand = 12000;
    dUpperTaxBand = 29000;
    }
    else if(cAccountType == 'C' || cAccountType == 'c') // married two salary
    {
    dLowerTaxBand = 20000;
    dUpperTaxBand = 50000;
    }

    double dStandardTaxRange = dUpperTaxBand - dLowerTaxBand;
    double dTaxableSalary = dSalary - dLowerTaxBand;
    double dTaxDue = 0.0;

    if(dTaxableSalary > 0.0)
    {
    if(dTaxableSalary > dStandardTaxRange)
    dTaxDue = dStandardTaxRange * dLowerTaxRate;
    else
    dTaxDue = dTaxableSalary * dLowerTaxRate;

    dTaxableSalary -= dUpperTaxBand;

    if(dTaxableSalary > 0.0)
    dTaxDue += dTaxableSalary * dUpperTaxRate;
    }

    System.out.println("Tax due: " + dTaxDue);
    }
    }
    [/php]


  • Registered Users, Registered Users 2 Posts: 3,599 ✭✭✭sashafierce


    This post has been deleted.


  • Registered Users, Registered Users 2 Posts: 3,599 ✭✭✭sashafierce


    This post has been deleted.


  • Closed Accounts Posts: 3,357 ✭✭✭Beano


    jaysond wrote: »
    I've included code below for calculating the tax. I put a few test cases through it and it 'seems' ok but don't start flaming me if any parts of it are wrong. If they are wrong, you should be able to fix them yourself. If not, simply give up.

    I agree with the comments of all the above authors especially the 'handing out answers on a plate' one. I know I've just done it (not fully tested!!), but I've had numerous bad experiences in the past of working with 'programmers' who constantly expected to be spoon fed solutions. They are time consuming leeches and are f**k all use around deadline time (or any time for that matter). Do yourself a favour and start solving problems yourself or at least make a serious effort doing so before you approach someone for the solution.

    Your gonna have to learn (or get use to) persevering with the problem and just as importantly, make sure that you understand the problem. In your example, variables were not declared in your listing, syntax was incorrect which would have generated numerous errors when compiled. These are very basic programming items and people really don't want to be wasting their time with this kind of stuff. Anyways, have fun and for your own sake, RTFM and if you don't understand it the first time, do it again and again until you do. Persevere and make sure you understand!!

    In the code below, your also gonna have to put in some code for reading from the keyboard and initialise the respective variables. Enjoy!

    [PHP]
    import java.util.*;

    public class TaxAssignment
    {
    public static void main(String[] args)
    {
    char cAccountType;
    double dLowerTaxBand = 0.0, dUpperTaxBand = 0.0;
    double dLowerTaxRate, dUpperTaxRate;
    double dSalary;

    cAccountType = 'A'; // catagory of tax payer
    dSalary = 50000; // salary per year

    dLowerTaxRate = 28.0 / 100.0; // tax rates same for all cases.
    dUpperTaxRate = 45.0 / 100.0;

    if(cAccountType == 'A' || cAccountType == 'a') // Single person
    {
    dLowerTaxBand = 10000;
    dUpperTaxBand = 28000;
    }
    else if(cAccountType == 'B' || cAccountType == 'b') // married single sal
    {
    dLowerTaxBand = 12000;
    dUpperTaxBand = 29000;
    }
    else if(cAccountType == 'C' || cAccountType == 'c') // married two salary
    {
    dLowerTaxBand = 20000;
    dUpperTaxBand = 50000;
    }

    double dStandardTaxRange = dUpperTaxBand - dLowerTaxBand;
    double dTaxableSalary = dSalary - dLowerTaxBand;
    double dTaxDue = 0.0;

    if(dTaxableSalary > 0.0)
    {
    if(dTaxableSalary > dStandardTaxRange)
    dTaxDue = dStandardTaxRange * dLowerTaxRate;
    else
    dTaxDue = dTaxableSalary * dLowerTaxRate;

    dTaxableSalary -= dUpperTaxBand;

    if(dTaxableSalary > 0.0)
    dTaxDue += dTaxableSalary * dUpperTaxRate;
    }

    System.out.println("Tax due: " + dTaxDue);
    }
    }
    [/php]

    Should we really be providing lumps of code like this?


  • Registered Users, Registered Users 2 Posts: 59,703 ✭✭✭✭namenotavailablE


    tax = (income-(10000*0.00)-(15000*0.28))*0.45;
    Check the logic of this and similar statements in your code- as it looks to me, you're getting 45% of an incorrect income value


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,781 ✭✭✭amen


    cAccountType == 'C' || cAccountType == 'c'

    and why this?

    why not UCase before comparing?


Advertisement