×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Create a Program to Create Contact Service Application in Java Assignment Solution

July 09, 2024
Chloe Wong
Chloe Wong
🇨🇦 Canada
Java
Chloe Wong, holding a master's in computer science from the University of British Columbia, has successfully completed over 900 Java assignments. Her proficiency includes array initialization, searching techniques, and exception management. Chloe's meticulous approach and dedication to delivering well-structured solutions make her a trusted expert for students aiming to excel in their programming coursework.
Key Topics
  • Instructions
    • Objective
  • Requirements and Specifications
Tip of the day
Use Python libraries effectively by importing only what you need. For example, if you're working with data, using libraries like pandas and numpy can save time and simplify complex tasks like data manipulation and analysis.
News
In 2024, the Biden-Harris Administration has expanded high-dosage tutoring and extended learning programs to boost academic achievement, helping programming students and others recover from pandemic-related setbacks. These initiatives are funded by federal resources aimed at improving math and literacy skills​

Instructions

Objective

Write a program to create contact service application in java language.

Requirements and Specifications

program-to-create-contact-service-application-in-java

Source Code

CONTACT

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.mycompany.contacttests; public class Contact { private String contactId; private String firstName; private String lastName; private String address; private String phoneNumber; public Contact(String contactId, String firstName, String lastName, String address, String phoneNumber) { //validate inputs against requirements boolean isValid = validateInput(contactId, 10); if(isValid) { this.contactId = contactId; } isValid = isValid && setContactFirstName(firstName); isValid = isValid && setContactLasttName(lastName); isValid = isValid && setAddress(address); isValid = isValid && setPhoneNumber(phoneNumber); if(!isValid) { throw new IllegalArgumentException("Invalid input"); } } public boolean setContactFirstName(String firstName) { boolean isValid = validateInput(firstName, 10); if(isValid) { this.firstName = firstName; } return isValid; } public boolean setContactLasttName(String lastName) { boolean isValid = validateInput(lastName, 10); if(isValid) { this.lastName = lastName; } return isValid; } public boolean setAddress(String address) { boolean isValid = validateInput(address, 20); if(isValid) { this.address = address; } return isValid; } public boolean setPhoneNumber(String phoneNumber) { boolean IsValid = phoneNumber.matches("\\d{10}"); if(IsValid) { this.phoneNumber = phoneNumber; } return IsValid; } public String getContactId() { return contactId; } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public String getAddress() { return address; } public String getPhoneNumber() { return phoneNumber; } private boolean validateInput(String item, int length) { return (item != null && item.length() <= length && item.length() > 0); } }

CONTACT SERVICE

package com.mycompany.contacttests; /* * To change this license header, choose License Headers in Project Properties. ;* To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.util.HashMap; import java.util.Map; public class ContactService { private static ContactService reference = new ContactService(); private final Map contacts; ContactService() { this.contacts = new HashMap(); } //Create a singleton Contact Service public static ContactService getService() { return reference; } public boolean addContact(Contact contact) { boolean isSuccess = false; if(!contacts.containsKey(contact.getContactId())) { contacts.put(contact.getContactId(), contact); isSuccess = true; } return isSuccess; } public boolean deleteContact(String contactId) { return contacts.remove(contactId) != null; } public Contact getContact(String contactId) { return contacts.get(contactId); } }

Similar Samples

Explore a variety of programming assignment samples at ProgrammingHomeworkHelp.com. Our samples cover Java, Python, C++, SQL, and more, showcasing our expertise in delivering precise solutions. Whether you need help with algorithms, databases, or web development, our examples demonstrate our commitment to excellence in programming assistance.