Define a class IncomeTax having the following description:
Data members/instance variables
int pan - to store permanent account number
String name - to store name of person
int income - to store annual income of the person
double tax - to store tax to be paid by the person
Member functions:
IncomeTax () -- constructor to initialize pan as 0, name as null and income as 0
input() - to accept pan, name and income.
calculate() - to calculate tax for a person as per following condition
Total Income Tax (in %)
Less than Rs. 200000 8%
Rs. 200001 to Rs. 500000 15%
Rs. 500001 to Rs. 100000 25%
Above Rs. 100000 30%
display()- To display the details.
Create an object in the main() method and invoke the above function to perform the above work.
import java.util.Scanner;
class IncomeTax {
private int pan;// - to store permanent account number
private String name;// - to store name of person
private int income;// - to store annual income of the person
private double tax;// - to store tax to be paid by the person
// Member functions:
/**
* constructor to initialize pan as 0, name as null and income as 0
*/
public IncomeTax() {
this.pan = 0;
this.name = null;
this.income = 0;
}
/**
* input() - to accept pan, name and income.
*/
public void input() {
Scanner keyBoard = new Scanner(System.in);
System.out.print("Enter pan: ");
pan = keyBoard.nextInt();
keyBoard.nextLine();
System.out.print("Enter name: ");
name = keyBoard.nextLine();
System.out.print("Enter income: ");
income = keyBoard.nextInt();
keyBoard.close();
}
/**
* calculate() - to calculate tax for a person as per following condition Total
* Income Tax (in %) Less than Rs. 200000 8% Rs. 200001 to Rs. 500000 15% Rs.
* 500001 to Rs. 100000 25% Above Rs. 100000 30%
*
* @return
*/
public double calculate() {
if (income <= 200000) {
return (double) income * 0.08;
}
if (income >= 200001 && income <= 500000) {
return (double) income * 0.15;
}
if (income >= 500001 && income <= 100000) {
return (double) income * 0.25;
}
return (double) income * 0.30;
}
/**
* display()- To display the details.
*
*/
public void display() {
System.out.println("Pan: " + pan);
System.out.println("Name: " + name);
System.out.println("Income: " + income);
System.out.printf("Total Income Tax: %.2f\n\n", calculate());
}
}
public class App {
public static void main(String[] args) {
// Create an object in the main() method and invoke the above function to
// perform the above work.
IncomeTax IncomeTax = new IncomeTax();
IncomeTax.input();
IncomeTax.display();
}
}
Comments
Leave a comment