1,105,242 Community Members

Personal Information Class

Member Avatar
mags11
Light Poster
45 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
zeroliken
Nearly a Posting Virtuoso
1,222 posts since Nov 2011
Reputation Points: 79 [?]
Q&As Helped to Solve: 216 [?]
Skill Endorsements: 15 [?]
 
0
 

Your not making use of the PersonalInformation class
To get you started create 3 new instances of this class
I suggest read this
http://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html
and the rest of the docs
http://docs.oracle.com/javase/tutorial/java/javaOO/index.html

Member Avatar
mags11
Light Poster
45 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
// 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.

Member Avatar
mags11
Light Poster
45 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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();
	}
}
Member Avatar
bibiki
Posting Whiz
393 posts since Nov 2009
Reputation Points: 18 [?]
Q&As Helped to Solve: 31 [?]
Skill Endorsements: 0 [?]
 
0
 

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");
Member Avatar
mags11
Light Poster
45 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
// 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

Member Avatar
zeroliken
Nearly a Posting Virtuoso
1,222 posts since Nov 2011
Reputation Points: 79 [?]
Q&As Helped to Solve: 216 [?]
Skill Endorsements: 15 [?]
 
0
 

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

Member Avatar
mags11
Light Poster
45 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
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

Member Avatar
zeroliken
Nearly a Posting Virtuoso
1,222 posts since Nov 2011
Reputation Points: 79 [?]
Q&As Helped to Solve: 216 [?]
Skill Endorsements: 15 [?]
 
0
 

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

Member Avatar
mags11
Light Poster
45 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
cyrusdude
Newbie Poster
1 post since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hey mags, do you have a solution for this?

Member Avatar
stultuske
Posting Expert
5,290 posts since Jan 2007
Reputation Points: 935 [?]
Q&As Helped to Solve: 774 [?]
Skill Endorsements: 35 [?]
Featured
 
0
 

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

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: