Question

Hi could you guys help me with this one! thank you and yes I'll rate you...

Hi could you guys help me with this one! thank you and yes I'll rate you up! thank you

Design a class Contact with the data and functionality for one made up contact person ( Don't use actual contact). As data it should store a name, email, and phone.

The functions should include getter (accessor) and setter (modifier) functions for each of these data items.

Write a small main function that initializes an array of size 10 with:

  • 3 Contact objects for your friends, and
  • 7 Contact objects with default data (blank).

Show how you would change the phone for one contact

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class Contact {

   // private instance variables
   private String name;
   private String email;
   private String phone;

   // constructor
   public Contact() {
       this.name = " ";
       this.email = " ";
       this.phone = " ";
   }

   // constructor with fields
   public Contact(String name, String email, String phone) {
       this.name = name;
       this.email = email;
       this.phone = phone;
   }

   // getter for getting name
   public String getName() {
       return name;
   }

   // setter for setting name
   public void setName(String name) {
       this.name = name;
   }

   // getter for getting email
   public String getEmail() {
       return email;
   }

   // setter for setting email
   public void setEmail(String email) {
       this.email = email;
   }

   // getter for getting phone
   public String getPhone() {
       return phone;
   }

   // setter for setting phone
   public void setPhone(String phone) {
       this.phone = phone;
   }

   public static void main(String... args) {

       // contacts array
       Contact[] contacts = new Contact[10];

       // Add three friends data
       contacts[0] = new Contact("Friend A", "[email protected]", "6543210");
       contacts[1] = new Contact("Friend B", "[email protected]", "6643617");
       contacts[2] = new Contact("Friend C", "[email protected]", "6243219");

       // add seven contacts with blank data
       for (int i = 3; i < 10; i++) {

           contacts[i] = new Contact();
       }

       // Print list
       System.out.println("Original Contacts List : ");
       System.out.println();
       for (int i = 0; i < 10; i++) {

           System.out.println(contacts[i].name + " " + contacts[i].email + " " + contacts[i].phone);

       }

       // change Friend C data
       contacts[2].setPhone("6200012");

      
      
// Print modified lits
       System.out.println("Modified Contacts List after changing friend C phone : ");
       System.out.println();
       for (int i = 0; i < 10; i++) {

           System.out.println(contacts[i].name + " " + contacts[i].email + " " + contacts[i].phone);

       }
   }

}

// Output

Add a comment
Know the answer?
Add Answer to:
Hi could you guys help me with this one! thank you and yes I'll rate you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hi could you guys help me with this 3 questions tho and yes I'll rate you...

    Hi could you guys help me with this 3 questions tho and yes I'll rate you up thank you! 5. A C++ class is most similar to a(n) a. inline function b. pointer c. library function d. structure e. reference 6. A __________ is a member function that is automatically called when a class object is __________. a. constructor, created b. destructor, created c. static function, deallocated d. utility function, declared e. None of these 7. Which is the base...

  • Hi could you guys help me with this one and yes I'll rate you up after...

    Hi could you guys help me with this one and yes I'll rate you up after thank youu ^^ Suppose a firm is currently producing 900 computers per week and charging a price of $1,200 per computer. a. Show how the firm will respond to a negative demand shock if prices are flexible b. Generalizing from the computer market specifically to the economy as a whole, what will happen when this negative demand shock occurs across the economy's many markets?...

  • C++ In this assignment, you will write a class that implements a contact book entry. For...

    C++ In this assignment, you will write a class that implements a contact book entry. For example, my iPhone (and pretty much any smartphone) has a contacts list app that allows you to store information about your friends, colleagues, and businesses. In later assignments, you will have to implement this type of app (as a command line program, of course.) For now, you will just have to implement the building blocks for this app, namely, the Contact class. Your Contact...

  • hi could you guys help me to solve this question please. book: surveying 6th edition page...

    hi could you guys help me to solve this question please. book: surveying 6th edition page 118 exercise 7.17 thank you!! 7.17 In running a line of levels from BM, (elevation 492.10) to BM2, the following readings were taken in the order given: 3.37, 6.87, 4.09,7.82,5.44, 2.08, 6.41, 5.29, 8.33, and 2.63. Set up and complete the level notes including the math check. (Ans.: BM2 = 495.05) ncluding 19

  • language:python VELYIEW Design a program that you can use to keep information on your family or...

    language:python VELYIEW Design a program that you can use to keep information on your family or friends. You may view the video demonstration of the program located in this module to see how the program should function. Instructions Your program should have the following classes: Base Class - Contact (First Name, Last Name, and Phone Number) Sub Class - Family (First Name, Last Name, Phone Number, and Relationship le. cousin, uncle, aunt, etc.) Sub Class - Friends (First Name, Last...

  • Hi. Could you help me write the below program? Please don't use any header other than...

    Hi. Could you help me write the below program? Please don't use any header other than iostream, no Chegg class, no argc/argv. Nothing too advanced. Thank you! For this assignment you are implement a program that can be used to compute the variance and standard deviation of a set of values. In addition your solution should use the functions specified below that you must also implement. These functions should be used wherever appropriate in your solution. With the exception of...

  • C++ Please help. 1) Create an array to store 10 Point2D points (the Point2D class from...

    C++ Please help. 1) Create an array to store 10 Point2D points (the Point2D class from A6). Set the coordinates from 0,0 to 9,9. Move all the points left 5 units and up 10 units. Print their new location. 2) Make a new class Point3D which inherits from the Point2D class. The class has one more data member for the z coordinate. There are two constructors, a default one and one with 3 coordinates. Add the new member functions getZ,...

  • Desperately need help with this one thank you and I'll rate you up after thanks : ) Please let me know if any clarif...

    Desperately need help with this one thank you and I'll rate you up after thanks : ) Please let me know if any clarification or additional information is needed. Compliance with the outlined project requirements is crucial. In this question you should program something of your choice but if possible our professor said to make a program that store account number and balance thank you Project: Programming a project of your choice in C++. Step 1- Program must implement a...

  • Please do this in C++. Thank you in advance. Note that you have to carefully create...

    Please do this in C++. Thank you in advance. Note that you have to carefully create your class using the names and capitalization shown below. Put comments into your program, make sure you indent your program properly, and use good naming conventions. Create a class called entry. It should have two private data members of type std::string. One represents a name and the other represents an email address. Make sure you give them ,meaningful names. Create public getters and setters...

  • Please submit a .cpp file or upload zip if you have more than one file before...

    Please submit a .cpp file or upload zip if you have more than one file before the time up. No library function is allowed. ***The code must contain your name and has proper format. Create a class named CupCake. It contains: • Has private instance variables 1. egg 2. butter 3. baking powder 4. sugar 5. flour 6. milk • All members must have public methods: getter() and setter(). • A constructor - a default constructor with no arguments. The...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT