Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6912279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:04:18+00:00 2026-05-27T09:04:18+00:00

I have a class named Person .This class represents (as the name says) a

  • 0

I have a class named Person.This class represents (as the name says) a Person. Now I have to create a class PhoneBook to represent a list of Persons. How can I do this? I don’t understand what means “create a class to represent a list”.

import java.util.*;

public class Person {

private String surname;
private String name;
private String title;
private String mail_addr;
private String company;
private String position;

private int homephone;       
private int officephone;      
private int cellphone;       

private Collection<OtherPhoneBook> otherphonebooklist;

public Person(String surname,String name,String title,String mail_addr,String company,String position){

    this.surname=surname;
    this.name=name;
    this.title=title;
    this.mail_addr=mail_addr;
    this.company=company;
    this.position=position;

    otherphonebooklist=new ArrayList<OtherPhoneBook>();

}

public String getSurname(){

    return surname;
}

public String getName(){

    return name;
}

public String getTitle(){

    return title;
}

public String getMailAddr(){

    return company;
}

public String getCompany(){

    return position;
}

public void setHomePhone(int hp){

    homephone=hp;
}

public void setOfficePhone(int op){

    officephone=op; 
}

public void setCellPhone(int cp){

    cellphone=cp;
}

public int getHomePhone(){

    return homephone;
}

public int getOfficePhone(){

    return officephone;
}

public int getCellPhone(){

    return cellphone;
}

public Collection<OtherPhoneBook> getOtherPhoneBook(){

    return otherphonebooklist;
}

public String toString(){

    String temp="";

    temp+="\nSurname: "+surname;
    temp+="\nName: "+name;
    temp+="\nTitle: "+title;
    temp+="\nMail Address: "+mail_addr;
    temp+="\nCompany: "+company;
    temp+="\nPosition: "+position;

    return temp;

}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:04:19+00:00Added an answer on May 27, 2026 at 9:04 am

    Based on the class being named PhoneBook, I assume that you ultimately want to create a mapping between a phone number, and a person. If this is what you need to do then your PhoneBook class should contain a Map instead of a List (but this may depend on other parameters of the project).

    public class PhoneBook
    {
        private Map<String,Person> people = new HashMap<String,Person>();
    
        public void addPerson(String phoneNumber, Person person)
        {
            people.put(phoneNumber,person);
        }
    
        public void getPerson(String phoneNumber)
        {
            return people.get(phoneNumber);
        }
    }
    

    In the above, the phone number is represented as a String, which is probably not ideal since the same phone number could have different String representations (different spacing, or dashes, etc). Ideally the Map key would be a PhoneNumber class that takes this all into account in its hashCode and equals functions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class named Person and in this class is the property PersonName
I have a class like this, public class person { name Name {set; get;}
I have a person class which has a name and a list of friends
I have a class Person and a class Name. Name contains two Strings firstName
I have a class Person i.e. the definition of Person with name and age.
Say I have my class @interface Person : NSObject { NSString *name; } I
I have the following models class Person(models.Model): name = models.CharField(max_length=100) class Employee(Person): job =
I have the following CoffeeScript code: class Person secret = 0 constructor: (@name, @age,
I have models (simplified example): class Group(models.Model): name = models.CharField(max_length = 32) class Person(models.Model):
I have a General Class named MyGeneralClass: public MyGeneralClass<T> { public List<T> Data {get;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.