these 2 are same questions ..first is algorithm and 2nd is java code..pls help D
ID: 3911536 • Letter: T
Question
these 2 are same questions ..first is algorithm and 2nd is java code..pls help
Design an algorithm to accept income from the user; compute the income tax to be paid and display the income and the tax payable on the screen. 3. Income tax calculation is based on the following table. It is also available at this link: https://www.iras.gov.sg/irashome/Individuals/Locals/Working-Out-Your-Taxes/Income Tax-Rates/ (12 Marks) Chargeable Income Income Tax Rate (%) Gross Tax Payable (S) First $20,000 Next $10,000 200 First $30,000 Next $10,000 200 350 3.50 First $40,000 Next $40,000 550 2,800 First $80,000 Next $40,000 3.350 4,600 11.5 First $120,000 Next $ 40,000 7,950 6,000 15 First $160,000 Next $40,000 13,950 6,800 17 First $200.000 Next $120,000 20,750 21,600 18 42,350 First $320,000 Above $320,000 20Explanation / Answer
Algorithm
Take the values into two arrays
Loop through the arrays and keep adding the relavant tax to a variable
Print the tax
// Code
import java.util.Scanner;
class Main {
public static void main(String[] args) {
// declaring variables
double[] income = new double[]{20000, 30000, 40000, 80000, 120000, 160000, 200000, 320000};
double[] tax = new double[]{0, 2, 3.5, 7, 11.5, 15, 17, 18, 20};
Scanner sc = new Scanner(System.in);
int i;
double diff = 0, chargeable_income, taxDeducted = 0;
System.out.print("Enter the income: $");
chargeable_income = sc.nextDouble();
// this is to keep doing the same thing over and over again as long as the user doesn't enter -1
while (chargeable_income >= 0)
{
diff = 0;
// putting tax into taxDeducted variable
for(i=1; i<8 && income[i] < chargeable_income; i++)
{
diff = income[i] - income[i-1];
taxDeducted += diff*tax[i]*0.01;
}
// some part is still remained to be considered
if(i<8)
{
diff = chargeable_income - income[i-1];
taxDeducted += diff*tax[i]*0.01;
}
else
{
diff = chargeable_income - 321000;
taxDeducted = 42350.0 + diff*tax[i]*0.01;
}
System.out.printf("Tax for $%.2f is $%.2f ",chargeable_income, taxDeducted);
System.out.print(" Enter income again, (-1 to stop the program): $");
chargeable_income = sc.nextDouble();
}
}
}
/*SAMPLE OUTPUT
Enter the income: $ 45000
Tax for $45000.00 is $900.00
Enter income again, (-1 to stop the program): $ 100000
Tax for $100000.00 is $6550.00
Enter income again, (-1 to stop the program): $ -1
*/
Algorithm
Take the values into two arrays
Loop through the arrays and keep adding the relavant tax to a variable
Print the tax
// Code
import java.util.Scanner;
class Main {
public static void main(String[] args) {
// declaring variables
double[] income = new double[]{20000, 30000, 40000, 80000, 120000, 160000, 200000, 320000};
double[] tax = new double[]{0, 2, 3.5, 7, 11.5, 15, 17, 18, 20};
Scanner sc = new Scanner(System.in);
int i;
double diff = 0, chargeable_income, taxDeducted = 0;
System.out.print("Enter the income: $");
chargeable_income = sc.nextDouble();
// this is to keep doing the same thing over and over again as long as the user doesn't enter -1
while (chargeable_income >= 0)
{
diff = 0;
// putting tax into taxDeducted variable
for(i=1; i<8 && income[i] < chargeable_income; i++)
{
diff = income[i] - income[i-1];
taxDeducted += diff*tax[i]*0.01;
}
// some part is still remained to be considered
if(i<8)
{
diff = chargeable_income - income[i-1];
taxDeducted += diff*tax[i]*0.01;
}
else
{
diff = chargeable_income - 321000;
taxDeducted = 42350.0 + diff*tax[i]*0.01;
}
System.out.printf("Tax for $%.2f is $%.2f ",chargeable_income, taxDeducted);
System.out.print(" Enter income again, (-1 to stop the program): $");
chargeable_income = sc.nextDouble();
}
}
}
/*SAMPLE OUTPUT
Enter the income: $ 45000
Tax for $45000.00 is $900.00
Enter income again, (-1 to stop the program): $ 100000
Tax for $100000.00 is $6550.00
Enter income again, (-1 to stop the program): $ -1
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.