[Go to site: main page, start]

0% found this document useful (0 votes)
18 views5 pages

Programa de Aumento Salarial de Funcionários

Uploaded by

valentimmorais81
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views5 pages

Programa de Aumento Salarial de Funcionários

Uploaded by

valentimmorais81
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Fazer um programa para ler um número inteiro N e depois os dados (id, nome e salario) de

N funcionários. Não deve haver repetição de id.


Em seguida, efetuar o aumento de X por cento no salário de um determinado funcionário.
Para isso, o programa deve ler um id e o valor X. Se o id informado não existir, mostrar uma
mensagem e abortar a operação. Ao final, mostrar a listagem atualizada dos funcionários,
conforme exemplos.
Lembre-se de aplicar a técnica de encapsulamento para não permitir que o salário possa
ser mudado livremente. Um salário só pode ser aumentado com base em uma operação de
aumento por porcentagem dada.
How many employees will be registered? 3

Emplyoee #1:
Id: 333
Name: Maria Brown
Salary: 4000.00

Emplyoee #2:
Id: 536
Name: Alex Grey
Salary: 3000.00

Emplyoee #3:
Id: 772
Name: Bob Green
Salary: 5000.00

Enter the employee id that will have salary increase : 536


Enter the percentage: 10.0

List of employees:
333, Maria Brown, 4000.00
536, Alex Grey, 3300.00
772, Bob Green, 5000.00

How many employees will be registered? 2

Emplyoee #1:
Id: 333
Name: Maria Brown
Salary: 4000.00

Emplyoee #2:
Id: 536
Name: Alex Grey
Salary: 3000.00

Enter the employee id that will have salary increase: 776


This id does not exist!

List of employees:
333, Maria Brown, 4000.00
536, Alex Grey, 3000.00

Entrar no Eclipse e criar um programa principal no Package application.


package application;

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

public class Program {

public static void main(String[] args) {

[Link]([Link]);

Scanner sc = new Scanner([Link]);

List<Employee> list = new ArrayList<>();

// PART 1 - READING DATA:

[Link]("How many employees will be registered? ");

int n = [Link]();

for (int i=1; i<=n; i++) {

[Link]();

[Link]("Employee #" + i + ": ");

[Link]("Id: ");

int id = [Link]();

while (hasId(list, id)) {

[Link]("Id already taken. Try again: ");

id = [Link]();

[Link]("Name: ");

[Link]();

String name = [Link]();

[Link]("Salary: ");
double salary = [Link]();

[Link](new Employee(id, name, salary));

// PART 2 - UPDATING SALARY OF GIVEN EMPLOYEE:

[Link]();

[Link]("Enter the employee id that will have salary increase: ");

int id = [Link]();

Employee emp = [Link]().filter(x -> [Link]() == id).findFirst().orElse(null);

if (emp == null) {

[Link]("This id does not exist!");

else {

[Link]("Enter the percentage: ");

double percentage = [Link]();

[Link](percentage);

// PART 3 - LISTING EMPLOYEES:

[Link]();

[Link]("List of employees:");

for (Employee obj : list) {

[Link](obj);

[Link]();

public static boolean hasId(List<Employee> list, int id) {

Employee emp = [Link]().filter(x -> [Link]() == id).findFirst().orElse(null);

return emp != null;


}

Criar uma classe Employee no Package entities

package entities;

public class Employee {

private Integer id;

private String name;

private Double salary;

public Employee() {

public Employee(Integer id, String name, Double salary) {

[Link] = id;

[Link] = name;

[Link] = salary;

public Integer getId() {

return id;

public void setId(Integer id) {

[Link] = id;

public String getName() {

return name;

public void setName(String name) {

[Link] = name;

public Double getSalary() {

return salary;

public void setSalary(Double salary) {

[Link] = salary;
}

public void increaseSalary(double percentage) {

salary += salary * percentage / 100.0;

public String toString() {

return id + ", " + name + ", " + [Link]("%.2f", salary);

Common questions

Powered by AI

In the Employee class, constructors initialize new instances of the class with specific attributes. The program defines two constructors: a default no-argument constructor and another that takes parameters for the ID, name, and salary. The parameterized constructor is used to set up new Employee objects with specific initial values when they are added to the employee list. This ensures that every employee in the system is instantiated with complete and consistent information .

The program ensures encapsulation by using a private modifier for the salary attribute within the Employee class. Direct modifications of the salary are not allowed. Instead, any changes to an employee's salary must occur through a controlled method, specifically 'increaseSalary', which implements the logic to increase the salary by a certain percentage. This encapsulation protects the integrity of salary modifications by preventing unauthorized or incorrect updates .

Without proper encapsulation, an employee management program could face several issues, including: 1) Directly modifiable salary and other sensitive data, leading to inconsistent or unauthorized changes without any validation. 2) Increased risk of data corruption, as there would be no control over the format, range, or type of modifications made. 3) Difficulty in debugging and maintenance, since changes in data might not be traceable to specific actions or functions. Such a lack of control could compromise data integrity and security, negatively impacting the reliability of the system overall .

Encapsulation is crucial in managing employee data because it ensures that sensitive data, such as salaries, cannot be altered arbitrarily, maintaining data integrity and security. In the program, encapsulation is implemented by keeping the salary attribute private and only allowing changes through a specific method (increaseSalary) that defines how salaries can be increased. This prevents direct access to modify the salary attribute, enforcing controlled access through well-defined interfaces .

The program ensures data integrity in several ways: 1) During registration, it avoids duplicate IDs using a check mechanism that prevents adding employees with existing IDs. 2) It encapsulates attributes like salary, preventing arbitrary modifications and only allowing them through defined methods like 'increaseSalary'. 3) It uses descriptive prompts and feedback to guide users through correct processes, such as indicating errors when invalid IDs are entered for salary updates. These features collectively maintain consistent, accurate, and reliable employee records .

For handling salary increases, the program first prompts the user to enter the ID of the employee whose salary is to be increased. It then checks the list for the presence of this ID. If found, the program asks for the percentage increase and calls the 'increaseSalary' method on the matched employee object. This method calculates the new salary by adding the specified percentage increase to the current salary .

The program addresses errors when updating employee salaries by first checking if the ID provided exists in the employee list. If the ID does not exist, it communicates this to the user by displaying an error message: 'This id does not exist!' and aborts the operation. This approach prevents incorrect salary updates and educates the user about the input issue, ensuring only valid operations proceed. The error handling is user-friendly and helps maintain the integrity of operations by preventing erroneous data entries .

To ensure no duplicate employee IDs, the program should use a method to check if the ID already exists in the list. Specifically, before adding a new employee, the program asks for the ID and checks its uniqueness using the 'hasId' method. This method filters through the list of already registered employees to determine if the ID is present, returning true if it exists and thus prompting the user to input another ID if necessary .

The current implementation of the employee management program may have limitations in terms of scalability and user interaction. As the number of employees grows, performance could be impacted due to the linear search method (hasId) used for verifying unique IDs. User interaction is based solely on console inputs, which is not ideal for larger systems or user-friendliness, as graphical interfaces might be preferred. Additionally, error handling is basic, and more sophisticated mechanisms might be needed for a larger, multi-user environment (e.g., concurrent access issues). These limitations could affect the program's efficiency and ease of use as the scale grows .

The key steps in updating an employee's salary based on user input are: 1) Prompt the user to enter the employee ID; 2) Check if the employee exists using that ID by filtering through the list; 3) If the ID does not exist, notify the user with a message and abort the update; 4) If the ID exists, prompt the user to enter the percentage increase; and 5) Call the 'increaseSalary' method on the Employee object to update the salary accordingly .

You might also like