#Abstract

1 messages · Page 1 of 1 (latest)

red helm
#
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();
        
    }
}
median topazBOT
# red helm ```/*Write a Java program to create an abstract class Employee with abstract met...

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.

stone yarrow
#

hi, what is your question?

red helm
#

The questio is there in the comments

stone yarrow
#

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?

red helm
# stone yarrow well thats not a question, thats a task instead

/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
/

stone yarrow
#

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

red helm
ancient sleet
#

Well that’s the entire task, did you set up a IDE?

red helm
#

I have written the code

red helm
# red helm

I'm getting the same output for both manager and programmer's salary

ancient sleet
#

What’s the error?

red helm
#

There's no error

red helm
#

The output of the salary should be different as the salary of manager and progammer are different

#

(the first two lines)

sonic reef
#

you're displaying the manager twice

#

m.displayInfo()

#

@red helm

#
m.calculateSalary();
m.displayInfo();
p.calculateSalary();
m.displayInfo(); // should be p.displayInfo()```
red helm
#

Ohhhh my god

#

Understood

#

Thank you soo much