Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Please Help Please

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Location
    St. Louis, MO
    Posts
    9
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Please Help Please

    Design a class that holds the following personal data: name, address, 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 members' information.
    I started it but I can't get the code right. Please if anyone can give some advice let me know.

  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    979
    Thanks
    7
    Thanked 206 Times in 182 Posts

    Default Re: Please Help Please

    It would help if you provided more details.

    What code have you written? If it does not compile and you can't understand the compiler's messages, post them and someone is sure to explain what they mean. If your code compiles but does something weird at runtime describe both the observed behaviour and what you expected or intended.

    -----

    One piece of advice would be to work in very small steps. Your class is supposed to represent a number of pieces of data, but you could start with just name. Compile often and make sure you deal with any compiler messages as they arise.

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Location
    St. Louis, MO
    Posts
    9
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please Help Please

    Thank you for your reply. What I gave is what my teacher gave to us and told us to create it for homework. This is what I have done so far:


    public class Personal

    {
    private String name;
    private String address;
    private int age;
    private int phoneNumber;

    public void setName(String n)
    {
    name = n;
    }

    public void setAddress(String a)
    {
    address = a;
    }

    public void setAge(int b)
    {
    age = b;
    }

    public void setPhoneNumber(int c)
    {
    phoneNumber = c;
    }

    public String getName()
    {
    return name;
    }

    public String getAddress();
    {
    return Address;
    }

    public int getAge();
    {
    return age;
    }

    public int getPhoneNumber();
    {
    return phoneNumber;
    }

    }


    This is page one and my teacher wants us to link two pages together, for example what I just put and a second page printing it out and linking it. He confuses us all lol.

  4. #4
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    979
    Thanks
    7
    Thanked 206 Times in 182 Posts

    Default Re: Please Help Please

    This is page one and my teacher wants us to link two pages together
    I think your teacher is getting at the fact that the questions asks for *two* Java classes. And you have written the first one.

    Does it compile? As I mentioned the first order of business is to address any problems to which the compiler has alerted you.

  5. #5
    Junior Member
    Join Date
    Mar 2012
    Location
    St. Louis, MO
    Posts
    9
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please Help Please

    I don't know how to start the second page with this really with that little information. I just got this page to compile. We just started this and kind of get tossed under the bus lol. Here is the second page I just created and I was completely guessing on it.
    public class PersonalDriver
    {
    public static void main(String[] args)
    {
    Personal p1 = new Personal();
    e1.setName("John Boyer");
    e1.setAddress("154 weird st. St. Louis, MO 63111");
    e1.setAge(28);
    e1.setPhoneNumber(314-471-4161);

    System.out.println("Personal Name: " + e1.getName());
    System.out.println("Personal Address: " + e1.getAddress());
    System.out.println("Personal Age: " + e1.getAge());
    System.out.println("Personal Phone Number: " + e1.getPhoneNumber());


    Personal p2 = new Personal();

    e2.setName("Mark Jones");
    e2.setAddress("1232 Main st. st. louis, MO 63223");
    e2.setAge(29);
    e2.setPhoneNumber(314 555 5555);

    System.out.println("Personal Name: " + e2.getName());
    System.out.println("Personal Address: " + e2.getAddress());
    System.out.println("Personal Age: " + e2.getAge());
    System.out.println("Perosnal PhoneNumber: " + e2.getPhoneNumber());

    Personal p3 = new Personal();

    e3.setName("Susan Jones");
    e3.setAddress("432 Apple dr. st. louis mo 63010");
    e3.setAge(26);
    e3.setPhoneNumber(314 555 4754);

    System.out.println("Personal Name: " + e3.getName());
    System.out.println("Personal Address: " + e3.getAddress());
    System.out.println("Personal Age: " + e3.getAge());
    System.out.println("Personal Phone Number: " + e3.getNumber());

    }
    }

    He said the directing in the paragraph I posted is enough for a basic code with classes and objects. I cant get this page to compile I get a lot of errors. I dont understand the errors bc a book says its right.

  6. #6
    Junior Member
    Join Date
    Mar 2012
    Location
    St. Louis, MO
    Posts
    9
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please Help Please

    Sorry I realized I messed up on something, but I still can't get this page to compile and I am not sure its right. I wish he would have given us more information.

    public class PersonalDriver
    {
    public static void main(String[] args)
    {
    Personal p1 = new Personal();
    p1.setName("John Boyer");
    p1.setAddress("154 weird st. St. Louis, MO 63111");
    p1.setAge(28);
    p1.setPhoneNumber(314-471-4161);

    System.out.println("Personal Name: " + p1.getName());
    System.out.println("Personal Address: " + p1.getAddress());
    System.out.println("Personal Age: " + p1.getAge());
    System.out.println("Personal Phone Number: " + p1.getPhoneNumber());


    Personal p2 = new Personal();

    p2.setName("Mark Jones");
    p2.setAddress("1232 Main st. st. louis, MO 63223");
    p2.setAge(29);
    p2.setPhoneNumber(314 555 5555);

    System.out.println("Personal Name: " + p2.getName());
    System.out.println("Personal Address: " + p2.getAddress());
    System.out.println("Personal Age: " + p2.getAge());
    System.out.println("Perosnal PhoneNumber: " + p2.getPhoneNumber());

    Personal p3 = new Personal();

    p3.setName("Susan Jones");
    p3.setAddress("432 Apple dr. st. louis mo 63010");
    p3.setAge(26);
    p3.setPhoneNumber(314 555 4754);

    System.out.println("Personal Name: " + p3.getName());
    System.out.println("Personal Address: " + p3.getAddress());
    System.out.println("Personal Age: " + p3.getAge());
    System.out.println("Personal Phone Number: " + p3.getNumber());

    }
    }

  7. #7
    Member
    Join Date
    Mar 2012
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please Help Please

    I would suggest using an IDE.
    Then if he needs to see it just make it into a JAR cause I believe it will show the console for you.

  8. #8
    Junior Member
    Join Date
    Mar 2012
    Location
    St. Louis, MO
    Posts
    9
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please Help Please

    ok I will try it thank you. I am just starting out and don't know much on how to use it. I will let you know how it goes and thank you for the advice.

  9. #9
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    979
    Thanks
    7
    Thanked 206 Times in 182 Posts

    Default Re: Please Help Please

    As posted the first class will *not* compile. I would advise making it good before moving on to the other one. If you've corrected the fairly minor syntax errors (the overall structure of your original post is Ok) then repost the corrected code. If the are unresolved compile problems with that code, post the compiler's messages.