Mutator methods

Discussion in 'Java' started by john21, Nov 20, 2020.

Tags:
  1. john21

    john21 New Member

    Joined:
    May 30, 2020
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Male
    Hey guys I wrote this Java program but the problem is that I need to fix the mutator methods (with something like public void set...). Please can someone add them in for me I would be forever grateful.

    Code:
    import java.util.*;
    
    public class MainDemo {
        public static void main(String[] args){
                 //Initialization Code....
        }
    }
    class Employee{
        int empID;
        String eFirstname;
        String eLastname;
        String email;
        String position;
        String username;
        String password;
        Employee( ){
            System.out.println("Employee Class Constructor"); 
        }
        @Override
        public String toString(){
            String s1= "empID: "+empID+"\neFirstname: "+eFirstname+"\neLastname: "+eLastname+"\nemail: "+email;
            String s2="\nposition: "+position+"\nusername: "+username+"\npassword: "+password; 
            return s1+s2;
        }
        void empSet(){
            //Mutator method
            System.out.println("Enter Employee Details:");
            Scanner sc = new Scanner(System.in);
            System.out.println("empID, Firstname, Lastname, email, position, username, password");
            this.empID = sc.nextInt();
            this.eFirstname = sc.next();
            this.eLastname = sc.next();
            this.email = sc.next();
            this.position = sc.next();
            this.username = sc.next();
            this.password = sc.next();
        }
        void empGet(){
            //Accessor Method
            System.out.println(this.toString());
        }
    }
    class GeneralManager extends Employee{
        String cellPhone;
        double monthlySalary;
        GeneralManager(){
            System.out.println("General Manager Class Constructor");
        }
        void SetGM(){
            this.empSet();
            //Mutator Method
            System.out.println("Enter GeneralManager extra details:");
            Scanner sc = new Scanner(System.in);
            System.out.println("cellPhone, monthlysalary");
            this.cellPhone = sc.next();
            this.monthlySalary = sc.nextDouble();
        }
        void getGM(){
            //Accessor Method     
            System.out.println(this.toString());
        }
        @Override
        public String toString(){
            return super.toString()+"\ncellPhone: "+this.cellPhone+"\nmonthlySalary: "+this.monthlySalary;
        }
    }
    class SecurityOfficer extends Employee{
       boolean fiearmLicence;
       double hourlyRate;
        SecurityOfficer(){
            System.out.println("SecurityOfficer Class Constructio");
        }
        void setSO(){
            this.empSet();
            //Mutator Method
            System.out.println("Enter SecurityOfficer extra details:");
            Scanner sc = new Scanner(System.in);
            System.out.println("fiearmLicence, hourlyRate");
            this.fiearmLicence = sc.nextBoolean();
            this.hourlyRate = sc.nextDouble();
        }
        void getAC(){
            System.out.println(this.toString());
        }
        @Override
        public String toString(){
            return super.toString()+"\nfiearmLicence: "+this.fiearmLicence+"\nhourlyRate: "+this.hourlyRate;
        } 
    }
    class AdminClerk extends Employee{
        double weeklywage;
        AdminClerk(){
            System.out.println("AdminClerk Class Constructio");
        }
        void setAC(){
            this.empSet();
            //Mutator Method
            System.out.println("Enter GeneralManager extra details:");
            Scanner sc = new Scanner(System.in);
            System.out.println("weeklywage");
            this.weeklywage = sc.nextDouble();
      
        }
        void getAC(){
            System.out.println(this.toString());
        }
        @Override
        public String toString(){
            return super.toString()+"\nWeeklywage:"+this.weeklywage;
        } 
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice