Search This Blog

Monday, December 27, 2010

Define class salary with given data members & member methods - ICSE BOARD QUESTION 2007

/**
 * Define a class salary  - ICSE BOARD QUESTION 2007
 */ 
import java.io.*;   
class questionFOUR2007
{
    public static void main(String args[]) throws IOException
    {
        salary ob=new salary();
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
       
        System.out.println("Enter the NAME of the teacher ");
        String name=br.readLine();
       
        System.out.println("Enter the ADDRESS of the teacher ");
        String address=br.readLine();
       
        System.out.println("Enter the PHONE number");
        int phone=Integer.parseInt(br.readLine());
       
        System.out.println("Enter the SUBJECT SPECIALISATION ");
        String subject=br.readLine();
       
        System.out.println("Enter the monthly salary ");
        double salary=Double.parseDouble(br.readLine());
       
        ob.accept(name, address, phone, subject, salary);
        ob.compute();
        ob.display();
    }
}
class salary
{
    String name,address, subject;
    int phone;
    double salary;
    double tax=0.0;
    void accept(String n, String add, int ph, String sub, double sal)
    {
        name=n;
        address=add;
        phone=ph;
        subject= sub;
        salary=sal;
      
    }
    void compute()
    {
        double annualsalary=salary*12;  //annual salary
        tax=0.05*(annualsalary-175000);
    }
    void display()
    {
        System.out.println("NAME \t ADDRESS \t PHONE \t SUBJECT SPECIALISATION \t MONTHLY SALARY \t INCOME TAX ");
        System.out.println( name + "\t" + address + "\t" + phone + "\t" + subject + "\t" + salary + "\t" + tax);
    }
}
   
OUTPUT:
Enter the NAME of the teacher
AMAN
Enter the ADDRESS of the teacher
CHANDIGARH
Enter the PHONE number
98157
Enter the SUBJECT SPECIALISATION
MBA FINANCE
Enter the monthly salary
90000
NAME      ADDRESS      PHONE      SUBJECT SPECIALISATION    SALARY     INCOME TAX
AMAN    CHANDIGARH    98157    MBA FINANCE                           90000.0          45250.0

No comments:

Post a Comment