Creating objects and assigning values.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jesuscortes0
    New Member
    • Feb 2023
    • 1

    Creating objects and assigning values.

    Hello in my online university center, they gave me this challenge in Java.

    1. Declare an Employee class with String attributes for RFC, first name, last name, street address, postal code, and city. This class must include the object type job attribute of the JobPost class. Declare the JobPost class with String attributes for: code and description and a double attribute for the gross salary. Develop the constructor method in the declaration of both classes.

    2. Develop a Java program that instantiates at least two objects of the Employee class declared in question 1.

    3. Declare the Administrative and Consultant derived classes of the Employee class. The Administrative class has an attribute of type int for seniority. The Consultant class has a String attribute for the professional category. Develop the constructor method in the declaration of both classes. This method must call the constructor of the base class.

    4. Develop a Java program that instantiates an object of the Administrative and Consultant classes declared in question 3.

    5. Define the getAttributes() method of the Employee, Administrative and Consultant classes. The getAttributes() method of the Employee class must use the getDescription( ) method to display the job description. Methods

    getAttributes() of the Administrative and Consultant subclasses must override the method of the Employee superclass.

    So it leads me to think that Employee has a job position, and an employee, can be a consultant or an administrator, has seniority, in the end, the result will be displayed in the CMD, in this order, RFC, name, surname, address, Postal code, city, job position, Consultant or administrator, code, description, salary, category and seniority.

    Therefore I have created the classes and objects without any attributes
    They had been declared correctly, when I started giving attributes to objects with single quotes or without quotes. This was giving me errors. In the end this is JAVA source code.

    Code:
    class Empleado {
    public static void main(String[] arg){}
        private String RFC;
        private String nombre;
        private String apellidos;
        private String domicilio;
        private String codigoPostal;
        private String ciudad;
        private PuestoTrabajo puestoTrabajo;
        public Empleado(String RFC, String nombre, String apellidos, String domicilio, String codigoPostal, String ciudad, PuestoTrabajo puestoTrabajo)
        {
            this.RFC = RFC;
            this.nombre = nombre;
            this.apellidos = apellidos;
            this.domicilio = domicilio;
            this.codigoPostal = codigoPostal;
            this.ciudad = ciudad;
            this.PuestoTrabajo = puestoTrabajo;
            Empleado empleado1 = new Empleado("qwerty1", "juan", "Garcia", "calle 3", "53700", "MEXICO", puesto1);
            Empleado empleado1 = new Empleado("qwerty1", "maria", "barrera", "calle456", "53700", "Puebla", puesto2);
     
        }
    }
    class PuestoTrabajo {
        private String codigo;
        private String descripcion;
        private double sueldoBruto;
        public PuestoTrabajo(String codigo, String descripcion, double sueldoBruto)
        {
            this.codigo = codigo;
            this.descripcion = descripcion;
            this.sueldoBruto = sueldoBruto;        
            PuestoTrabajo puesto1 = new PuestoTrabajo("P001", "Programador", 400);
        }
        public String getDescripcion(){
            return descripcion;
        }
    }
    
    class Consultor extends Empleado 
    {
        public Consultor(String RFC, String nombre, String apellidos, String domicilio, String codigoPostal, String ciudad)
        {
            super(RFC, nombre, apellidos, domicilio, codigoPostal, ciudad, puestoTrabajo);
            this.categoriaProfesional = categoriaProfesional;
            Consultor consultor = new Consultor(empleado1, puesto1, "Senior", 5);
        }
    }
    class Administrativo extends Empleado
    {
        private int Antiguedad;
        public Administrativo(String RFC, String nombre, String apellidos, String domicilio, String codigoPostal, String ciudad, PuestoTrabajo puestoTrabajo, int Antiguedad)
        {
        super(RFC, nombre, apellidos, domicilio, codigoPostal, ciudad, puestoTrabajo);
        this.Antiguedad = Antiguedad;
        Administrativo admin = new Administrativo("qwerty1", "maria", "barrera", "calle456", "53700", "Puebla", puesto2, 5);
        }
    }
    This is the error that given the CMD
    Code:
    symbol: variable JobPosition
    Employee.java:20: error: cannot find symbol
    
      symbol: variable position1
       location: class Employee
    This error is repeated up to 10 times. The error is marked in the objects and the statement this and super
    Could you please correct my code or tell me why it marks errors in objects and this and super instructions
  • junfeng
    New Member
    • Feb 2023
    • 2

    #2
    I have try your code in my ide, and found some errors.

    you have define two symbol named [empleado1] . [puesto1] and [puesto2] are not defined yet.

    Empleado empleado1 = new Empleado("qwert y1", "juan", "Garcia", "calle 3", "53700", "MEXICO", puesto1);
    Empleado empleado1 = new Empleado("qwert y1", "maria", "barrera", "calle456", "53700", "Puebla", puesto2);

    you can use an ide , for example Intelli IDEA , to make it easy to find errors.

    Comment

    Working...