calculateSalary() and displayInfo(). Create subclasses Manager and Programmer that extend the Employee class
and implement the respective methods to
calculate salary and display information for each role*/
import java.util.*;
abstract class Employee{
public abstract void calculateSalary();
public abstract void displayInfo();
}
class Manager extends Employee{
int sal;
double per;
double tot;
Manager(int sal,double per){
this.sal=sal;
this.per=per;
}
@Override
public void calculateSalary(){
System.out.println("sal"+sal);
tot=sal+sal*per;
}
@Override
public void displayInfo(){
System.out.println(tot);
}
}
class Programmer extends Employee{
int sal;
double pere;
double tote;
Programmer(int sal,double pere){
System.out.println("sal"+sal);
this.sal=sal;
this.pere=pere;
}
@Override
public void calculateSalary(){
tote=sal+sal*pere;
}
@Override
public void displayInfo(){
System.out.println(tote);
}
}
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int salm=sc.nextInt();
int salp=sc.nextInt();
double per=sc.nextDouble();
Manager m=new Manager(salm,per);
Programmer p= new Programmer(salp,per);
m.calculateSalary();
m.displayInfo();
p.calculateSalary();
m.displayInfo();
}
}
#Abstract
1 messages · Page 1 of 1 (latest)
Detected code, here are some useful tools:
Formatted code
/*Write a Java program to create an abstract class Employee with abstract methods
calculateSalary() and displayInfo(). Create subclasses Manager and Programmer that extend the Employee class
and implement the respective methods to
calculate salary and display information for each role*/
import java.util. * ;
abstract class Employee {
public abstract void calculateSalary();
public abstract void displayInfo();
}
class Manager extends Employee {
int sal;
double per;
double tot;
Manager(int sal, double per) {
this .sal = sal;
this .per = per;
}
@Override
public void calculateSalary() {
System.out.println("sal" + sal);
tot = sal + sal * per;
}
@Override
public void displayInfo() {
System.out.println(tot);
}
}
class Programmer extends Employee {
int sal;
double pere;
double tote;
Programmer(int sal, double pere) {
System.out.println("sal" + sal);
this .sal = sal;
this .pere = pere;
}
@Override
public void calculateSalary() {
tote = sal + sal * pere;
}
@Override
public void displayInfo() {
System.out.println(tote);
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int salm = sc.nextInt();
int salp = sc.nextInt();
double per = sc.nextDouble();
Manager m = new Manager(salm, per);
Programmer p = new Programmer(salp, per);
m.calculateSalary();
m.displayInfo();
p.calculateSalary();
m.displayInfo();
}
}
<@&987246399047479336> please have a look, thanks.
hi, what is your question?
The questio is there in the comments
well thats not a question, thats a task instead
we are not a code writing service
instead we help you do it yourself
so where are you stuck doing that task?
/Write a Java program to create an abstract class Employee with abstract methods
calculateSalary() and displayInfo(). Create subclasses Manager and Programmer that extend the Employee class
and implement the respective methods to
calculate salary and display information for each role/
yes?
thats still a task
not a question
and as I said we are not a code writing service
instead ask a question
so we can help
Well that’s the entire task, did you set up a IDE?
I have written the code
What’s the error?
There's no error
...
The output of the salary should be different as the salary of manager and progammer are different
(the first two lines)