Solved

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

Posted on 2016-09-29
1
90 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Iteration: Iteration is repetition of a process. A student who goes to school repeats the process of going to school everyday until graduation. We go to grocery store at least once or twice a month to buy products. We repeat this process every mont…
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 the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

856 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