Question

In: Computer Science

Write a class named ContactEntry that has fields for a person’s name, phone number and email...

Write a class named ContactEntry that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five ContactEntry objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to demonstrate that it works. I repeat, NO-ARG constructors. This is imperative!!

Solutions

Expert Solution

Hello

To call a method without using or creatin object or without writing no arg constructo we can declare that method as static and then call it by using name of the method

In below code i have create a method called show detail which will display all the objects stored in arraylist

In below code i didnot create NO ARG Constructor

I am also sharing Screenshot of the code and result

/////

ContactEntry.java

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ContactEntry {
   String PersonsName;
   String Phone;
   String Email;
  
   public ContactEntry(String personsName, String phone, String email) {
       super();
       PersonsName = personsName;
       Phone = phone;
       Email = email;
   }
  
  
  


   public String getPersonsName() {
       return PersonsName;
   }
   public void setPersonsName(String personsName) {
       PersonsName = personsName;
   }
   public String getPhone() {
       return Phone;
   }
   public void setPhone(String phone) {
       Phone = phone;
   }
   public String getEmail() {
       return Email;
   }
   public void setEmail(String email) {
       Email = email;
   }
  
  
   static List<ContactEntry> contactentry = new ArrayList <ContactEntry>();

   public static void showdetail()
   {
       Iterator itr=contactentry.iterator();

   //traverse elements of ArrayList object
   while(itr.hasNext()){
       ContactEntry st=(ContactEntry)itr.next();
   System.out.println(st.PersonsName+" "+st.Phone+" "+st.Email);
   }
   }
  
  
  
  
  
   public static void main(String[] args) {
      
       ContactEntry c1=new ContactEntry("John","5413134","[email protected]");
       ContactEntry c2=new ContactEntry("Jack","482123","[email protected]");
       ContactEntry c3=new ContactEntry("Josh","78642","[email protected]");
       ContactEntry c4=new ContactEntry("Jolly","325478","[email protected]");
       ContactEntry c5=new ContactEntry("Jordan","325479","[email protected]");
      
      
       contactentry.add(c1);
       contactentry.add(c2);
       contactentry.add(c3);
       contactentry.add(c4);
       contactentry.add(c5);
      

       showdetail();
      
      
      
   }


}

Thank YOU!!!


Related Solutions

In java, create a class named Contacts that has fields for a person’s name, phone number...
In java, create a class named Contacts that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five Contact objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to demonstrate that it works. Include javadoc...
JAVA/Netbeans •Design a class named Person with fields for holding a person’s name, address and phone...
JAVA/Netbeans •Design a class named Person with fields for holding a person’s name, address and phone number (all Strings) –Write a constructor that takes all the required information. –Write a constructor that only takes the name of the person and uses this to call the first constructor you wrote. –Implement the accessor and mutator methods. Make them final so subclasses cannot override them –Implement the toString() method •Design a class named Customer, which extends the Person class. It should have...
(Java) Design a class named Person with fields for holding a person’s name, address, and telephone...
(Java) Design a class named Person with fields for holding a person’s name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class’s fields. Next, design a class named Customer, which extends the Person class. The Customer class should have a field for a customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write one or more constructors and the appropriate mutator and...
Write a class named Person with data attributes for a person’s first name, last name, and...
Write a class named Person with data attributes for a person’s first name, last name, and telephone number. Next, write a class named Customer that is a subclass of the Person class. The Customer class should have a data attribute for a customer number and a Boolean data attribute indicating whether the customer wishes to be on a calling list. Demonstrate an instance of the Customer class in a simple program. Using python
Write a Data Element Class named Property that has fields tohold the property name, the...
Write a Data Element Class named Property that has fields to hold the property name, the city where the property is located, the rent amount, the owner's name, and the Plot to be occupied by the property, along with getters and setters to access and set these fields. Write a parameterized constructor (i.e., takes values for the fields as parameters) and a copy constructor (takes a Property object as the parameter). Follow the Javadoc file provided.Write a Data Element Class...
write program in java Create a class named PersonalDetails with the fields name and address. The...
write program in java Create a class named PersonalDetails with the fields name and address. The class should have a parameterized constructor and get method for each field.  Create a class named Student with the fields ID, PersonalDetails object, major and GPA. The class should have a parameterized constructor and get method for each field. Create an application/class named StudentApp that declare Student object. Prompts (GUI input) the user for student details including ID, name, address, major and GPA....
Create a class named Lease with fields that hold an apartment tenant’s name, apartment number, monthly...
Create a class named Lease with fields that hold an apartment tenant’s name, apartment number, monthly rent amount, and term of the lease in months. Include a constructor that initializes the name to “XXX”, the apartment number to 0, the rent to 1000, and the term to 12. Also include methods to get and set each of the fields. Include a nonstatic method named addPetFee() that adds $10 to the monthly rent value and calls a static method named explainPetPolicy()...
Design a class named Person with fields for holding a person's name, address, and telephone number(all...
Design a class named Person with fields for holding a person's name, address, and telephone number(all as Strings). Write a constructor that initializes all of these values, and mutator and accessor methods for every field. Next, design a class named Customer, which inherits from the Person class. The Customer class should have a String field for the customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write a constructor that initializes these...
Design a class named Person with fields for holding a person's name, address, and telephone number(all...
Design a class named Person with fields for holding a person's name, address, and telephone number(all as Strings). Write a constructor that initializes all of these values, and mutator and accessor methods for every field. Next, design a class named Customer, which inherits from the Person class. The Customer class should have a String field for the customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write a constructor that initializes these...
Programming C: Write a program for a Rolodex of contact information (e.g., name, phone number, email)...
Programming C: Write a program for a Rolodex of contact information (e.g., name, phone number, email) implemented as a linked list. The program will ask the user to enter a new contact information, retrieve/print a person’s contact information, and to delete a person. It will maintain the linked list in alphabetical order by last name. It will also allow the user to search for a person’s contact information by last name. Assume that all last names are unique.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT