package com.mycompany.testoop; import java.util.ArrayList; import java.util.Scanner; public class Main { static Scanner in = new Scanner(System.in); public static void main(String args[]){ Employees [] ourEmployees = new Employees[] {new Employees(), new Employees(), new Employees(), new Employees()}; for(int i=0; i<4; i++){ ourEmployees[i].setId(in.nextInt()); ourEmployees[i].setName(in.next()); ourEmployees[i].setSalary(in.nextFloat()); } for (int i=0; i<4; i++){ System.out.println("Employee #" + (i+1) + " ==> " + "ID = " + ourEmployees[i].getId() + ", Name = " + ourEmployees[i].getName() + ", Salary = " + ourEmployees[i].getSalary()); } } } package com.mycompany.testoop; public class Employees { private int id; private String name; private float salary; // ****************Constructors******************* public Employees() { } public Employees(int id, String name, float salary) { this.id = id; this.name = name; this.salary = salary; } // ****************Setters & Getters******************* public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public float getSalary() { return salary; } public void setSalary(float salary) { this.salary = salary; } // ****************Our Methods******************* @Override public String toString() { return "ID = " + id + ", Name = " + name + ", Salary = " + salary; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter