Computer Science, asked by roopsaikatta04, 6 months ago

Write a program which prints the following information about at least 5 persons:
NAME MAIL-ID EMPLOYEE-CODE PHONE
Eg. Umesh umesh@cse p03161 25764728
Salil salil@cse p03160 25764728
Each entry should be on a separate line. in java program ​

Answers

Answered by amikkr
0

The code would look something like this in java:

public class Person {

   // Declare variables to store the person's name, email, employee code, and phone number

   private String name;

   private String mailId;

   private String employeeCode;

   private String phone;

   // Constructor to create a new Person object with the specified name, email, employee code, and phone number

   public Person(String name, String mailId, String employeeCode, String phone) {

       this.name = name;

       this.mailId = mailId;

       this.employeeCode = employeeCode;

       this.phone = phone;

   }

   // Getter method to retrieve the name of the person

   public String getName() {

       return name;

   }

   // Getter method to retrieve the email of the person

   public String getMailId() {

       return mailId;

   }

   // Getter method to retrieve the employee code of the person

   public String getEmployeeCode() {

       return employeeCode;

   }

   // Getter method to retrieve the phone number of the person

   public String getPhone() {

       return phone;

   }

}

public class Main {

   public static void main(String[] args) {

       // Create Person objects for 5 people

       Person person1 = new Person("Umesh", "umesh@cse", "p03161", "25764728");

       Person person2 = new Person("Salil", "salil@cse", "p03160", "25764728");

       Person person3 = new Person("John", "john@cse", "p03162", "25764729");

       Person person4 = new Person("Jane", "jane@cse", "p03163", "25764730");

       Person person5 = new Person("Michael", "michael@cse", "p03164", "25764731");

       // Put the Person objects into an array

       Person[] people = {person1, person2, person3, person4, person5};

       // Loop through the array of Person objects and print the name, email, employee code, and phone number for each person

       for (Person person : people) {

           System.out.println(person.getName() + " " + person.getMailId() + " " + person.getEmployeeCode() + " " + person.getPhone());

       }

   }

}

#SPJ1

Similar questions