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

// 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 iName, String iAddress, int iAge, String iPhoneNumber)
      
      {
         name = iName;
         address = iAddress;
         age = iAge;
         phonenumber = iPhoneNumber;
      }
   
   	PersonalInformation yourPersonalInformation = new yourPersonalInformation();
		
		public PersonalInformation() 
		{
    	name = Barney Brown;
    	address = 56 Maplethorpe Street, Boston, MA 02215;
    	age = 45;
	phonenumber = 6178905443;
	}

	PersonalInformation friends = new friendsPersonalInformation();
   	
	public friendsPersonalInformation()
	{
	name = Carl Weathers;
	address = 67 Dorchester Rd., Boston, MA 02215;
	age = 29;
	phonenumber = 6177894567;
	}
		
	PersonalInformation dadPersonalInformation = new PersonalInformation();

	public dadPersonalInformation()
	{
	name = Fred Astaire;
	address = 89 Westwood Place, Beverly Hills, CA 90210;
	age = 34;
	phonenumber = 3108996768;
	}
		
	{
   	
        public String getName(String Name)
       {
      		
      
         return name;
       }
   	
   
   
      public String getAddress()
      {
        
         return address;
      
      }
   
   
      public int getAge()
      {
      
      
         return age;
      }
   
   
      public int setPhoneNumber()
      {
      
         return phonenumber;
      }
   }

It had a number errors after I compiled it and ran it. Not sure what I am doing wrong, even after reading the tutorials.

Here's my revision to both the class and demo:

// 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 startName, String startAddress, int startAge, int     startPhoneNumber)
      
      {
         name = startName;
         address = startAddress;
         age = startAge;
         phonenumber = startPhoneNumber;
      }		
	
   	
      public String getName(String Name)
      {
      		
      
         return name;
      }
   	
   
   
      public String getAddress()
      {
        
         return address;
      
      }
   
   
      public int getAge()
      {
      
      
         return age;
      }
   
   
      public int setPhoneNumber()
      {
      
         return phonenumber;
      }
   }

And here's the demo:

// 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
// Chapter 6, Programming Challenge #3 Personal Information Class.
// 3/14/2012


public class PersonalInformationDemo
{
	public static void main(String[] args)
	{
		// Create the first instance, which will be me.
		Name startName = new Name();
		Name.setName("John Deere");
		startAddress.setAddress1();
		startAge.setAge("39");
		startPhonenumber.setPhoneNumber("6173450221");
		
		// Create the second instance. 
		Name startName = new Name("Ewan McGregor");
		startAddress.setAddress();
		startAge.setAge("29");
		startPhonenumber.setPhoneNumber("2157679834");

		// Create the third instance. 
		Name startName = new Name("Phil Mickelson");
	        startAddress.setAddress();
		startAge.setAge("40");
		startPhoneNumber.setPhoneNumber("3458996787");
			
		// Display the data for first instance (me).
		System.out.println("Me");
		System.out.println("Name: " + startName.getName());
		System.out.println("Address: " + startAddress.getAddress());
		System.out.println("Age: " + startAge.getAge());
		System.out.println("Phonenumber: " + Phonenumber.getPhoneNumber());
		System.out.println();
		
		// Display the data for instance 2 (friend).
		System.out.println("Ewan McGregor");
		System.out.println("Name: " + startName.getName());
		System.out.println("Address: " + startAddress.getAddress());
		System.out.println("Age: " + startAge.getAge());
		System.out.println("PhoneNumber: " + startphoneNumber.getPhoneNumber());
		System.out.println();
		
		// Display the data for instance 3 (family member).
		System.out.println("Phil Mickelson");
		System.out.println("Name: " + startName.getName());
		System.out.println("Address: " + startAddress.getAddress());
		System.out.println("Age: " + startAge.getAge());
		System.out.println("PhoneNumber: " + startphoneNumber.getPhoneNumber());
		System.out.println();
	}
}

Hey mags11,
your PersonalInformation class looks good to me.

However, your demo is wrong. You still make no use of your PersonalInformation class inside your demo.

Here I will put some comments in your code and let you know what is worng.

Name startName = new Name("Ewan McGregor");//Name is not a class you have built. This is very likely to not compile
		startAddress.setAddress();//here, startAddress is the name of the parameter in your PersonalInformation constructor... you can not talk to method parameters. you can only talk to objects. setAddress is a method of a PersonalInformation object. But you have no PersonalInformation object anywhere in your demo, so you cannot invoke setAddress() because you have no object that can set an address. same for below. If you are going to use your setter methods, you will need a constructor of your PersonalInformation objects that takes no parameters. If you pass in parameters, then you need not use setter methods unless you want to change the values in the field variables. This is some hinting. Read this and then read some more of what zeroliken gave you and you should be able to do it.
		startAge.setAge("29");
		startPhonenumber.setPhoneNumber("2157679834");
// 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
// Chapter 6, Programming Challenge #3 Personal Information Class.
// 3/14/2012



   public class PersonalInformationDemo
   {
      public static void main(String[] args)
      {				
		public void PersonalInformation();
		{
		 
    		Name = startName;
    		Address = startAddress;
    		Age = startAge;
			PhoneNumber = startPhoneNumber;
		 
   		
		  				
      // Create the first instance, which will be me.
         startName.setName("John Deere");
         startAddress.setAddress();
         startAge.setAge("39");
         startPhoneNumber.setPhoneNumber("6173450221");
		
			

		 
    		Name = startName;
    		Address = startAddress;
    		Age = startAge;
			PhoneNumber = startPhoneNumber;

        
		  
		  
      // Create the second instance. 
         startName = setName("Ewan McGregor");
         startAddress.setAddress();
         startAge.setAge("29");
         startPhoneNumber.setPhoneNumber("2157679834");
		  
		
		  
    		Name = startName;
    		Address = startAddress;
    		Age = startAge;
			PhoneNumber = startPhoneNumber;


        
      // Create the third instance. 
         startName = setName("Phil Mickelson");
         startAddress.setAddress();
         startAge.setAge("40");
         startPhoneNumber.setPhoneNumber("3458996787");
      
		
      // Display the data for first instance (me).
       
         System.out.println("Name: " + startName.setName());
         System.out.println("Address: " + startAddress.setAddress());
         System.out.println("Age: " + startAge.setAge());
         System.out.println("Phonenumber: " + Phonenumber.setPhoneNumber());
         System.out.println();
      
      // Display the data for instance 2 (friend).
         System.out.println("Ewan McGregor");
         System.out.println("Name: " + startName.seName());
         System.out.println("Address: " + startAddress.setAddress());
         System.out.println("Age: " + startAge.setAge());
         System.out.println("PhoneNumber: " + startphoneNumber.setPhoneNumber());
         System.out.println();
      
      // Display the data for instance 3 (family member).
         System.out.println("Phil Mickelson");
         System.out.println("Name: " + startName.seName());
         System.out.println("Address: " + startAddress.setAddress());
         System.out.println("Age: " + startAge.setAge());
         System.out.println("PhoneNumber: " + startphoneNumber.setPhoneNumber());
         System.out.println();
		  }
      }
	}

When I compile this, I get the following:


PersonalInformationDemo.java:14: illegal start of expression
public void PersonalInformation();
^
PersonalInformationDemo.java:14: illegal start of expression
public void PersonalInformation();
^
PersonalInformationDemo.java:14: ';' expected
public void PersonalInformation();
^
3 errors

there shouldn't be a semicolon at the end of PersonalInformation()

public class PersonalInformationDemo
   {
      public static void main(String[] args)
      {				
				 
    		public void PersonalInformation()
			
			{
 
			String testName;
			String testAddress;
			int testAge;
			int testPhoneNumber;
			  				
      // Create the first instance, which will be me.
         startName.setName("John Deere");
         startAddress.setAddress();
         startAge.setAge("39");
         startPhoneNumber.setPhoneNumber("6173450221");
					  
		  
      // Create the second instance. 
         startName.setName("Ewan McGregor");
         startAddress.setAddress();
         startAge.setAge("29");
         startPhoneNumber.setPhoneNumber("2157679834");
		  
        
      // Create the third instance. 
         startName.setName("Phil Mickelson");
         startAddress.setAddress();
         startAge.setAge("40");
         startPhoneNumber.setPhoneNumber("3458996787");
      
		
      // Display the data for first instance (me).
       
         System.out.println("Name: " + startName.setName());
         System.out.println("Address: " + startAddress.setAddress());
         System.out.println("Age: " + startAge.setAge());
         System.out.println("Phonenumber: " + Phonenumber.setPhoneNumber());
         System.out.println();
      
      // Display the data for instance 2 (friend).
         System.out.println("Ewan McGregor");
         System.out.println("Name: " + startName.seName());
         System.out.println("Address: " + startAddress.setAddress());
         System.out.println("Age: " + startAge.setAge());
         System.out.println("PhoneNumber: " + startphoneNumber.setPhoneNumber());
         System.out.println();
      
      // Display the data for instance 3 (family member).
         System.out.println("Phil Mickelson");
         System.out.println("Name: " + startName.seName());
         System.out.println("Address: " + startAddress.setAddress());
         System.out.println("Age: " + startAge.setAge());
         System.out.println("PhoneNumber: " + startphoneNumber.setPhoneNumber());
         System.out.println();
		  }
      }

I don't know why this is taking so long to solve. The errors I got when compiling this edit are practically the same:


PersonalInformationDemo.java:16: illegal start of expression
public void PersonalInformation()
^
PersonalInformationDemo.java:16: illegal start of expression
public void PersonalInformation()
^
PersonalInformationDemo.java:16: ';' expected
public void PersonalInformation()
^
PersonalInformationDemo.java:70: reached end of file while parsing
}
^
4 errors

your missing a bracket for the main method, also don't create a method inside main

This program is driving me crazy. I'll have to resign if I don't get it right. :(

Hey mags, do you have a solution for this?

cyrusdude: the solution for his last issue was -> follow the java syntax.

how would we do it if we want the user to enter all this information

how would we do it if we want the user to enter all this information for their, friends and family

we would:
1. learn Java.
2. write the code
3. if we ran into trouble, create a new thread, instead of reviving a dead thread.

this is what your PersonalInformationDemo should be like.... the problem was that Actual or formal argument lists differs in length.

public class PersonalInformationDemo
{
  public static void main(String[] args)
  {
    // Create three Peronsal Information objects.
    PersonalInformationClass me = new PersonalInformationClass();
    me.setName("Firstname lastname");
    me.setAge(16); // your age goes in the parenthesis
    me.setAddress("your address goes here");
    me.setPhone("your phone number goes here");

    PersonalInformationClass Friend1 = new PersonalInformationClass();
    Friend1.setName("friend 1 name goes here");
    Friend1.setAge(19);//friend 1 age
    Friend1.setAddress("Friend 1 Address here");
    Friend1.setPhone("Friend 1 Phone number here");


    PersonalInformationClass Friend2 = new PersonalInformationClass();
    Friend2.setName("Friend 2 name goes here");
    Friend2.setAge(21); //friend 2 age
    Friend2.setAddress("Friend 2 Address here");
    Friend2.setPhone("Friend 2 Phone number here");

    // Display my info.
    System.out.println("My information:");
    System.out.println("Name: " + me.getName());
    System.out.println("Age: " + me.getAge());
    System.out.println("Address: "  + me.getAddress());
    System.out.println("Phone: " + me.getPhone());

    // Display friend #1's info.
    System.out.println("\nFriend #1's information:");
    System.out.println("Age: " + Friend1.getAge());
    System.out.println("Address: "  + Friend1.getAddress());
    System.out.println("Phone: " + Friend1.getPhone());


    // Display friensd #2's info.
    System.out.println("\nFriend #2's information:");
    System.out.println("Age: " + Friend2.getAge());
    System.out.println("Address: "  + Friend2.getAddress());
    System.out.println("Phone: " + Friend2.getPhone());
  }
}

@Ashik_2 ... did you NOT read the previous post before yours?
THIS was/is a dead thread.

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.