this is what i have so far.

public class PersonalInformation{

    /* ===================================================
    ===== Challenge 6.1 - Personal Information Class =====
    ======================================================

    Design a class that holds the following personal data: name, age, and phone number.
    Write appropriate accessor and mutator methods. Demonstrate the class by writing a
    program that creates three instances of it. One instance should hold your information,
    and the other two should hold your friends' or family member's information.

     */

    public static void main(String[] args) {
        // Create the objects.

        // Set my info.
        PersonalInformation myInfo = new PersonalInformation();
        name startName = new name("Joe Mahoney");
        startAddress.setAddress("724 22nd Street");
        startAge.setAge("27");
        startPhoneNumber.setPhoneNumber("(555)555-1234");
        // Set friend #1's info.
        PersonalInformation myFriend1 = new PersonalInformation();
        name startName = new name("Geri Rose");
        startAddress.setAddress("149 East Bay Street");
        startAge.setAge("24");
        startPhoneNumber.setPhoneNumber("(555)555-5678");
        // Set friend #2's info.
        PersonalInformation myFriend2 = new PersonalInformation();
        name startName = new name("John Carbonni");
        startAddress.setAddress("22 King Street");
        startAge.setAge("28");
        startPhoneNumber.setPhoneNumber("(555)555-0123");

        // Display my info.

        // Display friend #1's info.

        // Display friend #2's info.

    }
}


public class PersonBuilder
{
    private String name;     // A person's name
    private String address;  // A person's address 
    private int age;         // A person's age
    private int phoneNumber; // A person's phone number

    PersonalInformation(String startName, String startAddress, int startAge, int startPhoneNumber) {
        name = startName;
        address = startAddress;
        age = startAge;
        phoneNumber = startPhoneNumber;
    }

    /**
     The setName method sets the person's name.
     @param n The person's name.
     */

    /**
     The setAge method sets the person's age.
     @param a The person's age.
     */

    /**
     The setAddress method sets the person's address.
     @param a The person's address.
     */

    /**
     The setPhone method sets the person's phone number.
     @param p The person's phone number.
     */

    /**
     The getName method returns the person's name.
     @return The person's name.
     */
    public String getName(String Name){
        return name;
    }
    /**
     The getAge method returns the person's age.
     @return The person's age.
     */
    public String getAge(String Name){
        return age;
    }
    /**
     The getAdress method returns the person's address.
     @return The person's address.
     */
    public String getAddress(){
        return address;    
    }
    /**
     The getPhone method returns the person's phone number.
     @return The person's phone number.
     */
    public int getPhoneNumber(){
        return phoneNumber;
    }

}

Recommended Answers

All 2 Replies

I need it to save the three peices personal data, and then display them. if anyone has done this before a hand will you help me out?

        PersonalInformation myInfo = new PersonalInformation();
        name startName = new name("Joe Mahoney");
        startAddress.setAddress("724 22nd Street");
        startAge.setAge("27");
        startPhoneNumber.setPhoneNumber("(555)555-1234");

This will not work. In clear, it won't even compile. Your PersonalInformation class has this as constructor:

    private String name;     // A person's name
    private String address;  // A person's address 
    private int age;         // A person's age
    private int phoneNumber; // A person's phone number

    PersonalInformation(String startName, String startAddress, int startAge, int startPhoneNumber) {
        name = startName;
        address = startAddress;
        age = startAge;
        phoneNumber = startPhoneNumber;
    }

This tells me a few things:

  1. name is not of type 'name', it's a String
  2. similar issues with your other variables
  3. you have a parametrized constructor, and haven't explicitly added a non-parametrized one, so you can't call that

So, in order to create an instance, you first need to create the parameters for the constructor, of the correct type.

String name = "Cyroclasim"; // String, there is no class called name.
String address = "MyStreet 5"; // Again, the PersonalInformation class expects this in a String
int age = 18; // assuming you start at 18. But probably age is not sufficient for variable name.
// if it means to depict the name of the person at all time, you should store the date of birth
// if it needs to be the age of the person when the data is entered, you should consider renaming it to something like:
// int ageOnInscription;
int phoneNumber = 5553828;

PersonalInformation pI = new PersonalInformation(name, address, age, phoneNumber);

Now, you have your object you can use.

If you need to display them, the best way would be to add a "toString()" method to your PersonalInformation class:

@Override
public String toString() {
  return "Name: " + name + ", Address: " + address + ", Age: " + age + ", PhoneNumber: " + phoneNumber);
 }

You need to print that info to the command line?

System.out.println(pI);
will do (in order to print the instance we created earlier).

If it's a visual component:

myComponent.setText(pI.toString());

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.