• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to call sun class method calculate()  RSS feed

 
TahirAhmad Dar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.util.*;
class Employee {
String name;
int emp_id;
String desig;
int dept_id;
float basicsal;
float totalsal;
String deptname;
void setData(String n,int eid,String des,int did,float bs,String dname){
name=n;
emp_id=eid;
desig=des;
dept_id=did;
basicsal=bs;
deptname=dname;
}
float calculate(){
totalsal=basicsal*1.10f*1.10f;
return totalsal;
}
void display(){
System.out.println("Total sal="+totalsal);
}
}
class Production extends Employee{
float claculate(){
totalsal=basicsal+1.20F*1.20F;
System.out.print(" I am in prod");
return totalsal;
}
}

public class EmpInherit{
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
Employee[] e = new Employee[2];
Production[] p=new Production[2];
for(int ii=0;ii<2;ii++){
e[ii]=new Employee();
System.out.printf("Enter Name of Employee");
String s=in.nextLine();
System.out.printf("Enter ID of EMP:");
int i=in.nextInt();
in.nextLine();
System.out.printf("Enter designation");
String str=in.nextLine();
System.out.printf("Enter Deptname: ");
String dn=in.nextLine();
System.out.printf("Enter Dept number");
int dno=in.nextInt();
System.out.printf("Enter Basic salary");
float bsal=in.nextFloat();

if(dn.equals("Prod")){
p[ii]=new Production();
p[ii].setData(s,i,str,dno,bsal,dn);
System.out.println("the salary is: "+p[ii].calculate());
}
else{
e[ii].setData(s,i,str,dno,bsal,dn);
}

float t=e[ii].calculate();
System.out.printf("The Gross Salary is : %f",t);
in.nextLine();
System.out.println();
}
}
}


 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I put code tags around your java which makes it MUCH easier to read.

So...is there an actual question here?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!