Hi all. I have a program that uses a class called PersonalInformationClass. The assignment says:
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 think I may have got the code for the class to come out ok, but the demo doesn't come out to be exactly how I want it. The demo part needs to spit out three different instances (1. my info, 2. friends' info, 3. family info). The codes are as follows:
// PersonalInformation.java
// Programmed by Y.
// 03/14/2012
// This is a class called PersonalInformation that holds different data: name, address, age, and phone number.
// Chapter 6, #3.
public class PersonalInformation
{
private String name; // Name
private String address; // Address
private int age; // Age
private int phonenumber; // Phone number
PersonalInformation(String Name, String Address, int Age, int PhoneNumber)
{
name = Name;
address = Address;
age = Age;
phonenumber = PhoneNumber;
}
public String getName(String Name)
{
return name;
}
public String getAddress()
{
return address;
}
public int getAge()
{
return age;
}
public int setPhoneNumber()
{
return phonenumber;
}
}
// PersonalInformationDemo.java
// This is a program called PersonalInformationDemo that creates 3 instances of personal data:
// 1. My own information, 2. Friends' information, and 3. Family members' information.
// Programmer: Y
// CISC115
// Chapter 6, Programming Challenge #3 Personal Information Class.
// 3/14/2012
//import java.lang.*;
import java.util.Scanner; // imports the package necessary to use the Scanner class.
public class PersonalInformationDemo
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in); // declares scanner output object as keyboard
String Name; // Name
String Address; // Address
int Age; // Age
long PhoneNumber; // Phone number
//PersonalInformation personalinformation = new PersonalInformation(Name, Address, Age, PhoneNumber);
{
// Get the user's name.
System.out.print("What is your name? ");
Name = keyboard.nextLine();
// Get the user's address.
System.out.print("What is your full address? ");
Address = keyboard.nextLine();
// Get the user's age.
System.out.print("What is your age? ");
Age = keyboard.nextInt();
// Get the user's phone number.
System.out.print("Type your 10-digit phone number: ");
PhoneNumber = keyboard.nextLong();
}
for(int i = 1; i <= 3; i++)
{
System.out.println("Your name is " + Name);
System.out.println("Your address is " + Address);
System.out.println("Your age is " + Age);
System.out.println("Your phone number is " + PhoneNumber);
}
}
}
When I compile and run the program I get this:
What is your name? Karl Rove
What is your full address? 34 Barney Drive, Hazelton, PA 18765
What is your age? 56
Type your 10-digit phone number: 7845678765
Your name is Karl Rove
Your address is 34 Barney Drive, Hazelton, PA 18765
Your age is 56
Your phone number is 7845678765
Your name is Karl Rove
Your address is 34 Barney Drive, Hazelton, PA 18765
Your age is 56
Your phone number is 7845678765
Your name is Karl Rove
Your address is 34 Barney Drive, Hazelton, PA 18765
Your age is 56
Your phone number is 7845678765