Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The aim of this homework assignment is to practice writing classes. This homewor

ID: 3817540 • Letter: T

Question

The aim of this homework assignment is to practice writing classes. This homework assignment will help build towards project 1. which will be to write a program implementing a Management System for a Personal Contact Book. For this assignment, write a class called Contact. This class should contain information of a single personal contact. The information includes last name, first name, address, phone, and e-mail address. For now you can store an address as a string. Your class should support the following functions: Constructor that initializes a Contact by accepting all the parameters. Default constructor that initializes everything to default values. Accessor functions for each field. Mutator functions for each field. Input function to solicit the information. Output function to print out the information about the contact to console in a nice format. Any other necessary functions you feel are appropriate. Make sure the mutator functions accept correct formats of both email and phone number. (i.e., e-mail must be of the form [e-mail account]@[domain-name], [top-level -domain]. Phone number should be a string of 10 digits) Write a driver program to test you class.

Explanation / Answer


public class Contact {
  
   private String lastName;
   private String firstName;
   private String address;
   private String phone;
   private String email_address;
  
   Contact(){
      
   }
  
Contact(String lastName,String firstName,String address,String phone,String email_address){
  
   this.lastName=lastName;
   this.firstName=firstName;
   this.address=address;
   this.phone=phone;
   this.email_address=email_address;
      
   }

public String getLastName() {
   return lastName;
}

public void setLastName(String lastName) {
   this.lastName = lastName;
}

public String getFirstName() {
   return firstName;
}

public void setFirstName(String firstName) {
   this.firstName = firstName;
}

public String getAddress() {
   return address;
}

public void setAddress(String address) {
   this.address = address;
}

public String getPhone() {
   return phone;
}

public void setPhone(String phone) {
   this.phone = phone;
}

public String getEmail_address() {
   return email_address;
}

public void setEmail_address(String email_address) {
   this.email_address = email_address;
}

public void setContactDetails(String lastName,String firstName,String address,String phone,String email_address){
  
   this.firstName=firstName;
   this.lastName=lastName;
   this.address=address;
   this.phone=phone;
   this.email_address=email_address;
}

public void printContactDetails(){
  
   System.out.println("First Name: "+firstName);
   System.out.println("Last Name: "+lastName);
   System.out.println("Address: "+address);
   System.out.println("Phone: "+phone);
   System.out.println("Email Address: "+email_address);
}

public static void main(String[] args) {
  
   Contact contactDetails = new Contact("Tendulkar","Sachin","India","+91-9923678261","sachine.tendulkar");
  
   contactDetails.printContactDetails();
}

}


//Output is here....
First Name: Sachin
Last Name: Tendulkar
Address: India
Phone: +91-9923678261
Email Address: sachine.tendulkar

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote