Solved

Core java. Create the class with method that do logic for all elements of collection.

Posted on 2016-09-29
1
122 Views
Last Modified: 2016-10-17
Let there is pretty straightforward classes

public class Employees {
    String lastName;

    Employees(String lastName, int salary) {
        this.lastName = lastName;
        this.salary = salary; 

    }

    public String getLastName() {
        return lastName;
    }
}

public class EmployeesTest {

    public static void main(String[] args) { 
        new Employees("Smith", 60000);
        new Employees("Page", 75000);
        new Employees("Musk", 88000);
        new Employees("Dorsy",55000);
        new Employees("Gates",54000);
       
    }
}

Open in new window


I need to create some method that for example increase salary for all employees of the collection.
0
Comment
Question by:SunnyX
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 16

Accepted Solution

by:
gurpsbassi earned 500 total points
ID: 41821526
some initial observations:

your class should be called "Employee" not "Employees"

you need an instance variable for salary.

Make your instance variables private.


If salary can be changed, you need a setSalary(..) method on your class.

You would then simply either loop the collection or stream it and set the salary for each employee
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jboss wildfly 10.1 10 617
ejb stateless example 2 68
JavaFX TableView not displaying correctly 3 161
junit as external jar or library 7 58
Article by: Nadia
Suppose you use Uber application as a rider and you request a ride to go from one place to another. Your driver just arrived at the parking lot of your place. The only thing you know about the ride is the license plate number. How do you find your U…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question