Java Basics Lab 01
Java Basics Lab 01
Question 01
Advance Personal Income Tax (APIT) Calculator
In Sri Lanka, employed individuals are subject to Advance Personal Income Tax (APIT)
on their monthly income. The tax is calculated using a progressive tax slab system
where different portions of income are taxed at different rates.
For example, for someone who earns 200,000 LKR, they will be taxed for each tax
slab(100-141,141-183,183-200) separately and the sum will be the total tax amount.
If you are unsure, you can use this tool to see how to calculate the tax amount. The goal
is to write a program that functions in a similar way.
Write a Java program named APitCalculator that calculates the Advance Personal
Income Tax for a given monthly income. The program should:
1. Prompt the user to enter their total monthly employment income (salary plus
allowances)
2. Calculate the tax payable for each tax slab
3. Calculate the total tax payable
4. Calculate the effective tax rate (total tax / monthly income) as a percentage
5. Calculate the salary after tax
6. Display the results
Write a program called ReverseString, which prompts user for a String, and prints the
reverse of the String by extracting and processing each character. The output shall look
like
Hints
For a String called inStr, you can use inStr.length() to get the length of the String; and
inStr.charAt(idx) to retrieve the char at the idx position, where idx begins at 0, up to
instr.length() - 1.
// Define variables
String inStr; // input String
int inStrLen; // length of the input String
......
// Prompt and read input as "String"
System.out.print("Enter a String: ");
inStr = in.next(); // use next() to read a String
inStrLen = inStr.length();
// Use inStr.charAt(index) in a loop to extract each character
// The String's index begins at 0 from the left.
// Process the String from the right
for (int charIdx = inStrLen - 1; charIdx >= 0; --charIdx) {
// charIdx = inStrLen-1, inStrLen-2, ... ,0
......
}