Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- int salary;
- int serial;
- int numOfWords;
- String name;
- Scanner s1 = new Scanner(System.in);
- System.out.println("are you a secratry or a programmer? ENTER: S/P");
- char type = s1.next().charAt(0);
- if ((type == 'S')||(type == 's')){
- System.out.println("please enter name, serial number, your salary, and number of words per minute");
- name = s1.next();
- serial = s1.nextInt();
- salary = s1.nextInt();
- numOfWords = s1.nextInt();
- Employee S1 = new Secratry(name, serial, salary, numOfWords);
- System.out.println(S1);
- }
- else if ((type == 'P')||(type == 'p')) {
- System.out.println("please enter name, serial number, your salary");
- name = s1.next();
- serial = s1.nextInt();
- salary = s1.nextInt();
- Employee P1 = new Programmer(name, serial, salary);
- System.out.println(P1);
- }
- else
- System.out.println("not employee");
- }
- }
- package com.company;
- public class Employee {
- private String name;
- int serial, salary;
- public Employee(String name, int serial, int salary) {
- this.name = name;
- this.serial = serial;
- this.salary = salary;
- }
- public String toString() {
- return "employee name: " + name + " , serial number: " + serial + " , salary: " + salary;
- }
- public int calcBonus() {
- return 0;
- }
- public void updateSalary(int salary){
- this.salary+=salary;
- }
- }
- package com.company;
- public class Programmer extends Employee {
- public Programmer(String name, int serial, int salary) {
- super(name, serial, salary);
- }
- public int calcBonus(){
- return this.salary= salary + salary/2;
- }
- public String toString(){
- return super.toString()+ " new salary after bonus is: " + calcBonus();
- }
- }
- package com.company;
- public class Secratry extends Employee {
- int numOfWords;
- public Secratry(String name, int serial, int salary,int numOfWords) {
- super(name, serial, salary);
- this.numOfWords=numOfWords;
- }
- public int calcBonus(){
- return this.salary=salary+500;
- }
- public String toString(){
- return super.toString()+ " number of words per minute: " + numOfWords + " new salary after bionus: " +calcBonus() ;
- }
- }
Add Comment
Please, Sign In to add comment