473,503 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating objects and assigning values.

1 New Member
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 13036
junfeng
2 New Member
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
8262
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
1383
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
74755
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
1980
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
1338
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
1581
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
3148
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
1639
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
18735
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
17163
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";
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6982
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5572
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.