Results 1 to 8 of 8
 07312007, 04:35 AM #1Member
 Join Date
 Jul 2007
 Posts
 7
 Rep Power
 0
help with an exercise calcuting tax
i was hoping to get some help on an exercise that we have been given that asks to calculate tax. i am an absolute novice and any help would be appreciated.
we're asked to calculate tax for the 2007 period on a given income and the percentage of the income the tax represents. income less than $38000 is taxed at 19.5%, from $38000 to $60000 at 33% and over $60000 at 39%. However, earned income less than $9500 is given a rebate of 4.5% but this rebate is reduced by 1.5% of income between $9,500 and $38,000.
Additionally there is the repayment of a student loan. Although called a “loan” it is not an ordinary loan as it doesn’t ever have to be repaid, rather an agreement to pay additional tax of 10% on income over $17,160 until you have met your obligation.
Your program should show the tax both with and without a student loan in exactly the format of the following example:
Type in total income to nearest dollar: 35500
On an income of: $35500
Income tax is: $6923
With rebate of: $38
Giving total tax of: $6885
Which is: 19% of income
With a student loan:
Loan repayment is an additional: $1834
For total "tax" of: $8719
Which is: 25% of income
Press any key to continue . . .
we are given some variables such as:
final double LOW_TAX_RATE = 0.195;
final double MID_TAX_RATE = 0.33;
final double TOP_TAX_RATE = 0.39;
final double REBATE_RATE = 0.045;
final double PENALTY_RATE = 0.015;
final double LOAN_RATE = 0.1;
This kind of program will be easier to write when we have gone further and learned about conditional statements. For now you must write this program without using any conditional statements at all. Rather, you need to make use of the methods Math.max() and Math.min().
For example, the amount of income less than $38000 may be calculated as:
Math.min(income,38000)
the amount of income over $60000 may be calculated as:
Math.max(0,income60000)
Note that the amount of income between, say, $38,000 and $60,000 is the amount of income less than $60,000 that is greater than $38,000.
The detailed instructions ask that you do arithmetic with double variables and values but print out the answers to the nearest dollar. Use the method Math.round()to convert a double value to the nearest whole dollar value.
we havent as yet covered if and else statements and are only up to strings
 07312007, 08:27 AM #2Java Code:
import java.util.Scanner; public class TaxCalculation { // Member variable constants. final double LOW_TAX_RATE = 0.195; final double MID_TAX_RATE = 0.33; final double TOP_TAX_RATE = 0.39; final double REBATE_RATE = 0.045; final double PENALTY_RATE = 0.015; final double LOAN_RATE = 0.1; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); boolean goAgain = true; while(goAgain) { System.out.print("Type in total income to nearest dollar: "); String line = scanner.nextLine().trim(); int income = Integer.parseInt(line); int under38 = Math.min(income, 38000); System.out.println("income less than 38,000 = " + under38); int over38 = Math.max(0, income  38000); //System.out.printf("over38 = %d%n", over38); int over60 = Math.max(0, income  60000); int between = over38  over60; System.out.println("income between 38000 and 60000 = " + between); System.out.println("income over 60000 = " + over60); // Now you can figure the taxes... System.out.println("More? \"y\" or \"n\""); goAgain = scanner.nextLine().equals("y"); } } }
 07312007, 08:34 AM #3Member
 Join Date
 Jul 2007
 Posts
 7
 Rep Power
 0
thanx hardwired for doing that.
we havent covered boolean expressions or scanners. how would i get past this??
cheers
 07312007, 10:04 AM #4
Depends on your class/teacher. How do you get user input from the console in class? Maybe IO, ie, using readers. That's the way you would use. Have you learned while loops? If not maybe it's too early to do the loop part.
 07312007, 10:19 AM #5Member
 Join Date
 Jul 2007
 Posts
 7
 Rep Power
 0
no, havent done while loops. we read input using a custom keyboard class file that we save into the source directory. eg. when using a String;
String x = Keyboard.readInput();
double y = Double.parseDouble(x);
and we use equations in println statements eg:
System.out.println(x + "Hello" + y);
thanks
 07312007, 11:06 AM #6Member
 Join Date
 Jul 2007
 Posts
 7
 Rep Power
 0
this is what ive got so far and its not very good:
public class Q2Program {
public void start(){
// User types in income to nearest dollar and program
// responds with tax owing, and tax as % of income
// Ignore the under $9,880 rebate
// Assume all income counts for the "under $38,000" rebate
// Show with, and without, student loan owing for the entire year
// Use double arithmetic for calculations, but..
// Display money amounts rounded to nearest dollar
// Make use of the following constants for the tax rates
final double LOW_TAX_RATE = 0.195;
final double MID_TAX_RATE = 0.33;
final double TOP_TAX_RATE = 0.39;
final double REBATE_RATE = 0.045;
final double PENALTY_RATE = 0.015;
final double LOAN_RATE = 0.1;
/* Note that a professional program would also use constants for the
various income levels, but that would make this exercise a bit
cumbersome for beginners */
// Get income from the user
System.out.print("Type in total income to nearest dollar: ");
String income = Keyboard.readInput();
double income<38000 = Math.min(income, 38000);
System.out.print("On a income of: $" + income<38000);
double income>38000 = Math.max(0,income  38000);
System.out.print("On a income of: $" + income>38000);
double income>38000<60000 = ?????????????? Math.max(0, income,  38000, 60000);
System.out.print("On a income of: $" + income>38000<60000);
double income>60000 = Math.max(0, income  60000);
System.out.print("On a income of: $" + income>60000);
// Calculate income tax
// find tax on income up to $38,000 at 19.5%
double income<38000Tax = income<38000 * LOW_TAX_RATE;
System.out.print(" Income tax is: $" + income<38000Tax);
// find tax on income between $38,000 and $60,000 at 33%
double income>38000<60000Tax = income>38000<60000 * MID_TAX_RATE;
System.out.print(" Income tax is: $" + income>38000<60000Tax);
// find tax on income over $60,000 at 39%
double income>60000Tax = income>60000 * TOP_TAX_RATE;
System.out.print(" Income tax is: $" + income>60000Tax);
// Calculate tax rebate
// find rebate on income up to $9500 at 4.5%
double taxRebate = 9500 * REBATE_RATE;
// find penalty on rebate for income between $9500 and $38,000 at 1.5%
double penaltyRebate = (income  9500) * PENALTY_RATE;
// calculate net rebate
double netRebate = (taxRebate  penaltyRebate);
// calculate total income tax
double totalIncomeTax<38000 = (income<38000  income<38000Tax);
double totalIncomeTax>38000<60000 = (income>38000<60000  income>38000<60000Tax);
double totalIncomeTax>60000 = (income>60000  income>60000Tax);
// Calculate percentage of income
double percentageOfIncome<38000 = ((income<38000  totalIncomeTax<38000) * 100);
double percentageOfIncome>38000<60000 = ((income>38000<60000  totalIncomeTax>38000<60000) * 100);
double percentageOfIncome>60000 = ((income>60000  totalIncomeTax>60000) * 100);
// Calculate student loan tax
double studentLoanTax = (income  17160) * LOAN_RATE;
// Calculate total taxes, with and without loan;
double totalTax = (?????????????income tax  netRebate);
double totalTaxInclStudentLoan = (totalTax + studentLoanTax);
// Display tax owing and rates
System.out.print(" With rebate of: " + netRebate);
System.out.print(" Giving total tax of: " + totalTax);
System.out.print(" Which is: " + percentageOfIncome<38000" of income");
System.out.print(" Which is: " + percentageOfIncome>38000<60000" of income");
System.out.print(" Which is: " + percentageOfIncome>60000" of income");
System.out.print("With a student loan:");
System.out.print(" Loan repayment is an additional: " + studentLoanTax);
System.out.print(" For total \"tax\" of: " + totalTax);
System.out.print(" Which is: " + percentageOfIncome<38000 + " of income");
System.out.print(" Which is: " + percentageOfIncome>38000<60000 + " of income");
System.out.print(" Which is: " + percentageOfIncome>60000 + " of income");
//Use the method Math.round()to convert a double value to the nearest whole dollar value.
}
}
 07312007, 09:10 PM #7Java Code:
import java.util.Scanner; public class Q2P { public void start(){ // User types in income to nearest dollar and program // responds with tax owing, and tax as % of income // Ignore the under $9,880 rebate // Assume all income counts for the "under $38,000" rebate // Show with, and without, student loan owing for the entire year // Use double arithmetic for calculations, but.. // Display money amounts rounded to nearest dollar // Make use of the following constants for the tax rates final double LOW_TAX_RATE = 0.195; final double MID_TAX_RATE = 0.33; final double TOP_TAX_RATE = 0.39; final double REBATE_RATE = 0.045; final double PENALTY_RATE = 0.015; final double LOAN_RATE = 0.1; /* Note that a professional program would also use constants for the various income levels, but that would make this exercise a bit cumbersome for beginners */ //Scanner scanner = new Scanner(System.in); // Get income from the user System.out.print("Type in total income to nearest dollar: "); String in = Keyboard.readInput(); //scanner.nextLine(); double income = Double.parseDouble(in); double under38000 = Math.min(income, 38000); System.out.println("On a income of: $" + Math.round(under38000)); double over38000 = Math.max(0,income  38000); System.out.println("On a income of: $" + Math.round(over38000)); double inBetween = over38000  Math.max(0, income  60000); System.out.println("On a income of: $" + Math.round(inBetween)); double over60000 = Math.max(0, income  60000); System.out.println("On a income of: $" + Math.round(over60000)); // Calculate income tax // find tax on income up to $38,000 at 19.5% double under38000Tax = under38000 * LOW_TAX_RATE; System.out.println(" Income tax is: $" + Math.round(under38000Tax)); // find tax on income between $38,000 and $60,000 at 33% double inBetweenTax = inBetween * MID_TAX_RATE; System.out.println(" Income tax is: $" + Math.round(inBetweenTax)); // find tax on income over $60,000 at 39% double over60000Tax = over60000 * TOP_TAX_RATE; System.out.println(" Income tax is: $" + Math.round(over60000Tax)); // Calculate tax rebate // find rebate on income up to $9500 at 4.5% double taxRebate = 9500 * REBATE_RATE; // find penalty on rebate for income between $9500 and $38,000 at 1.5% // income between $9500 and $38,000 = incomeOver9500  incomeOver38000 double over9500 = Math.max(0, income  9500); System.out.printf("income = %.0f over9500 = %.0f over38000 = %.0f%n" + "income between $9500 and $38,000 = %.0f%n", income, over9500, over38000, over9500  over38000); double penaltyRebate = (over9500  over38000) * PENALTY_RATE; // calculate net rebate double netRebate = (taxRebate  penaltyRebate); // calculate total income tax double totalUnder38000Tax = (under38000  under38000Tax); double totalInBetweenTax = (inBetween  inBetweenTax); double totalOver60000Tax = (over60000  over60000Tax); // Calculate percentage of income double percentUnder38000 = ((under38000  totalUnder38000Tax) * 100); double percentInBetween = ((inBetween  totalInBetweenTax) * 100); double percentOver60000 = ((over60000  totalOver60000Tax) * 100); // Calculate student loan tax double studentLoanTax = (income  17160) * LOAN_RATE; // Calculate total taxes, with and without loan; double totalTax = (totalUnder38000Tax + totalInBetweenTax + totalOver60000Tax  netRebate); double totalTaxInclStudentLoan = (totalTax + studentLoanTax); // Display tax owing and rates // Use the method Math.round() to convert a double value // to the nearest whole dollar value. System.out.println(" With rebate of: " + Math.round(netRebate)); System.out.println(" Giving total tax of: " + Math.round(totalTax)); System.out.println(" Which is: " + Math.round(percentUnder38000) + " of income"); System.out.println(" Which is: " + Math.round(percentInBetween) + " of income"); System.out.println(" Which is: " + Math.round(percentOver60000) + " of income"); System.out.println("With a student loan:"); System.out.println(" Loan repayment is an additional: " + Math.round(studentLoanTax)); } public static void main(String[] args) { new Q2P().start(); } }
 08012007, 03:17 AM #8Member
 Join Date
 Jul 2007
 Posts
 7
 Rep Power
 0
Similar Threads

exercise of recursive method
By amexudo in forum New To JavaReplies: 2Last Post: 03092008, 05:55 PM 
Prob with an exercise
By jhetfield18 in forum New To JavaReplies: 4Last Post: 02152008, 06:11 PM 
Problems with Calendar exercise
By Jude in forum New To JavaReplies: 1Last Post: 11202007, 07:30 PM 
I/O exercise
By Feldom in forum New To JavaReplies: 1Last Post: 10282007, 04:48 PM 
help with exercise
By e_as're in forum New To JavaReplies: 3Last Post: 09252007, 10:14 AM
Bookmarks