473,287 Members | 1,426 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

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.

Expand|Select|Wrap|Line Numbers
  1. class Empleado {
  2. public static void main(String[] arg){}
  3.     private String RFC;
  4.     private String nombre;
  5.     private String apellidos;
  6.     private String domicilio;
  7.     private String codigoPostal;
  8.     private String ciudad;
  9.     private PuestoTrabajo puestoTrabajo;
  10.     public Empleado(String RFC, String nombre, String apellidos, String domicilio, String codigoPostal, String ciudad, PuestoTrabajo puestoTrabajo)
  11.     {
  12.         this.RFC = RFC;
  13.         this.nombre = nombre;
  14.         this.apellidos = apellidos;
  15.         this.domicilio = domicilio;
  16.         this.codigoPostal = codigoPostal;
  17.         this.ciudad = ciudad;
  18.         this.PuestoTrabajo = puestoTrabajo;
  19.         Empleado empleado1 = new Empleado("qwerty1", "juan", "Garcia", "calle 3", "53700", "MEXICO", puesto1);
  20.         Empleado empleado1 = new Empleado("qwerty1", "maria", "barrera", "calle456", "53700", "Puebla", puesto2);
  21.  
  22.     }
  23. }
  24. class PuestoTrabajo {
  25.     private String codigo;
  26.     private String descripcion;
  27.     private double sueldoBruto;
  28.     public PuestoTrabajo(String codigo, String descripcion, double sueldoBruto)
  29.     {
  30.         this.codigo = codigo;
  31.         this.descripcion = descripcion;
  32.         this.sueldoBruto = sueldoBruto;        
  33.         PuestoTrabajo puesto1 = new PuestoTrabajo("P001", "Programador", 400);
  34.     }
  35.     public String getDescripcion(){
  36.         return descripcion;
  37.     }
  38. }
  39.  
  40. class Consultor extends Empleado 
  41. {
  42.     public Consultor(String RFC, String nombre, String apellidos, String domicilio, String codigoPostal, String ciudad)
  43.     {
  44.         super(RFC, nombre, apellidos, domicilio, codigoPostal, ciudad, puestoTrabajo);
  45.         this.categoriaProfesional = categoriaProfesional;
  46.         Consultor consultor = new Consultor(empleado1, puesto1, "Senior", 5);
  47.     }
  48. }
  49. class Administrativo extends Empleado
  50. {
  51.     private int Antiguedad;
  52.     public Administrativo(String RFC, String nombre, String apellidos, String domicilio, String codigoPostal, String ciudad, PuestoTrabajo puestoTrabajo, int Antiguedad)
  53.     {
  54.     super(RFC, nombre, apellidos, domicilio, codigoPostal, ciudad, puestoTrabajo);
  55.     this.Antiguedad = Antiguedad;
  56.     Administrativo admin = new Administrativo("qwerty1", "maria", "barrera", "calle456", "53700", "Puebla", puesto2, 5);
  57.     }
  58. }
  59.  
  60.  
This is the error that given the CMD
Expand|Select|Wrap|Line Numbers
  1. symbol: variable JobPosition
  2. Employee.java:20: error: cannot find symbol
  3.  
  4.   symbol: variable position1
  5.    location: class Employee
  6.  
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
Feb 2 '23 #1
1 12909
junfeng
2 2Bits
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("qwerty1", "juan", "Garcia", "calle 3", "53700", "MEXICO", puesto1);
Empleado empleado1 = new Empleado("qwerty1", "maria", "barrera", "calle456", "53700", "Puebla", puesto2);

you can use an ide , for example Intelli IDEA , to make it easy to find errors.
Feb 24 '23 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ben | last post by:
Hi all, This may sound easy but I'm having trouble assigning values to array element. My problem is as follows: m = for o in m: # Here first o is 'Peter'.. I want to do something like this:...
1
by: ajit goel | last post by:
Hi; I have a question which respect to initialising and creating objects in loops.Here are the 2 scenarios: 1. ###############################################################################...
14
by: Eric Bantock | last post by:
Very basic question I'm afraid. Once an array has been declared, is there a less tedious way of assigning values to its members than the following: myarray=8; myarray=3; myarray=4; myarray=0;...
2
by: Jim | last post by:
I have some complex (fairly) user controls that I have created. Some of those user controls host other user controls. When I host one of these on a WinForm, I sometimes run into problems where...
1
by: chris | last post by:
I know I've asked this before, but I didn't really get an answer and I bet it's because I didn't explain myself very well. Here goes again. I have this code: Dim arrData(intNoOfRows,...
3
by: Richard Thornley | last post by:
Hello, I need some clarification in creating objects. Consider the following code... (note: The function InitializeListCombo initializes the combobox) Private daLists As New...
31
by: JoeC | last post by:
I have read books and have ideas on how to create objects. I often create my own projects and programs. They end up getting pretty complex and long. I often use objects in my programs they are...
5
by: Manuel Graune | last post by:
Hello, while trying to learn how to program using objects in python (up to now simple scripts were sufficient for my needs) I stumbled over the a problem while assigning values to an object. ...
17
by: Cliff | last post by:
Hi, I'm in the process of porting some code from a 3rd party and have hit a problem with the following: typedef struct { unsigned char Red; unsigned char Green; unsigned char Blue;...
43
by: emyl | last post by:
Hi all, here's an elementary question. Assume I have declared two variables, char *a, **b; I can then give a value to a like a="hello world";
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.