Solved

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

Posted on 2016-09-29
1
45 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
1 Comment
 
LVL 15

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now