Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (javk):

Can somebody help me with java. I need to write a program for calculating tax owed by a business. I've done most of it but there's this one method I'm stuck on:

OpenStudy (javk):

This is the information that was given to me: Meaning of terms used • Income: The income generated by the business • Business expenses: The expenses that the business has in meeting its costs eg materials, staff, premises etc. • Tax deductible expenses: The money spent by a business that can be deducted from tax owed, eg charitable donations. • Taxable income: the part of the income that tax can be assessed on • Tax band: the amount of tax to be paid depending on which band the taxable income falls into: • taxable income less than 10,000 – no tax • taxable income equal to or greater than 10,000 and less than 30,000 – 20% tax • taxable income equal to or greater than 30,000 and less than 50,000 – 40% tax • taxable income equal to or greater than 50,000 – 45% tax The algorithm 1. Deduct the business expenses from the income, giving the taxable income. 2. Work out what tax band applies to the taxable income. 3. Work out the amount of tax due on the taxable income (eg, a taxable income of 12,000 would be taxed at 20%, giving tax due of 2,400). 4. From the tax due deduct the tax deductible expenses to give the final tax amount. 5. If the final tax amount is a positive number, then the user is to be told that they owe that amount in tax. 6. If the final tax amount is a negative number then the user is to be told that they are owed a tax refund of the absolute value of the final tax amount.

OpenStudy (javk):

These are the tasks I need to accomplish: 1. Write methods to implement the tax calculator algorithm. It is good object-oriented practice to have methods that only do one thing, therefore each of steps 1 to 4 should have its own method. 2. Write a method that uses the first four methods you have written to calculate the final tax amount, and to tell the user whether they owe tax, owe nothing, or are owed a tax rebate. 3. Write comments in your program. Imagine that you have put the program to one side for a year, and write comments that would help you to remember what it is that the program does and how it does it. 4. Write a main method to test your final program. 5. Summarize your test results in a table, with at least the following headings: input; what the input is testing; expected output; actual output; pass/fail. Write a short (one paragraph) conclusion briefly discussing your results.

OpenStudy (javk):

This is what I came up: ``` import java.util.Scanner; public class TaxCalculator { private static int taxableIncome; private static int taxband1; //taxable income equal to or greater than 50,000 – 45% tax private static int taxband2; //taxable income equal to or greater than 30,000 and less than 50,000 – 40% tax private static int taxband3; //taxable income equal to or greater than 10,000 and less than 30,000 – 20% tax private static int taxband4; //taxable income less than 10,000 – no tax private static int taxDue; //amount of tax due on the taxable income private static int finalTax; //final tax due after taking away all expenses (actual value of tax due) public static void TaxableIncome() { //Takes in user input values for Income and Business Expenses and calculates Taxable Income. Scanner in = new Scanner(System.in); System.out.println("Please enter your Income "); int income = in.nextInt(); System.out.println("Enter your business expenses "); int businessExpenses = in.nextInt(); taxableIncome = income - businessExpenses; } public static void TaxBand() { //Decides which tax band would apply if (taxableIncome >= 50000) {taxableIncome = taxband1; System.out.println("taxband1");} else { if (taxableIncome >= 30000 && taxableIncome < 50000){taxableIncome = taxband2; System.out.println("taxband2");} else { if (taxableIncome >= 10000 && taxableIncome < 30000){taxableIncome = taxband3; System.out.println("taxband3");} else { if (taxableIncome < 10000){taxableIncome = taxband4; System.out.println("taxband4");} } } } } public static void TaxDue() //Tax due on taxable income { taxDue = taxband1 * 45 / 100; taxDue = taxband2 * 40 / 100; taxDue = taxband3 * 20 / 100; taxDue = taxband4; } public static void FinalTaxAmount() { Scanner in = new Scanner(System.in); System.out.println("Please enter your tax dedutible expenses"); int deductibleExpenses = in.nextInt(); finalTax = taxDue - deductibleExpenses; } public static void main(String[] args) { TaxableIncome(); TaxBand(); TaxDue(); FinalTaxAmount(); if (taxDue >= 0) System.out.println("You will recieve a tax refund."); else System.out.println("Your final tax amount is " + finalTax); } } ``` I'm sure my method TaxDue doesn't work

OpenStudy (ellecullen):

Did you test your methods to see if any work? I'm also having trouble with methods but for a different exercise. I'm only a beginner in java as I started my school course in September.

OpenStudy (javk):

yeah I'm pretty sure that there is a major problem with the method TaxDue, same here I just started too

OpenStudy (javk):

ok, no...wait there something wrong with my if statements too

OpenStudy (javk):

Can you help @theEric ?

OpenStudy (javk):

I resolved the issue with the method TaxBand, it looks like this now ``` public static void TaxBand() { //Decides which tax band would apply if (taxableIncome >= 50000) {taxband1 = taxableIncome; System.out.println(taxband1);} else { if (taxableIncome >= 30000 && taxableIncome < 50000){taxband2 = taxableIncome; System.out.println("taxband2");} else { if (taxableIncome >= 10000 && taxableIncome < 30000){ taxband3 = taxableIncome; System.out.println("taxband3");} else { if (taxableIncome < 10000){ taxband4 = taxableIncome; System.out.println("taxband4");} } } } }

OpenStudy (javk):

This is so funny...I must look like a mad woman...I'm having a fully fledged conversation with my self...

OpenStudy (woodrow73):

Anything in particular you want checked at this point?

OpenStudy (woodrow73):

Many programmers have conversations with themselves.. there can be a lot of information to juggle at any time. It's how the pros operate :p

OpenStudy (theeric):

Nice fix in the "TaxBand ()"! I would say, in the "TaxDue ()" method, look at what you're doing. I think you might have been on the right track. You know the other tax bands will be zero, so you can add them with the tax band that you set in "TaxBand ()". But you're just \(\it reassigning\) the "taxDue". You can make a simple change, if you're going for what I said, by using "+=".

OpenStudy (javk):

Good to know I'm not the only one @woodrow73 Thankyou, I did what you said and switched it up using the plus sign @theEric and now it's working, now I just have to do some extensive testing ``` public static void TaxDue() { //Calculates tax due on taxable income according to appropriate tax bar taxDue = (taxband1 * 45 / 100) + (taxband2 * 40 / 100) + (taxband3 * 20 / 100) + (taxband4 * 1); } ``` grey boxes ;)

OpenStudy (javk):

One more thing how do I know how many comments are just enough and when it gets too much?

OpenStudy (woodrow73):

Naturally comments ought to be clear and concise -- imagine the comments serving to help other programmers looking at your code to understand it quickly. Or even to just leave yourself reminders.. it's mostly personal preference.

OpenStudy (javk):

thankyou

OpenStudy (theeric):

I agree with @woodrow73 on the comments! Just NEVER say ``` int x = 5; // set "x" equal to five ``` The obvious should be read from the code. In my opinion, it would be okay \(\it sometimes\) to comment on that if it was like ``` int x = 5; // Must be five to ..blah blah blah ``` And, often times, you can do a lot of good communicating by using good variable names. Chances are, "x" is a \(\it bad\) name.

OpenStudy (theeric):

And usually a comment before methods are nice, if the name doesn't tell it all. It can be very breif. Here's one general suggestion on method names that might be just me, but maybe you'll like it too: Have method names be actions, because they are actions. Like "print" and "println". I would, if it were me, name the methods differently to tell \(\it what\ action\) the methods are doing. But that's all your call.

OpenStudy (javk):

thankyou thankyou thankyou

OpenStudy (theeric):

You're very welcome!!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!