Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

932 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

18 Experts available now in Live!

Get 1:1 Help Now