3 Replies - 548 Views - Last Post: 19 June 2012 - 11:10 PM Rate Topic: -----

#1 xghostchantx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 18-May 12

Working on my java assignment, some help required

Posted 19 June 2012 - 08:25 PM

Hi there,

I'm working on my latest uni assignment and have encountered a couple of hurdles.

I kiiinda have the solution to it in my head (using ifs, I guess), I'm just not sure how to go about implementing it.

I have recently completed Part A of the assignment

import java.util.Scanner;
public class TaxAssignment {

	public static void main(String[] args) {
    // The following code is to determine the personal information of the tax payer, e.g. name, TFN, etc.
    Scanner user_input = new Scanner(System.in);
    System.out.println("It is important to note before proceeding not to enter any special characters or spaces for your numeric inputs.\n");
	   System.out.println("Enter your name:");
	String name = user_input.nextLine();
	   System.out.println("Enter your tax file number:");
	String tfn = user_input.nextLine();
	   System.out.println("Enter the financial year:");
	String fyear = user_input.next();
	   System.out.println("Enter your gross taxable PAYG income for period 2011-2012:");
    String payg = user_input.next();
       Integer sum = Integer.valueOf(payg);
       System.out.println("Enter bank interest accrued:");
    String interest = user_input.next();
       Integer sum2 = Integer.valueOf(interest);
       System.out.println("Enter pre-tax superannuation contribution for period 2011-2012:");
    String supercont = user_input.next();
       Integer sum3 = Integer.valueOf(supercont);
       System.out.println("Enter claimable deductions for period 2011-2012:");
    String claim = user_input.next();
       Integer sum4 = Integer.valueOf(claim);
   // The following code is the result of the entered strings & variables, with equations for tax brackets & percentages
    
       System.out.println("         ***  Final Tax Statement ***              \n");
          System.out.println("Name:                            " +name);
             System.out.println("Tax File Number:                 " +tfn);
                System.out.println("Financial Year:                  " +fyear);
                   System.out.println("Assessable Income:               $" +(sum+sum2));
                      System.out.println("Minus Tax Offsets:               -$" +(sum3+sum4));
                         System.out.println("Taxable Income                   $" +((sum+sum2)-(sum3+sum4)));
                            System.out.println("Tax Payable:                     $" +(((sum+sum2)-(sum3+sum4))*0.15));
	}

}


And have since moved on to part B - which adds a couple more functions (two Y/N options) and the relevant tax brackets to calculate the correct amount to tax the payee.

I a presuming that

System.out.println("Tax Payable:                     $" +(((sum+sum2)-(sum3+sum4))*0.15));


Simply isn't going to work anymore, as there are multiple tax brackets that need to be calculated, and therefore I would need another series of if statements for tax payable.

My first issue (and probably the easiest) is implementing the table of tax brackets. As I mentioned before I'm presuming I can user a series of if statements to meet the criteria - However, there is another issue present in this for me personally, as I am absolutely horrendous at maths. Below are the tax brackets for reference.

0 - $6,000 Nil
$6,001 - $37,000 15c for each $1 over $6,000
$37,001 - $80,000 $4,650 plus 30c for each $1 over $37,000
$80,001 - $180,000 $17,550 plus 37c for each $1 over $80,000
$180,001 and over $54,550 plus 45c for each $1 over $180,000.

The second challenge for me is the two Y/N inputs - for part B, I need to include a couple of other tax related criteria; medicare levy and hecs/help debt. They simply require a Yes or No input as the amounts taxed on them are static amounts.

To obtain this input as a string, would I then need to convert the value of Y or N to 1 or 0 respectively as an integer for the next part of the if statement?

Any help is muchly appreciated!

Thanks,
James.

Is This A Good Question/Topic? 0
  • +

Replies To: Working on my java assignment, some help required

#2 natecat  Icon User is offline

  • D.I.C Head

Reputation: 53
  • View blog
  • Posts: 225
  • Joined: 19-December 11

Re: Working on my java assignment, some help required

Posted 19 June 2012 - 08:40 PM

For the yes no questions, I would recommend a JOptionPane input dialog, and then check if the string equals "Yes" or "No"
Was This Post Helpful? 0
  • +
  • -

#3 xghostchantx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 18-May 12

Re: Working on my java assignment, some help required

Posted 19 June 2012 - 08:49 PM

Quote

For the yes no questions, I would recommend a JOptionPane input dialog, and then check if the string equals "Yes" or "No"


I had a look at that, but the specifications require us to use an ordinary console input.

:(
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10804
  • View blog
  • Posts: 40,278
  • Joined: 27-December 08

Re: Working on my java assignment, some help required

Posted 19 June 2012 - 11:10 PM

You don't need to convert the inputs to ints. Just test:
if(inputString.equals("Y")){
   //user entered yes
}
else{
   //user entered no
}


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1