I am working on this problem and I got a pretty good idea of what I am doing...but, I don't know if I am doing it correctly. I already worked the problem out...but, need some assistance and I'm not trying to get you to do my homework for me, just need a little help.

Write a program that displays the income tax due (in a certain state) on a taxable income entered by the user, according to the tax table shown in Table 9.2.

TaxableIncome Tax Due
From To
$0 $50,000 $0 + 5% of amount over $0
$50,000 $100,000 $2,500 + 7% of amount over $50,000
$100,000 . . . $6,000 + 9% of amount over $100,000

The program should allow the user to enter a series of incomes, terminated by 0. Use a class called Tax, with attributes Income and TaxDue and methods that include ComputeTax() and access methods (SetIncome(), GetIncome(), SetTaxDue(), and GetTaxDue()) for each of the attributes.

Program

Declare Public Class tax
Declare Public Property INCOME As Integer;
Declare Public Property TAXDUE As Float With Precision 2, Size 3;

Declare Public Method NEW(income As Integer = 0)
this.INCOME = income;
this.TAXDUE = 0.00
End Public Method NEW

Declare Public Method COMPUTETAX
If this.INCOME Is Less Than Or Equal To 50000 Then
this.TAXDUE = this.INCOME * 0.05;
Else If this.Income Is Less Than Or Equal To 100000 Then
this.TAXDUE = (this.INCOME * 0.07) + 2500;
Else
this.TAXDUE = (this.INCOME * 0.09) + 6000;
End If
End Public Method COMPUTETAX

End Public Class


BEGIN main program BEGIN
Use Class tax;
Declare input As Integer;
Declare taxtotal As Float With Precision 2, Size 3

Do
Prompt "Input a salary (enter 0 To exit): " + Line Break;
input = User Input;
Declare salary As New tax(input);
taxtotal = salary.COMPUTETAX;
Output "The tax for salary of " + input + " is " + taxtotal + Line Break;
Loop While input Is Not Equal To 0

END main program END

Thank you so much for you assistance!

Recommended Answers

All 2 Replies

Your algorithm looks OK to me. The only thing I am not sure about is that why you try to limit the display format right where you "declare" the taxtotal? The number of precision should be determined at the display, not at your declaration unless the taxtotal is a display formatter object itself.

Hmm... Also, the requirement is a bit odd to me.

The program should allow the user to enter a series of incomes, terminated by 0. Use a class called Tax, with attributes Income and TaxDue and methods that include ComputeTax() and access methods (SetIncome(), GetIncome(), SetTaxDue(), and GetTaxDue()) for each of the attributes.

Because of this requirement, you may need to declare the salary "outside" your loop instead of repeat declaring a new salary object. The reason is that it has "setIncome()" method which implies that you are going to reuse the same object. Also, it has "getTaxDue()" method in it as well. That's another odd way of having extra steps in your computation (because of the requirement). So your algorithm may need to change to...

Declare salary with income 0
Do
Prompt "Input a salary (enter 0 To exit): " + Line Break;
input = User Input;
salary.SetIncome(input);
salary.ComputeTax(); // compute the tax and save it to the object's TAXDUE variable
Output "The tax for salary of " + salary.GetIncome() + " is " + salary.GetTaxDue() + Line Break;
Loop While input Is Not Equal To 0

However, getting value for income & tax can be placed in a variable first. Then you do the display format manipulation.

A better way for computing tax is to call the ComputeTax() right after you set the income (inside the SetIncome() method or at the end of your constructor) instead of explicitly call it as in the algorithm above. That way, you will ensure that the tax is computed because you already know what the income is at that point.

Hope this help.

Taywin, thank you so much...and, it does help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.