0% found this document useful (0 votes)
27 views8 pages

Java Assignment

The document is a student submission for a Diploma in Information Technology course. It contains details of the student such as name, student number, program, department, course code, course name, supervisor, and date of submission. The submission is for an Object Oriented Programming with Java course assessment.

Uploaded by

priwin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views8 pages

Java Assignment

The document is a student submission for a Diploma in Information Technology course. It contains details of the student such as name, student number, program, department, course code, course name, supervisor, and date of submission. The submission is for an Object Oriented Programming with Java course assessment.

Uploaded by

priwin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

SCHOOL OF INFORMATION TECHNOLOGY AND

MULTIMEDIA

STUDENT NAME: Priwin A/L Sri Morgen

STUDENT NUMBER: SCSJ2000314

PROGRAM NAME: Diploma in Information Technology

DEPARTMENT: Information Technology

COURSE CODE: IT109N

COURSE NAME: Object Oriented Programming with Java

SUPERVISOR: Mr.Foong

DATE OF SUBMISSION: 18/7/2021


Analysis:
I'd want to make a program that allows users to enter their income and compute their taxes for each
status. There are four filing statuses in this program: single filers, married filing jointly, married filing
jointly, married filing separately, and head of household. The program will calculate taxes accordingly to
federal personal tax rates.

Design:
To address the difficulty for this assessment,
I used if-else statement. I've also
attached a flowchart of how
I fixed the problem.
Testing:
Test Description Expected Result Actual Result
ID
ID01 Testing of four filing Single = 0
statuses correctly Married filing joinly or Qualified widow= 1
displayed or not. Married filing separately= 2
Head of household= 3
ID02 The filing status 0 is Enter the filing status: 0
tested as specified in the Enter the taxable income: 100000
assessment, ensuring Tax is 21720.0
that the tax calculation
is properly coded. The
outcome should match
the predicted outcome.
ID03 The filing status 1 is Enter the filing status: 1
tested as specified in the Enter the taxable income: 300339
assessment, ensuring Tax is 76932.87
that the tax calculation
is properly coded. The
outcome should match
the predicted outcome.
ID04 The filing status 2 is Enter the filing status: 2
tested as specified in the Enter the taxable income: 123500
assessment, ensuring Tax is 29665.5
that the tax calculation
is properly coded. The
outcome should match
the predicted outcome.
ID05 The filing status 3 is Enter the filing status: 3
tested as specified in the Enter the taxable income: 4545402
assessment, ensuring Tax is 1565251
that the tax calculation
is properly coded. The
outcome should match
the predicted outcome.
ID06 Testing incorrect filing Invalid status Entered
status. When user
enters wrong filing
status it should prompt
invalid status entered.
Source code:
import java.util.Scanner;
public class TaxCalculator {
public static void main(String[] args) {

// Creating a Scanner
Scanner input = new Scanner(System.in);

// Shows the user to enter filing status


System.out.print("Single = 0\n" + "Married filing joinly or Qualified widow= 1\n" + "Married
filling separately= 2\n" + "Head of household= 3\n" + "\n");
System.out.print("Enter valid filing status:");
int status = input.nextInt();

// Prompt the user to enter taxable income


System.out.print("Enter the taxable income: ");
double income = input.nextDouble();

// Assign Double
double tax = 0;

// Assigned single filers status into 0


if (status == 0) {

// Calculate tax for single filers


if (income <= 8350)
tax = income * 0.10;

else if (income <= 33950)


tax = 8350 * 0.10 + (income - 8350) * 0.15;
else if (income <= 82250)
tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
(income - 33950) * 0.25;

else if (income <= 171550)


tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
(82250 - 33950) * 0.25 + (income - 82250) * 0.28;

else if (income <= 372950)


tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
(82250 - 33950) * 0.25 + (171550 - 82250) * 0.28 +
(income - 171550) * 0.33;

else
tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
(82250 - 33950) * 0.25 + (171550 - 82250) * 0.28 +
(372950 - 171550) * 0.33 + (income - 372950) * 0.35;
}

// Assigned Married Filing Jointly or Qualified Widow(er) status into 1


else if (status == 1) {

// Calculate tax for Married Filing Jointly or Qualified Widow(er)


if (status == 1)
if (income <=16700)
tax = income * 0.10;

else if (income <=67900)


tax = 16700 * 0.10 + (income - 16700) * 0.15;
else if (income <= 137050)
tax = 16700 * 0.10 + (67900 - 16700) * 0.15 +
(income - 67900) * 0.25;

else if (income <= 208850)


tax = 16700 * 0.10 + (67900 - 16700) * 0.15 +
(137050 - 67900) * 0.25 + (income - 137050) * 0.28;

else if (income <= 372950)


tax = 16700 * 0.10 + (67900 - 16700) * 0.15 +
(137050 - 67900) * 0.25 + (208850 - 137050) * 0.28 +
(income - 208850) * 0.33;

else
tax = 16700 * 0.10 + (67900 - 16700) * 0.15 +
(137050 - 67900) * 0.25 + (208850 - 137050) * 0.28 +
(372950 - 208850) * 0.33 + (income - 372950) * 0.35;
}

// Assigned Married Filing Separately status into 2


else if (status == 2) {

// Calculate tax for Married Filing Separately


if (income <=8350)
tax = income * 0.10;

else if (income <=33950)


tax = 8350 * 0.10 + (income - 8350) * 0.15;
else if (income <= 68525)
tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
(income - 33950) * 0.25;

else if (income <= 104425)


tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
(68525 - 33950) * 0.25 + (income - 68525) * 0.28;

else if (income <=186475)


tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
(68525 - 33950) * 0.25 + (104425 - 68525) * 0.28 +
(income - 104425) * 0.33;

else
tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
(68525 - 33950) * 0.25 + (104425 - 68525) * 0.28 +
(186475 - 104425) * 0.33 + (income - 186475) * 0.35;
}

// Assigned Head of Household status into 3


else if (status == 3) {

// Calculate tax for Head of Household


if (income <= 11950)
tax = income * 0.10;

else if (income <= 45500)


tax = 11950 * 0.10 + (income - 11950) * 0.15;

else if (income <= 117450)


tax = 11950 * 0.10 + (45500 - 11950) * 0.15 +
(income - 45500) * 0.25;

else if (income <= 190200)


tax = 11950 * 0.10 + (45500 - 11950) * 0.15 +
(117450 - 45500) * 0.25 + (income - 117450) * 0.28;

else if (income <= 372950)


tax = 11950 * 0.10 + (45500 - 11950) * 0.15 +
(117450 - 45500) * 0.25 + (190200 - 117450) * 0.28 +
(income - 190200) * 0.33;

else
tax = 11950 * 0.10 + (45500 - 11950) * 0.15 +
(117450 - 45500) * 0.25 + (190200 - 117450) * 0.28 +
(372950 - 190200) * 0.33 + (income - 372950) * 0.35;
}

// Displays invalid status if user enters wrong status


else{
System.out.println("Invalid status Entered");
System.exit(1);
}

// Shows the result


System.out.println("Tax is " + (tax * 100) / 100.0);
}
}

You might also like