Question

In: Computer Science

Develop a program, in which you'll design a class that holds the following personal data: name,...

Develop a program, in which you'll design a class that holds the following personal data: name, address, age, and phone number. As part of the program, you'll then create appropriate accessor and mutator methods. Also, set up three instances of the class. One instance should hold your information, and the other two should hold your friends’ or family members’ information.

Input:

  • data for the following attributes of 3 instances of the  Personal Information Class:
  • name, address, age, and phone number

NOTE: The input data do not need to be real data; they need to be entered at the keyboard, when program is run.

Processing: Develop the following:

  • Personal Information Class
  • A program that creates three instances of the above class

Output:

Set up a loop and display data within each object:

  • name, address, age, and phone number

Solutions

Expert Solution

// PLEASE LIKE THE SOUTION
// FEEL FREE TO DISCUSS IN COMMENT SECTION
// JAVA PROGRAM

import java.util.*;
class PersonalInformation{
   // properties
   String name;
   String address;
   int age;
   long phoneNumber;

   // accessors
   public String getName(){
       return name;
   }

   public String getAddress(){
       return address;
   }

   public int getAge(){
       return age;
   }

   public long getPhoneNumber(){
       return phoneNumber;
   }

   // mutators
   // accessors
   public void setName(String name){
       this.name = name;
   }

   public void setAddress(String address){
       this.address = address;
   }

   public void setAge(int age){
       this.age = age;
   }

   public void setPhoneNumber(long phoneNumber){
       this.phoneNumber = phoneNumber;
   }

   // main method
   public static void main(String arg[]){
       // three objects
       PersonalInformation array[] = new PersonalInformation[3];

       // initialize
       for(int i=0;i<3;i++){
           array[i] = new PersonalInformation();
       }

       Scanner scan = new Scanner(System.in);

       // now ask user for information
       for(int i=0;i<3;i++){
           System.out.print("For Object "+(i+1)+"\n");
           System.out.print("Enter name ");
           String str = scan.next();
           array[i].setName(str);

           System.out.print("Enter Address ");
           str = scan.next();
           array[i].setAddress(str);

           System.out.print("Enter age ");
           int a = scan.nextInt();
           array[i].setAge(a);

           System.out.print("Enter phone number ");
           long x = scan.nextLong();
           array[i].setPhoneNumber(x);
           System.out.println();
       }

       // now print the values
       for(int i=0;i<3;i++){
           System.out.print("For Object "+(i+1)+"\n");
           System.out.print("Name = "+array[i].getName());
           System.out.print(" Address = "+array[i].getAddress());
           System.out.print(" Age = "+array[i].getAge());
           System.out.print(" Phone Number = "+array[i].getPhoneNumber());
           System.out.println();
       }
   }
}

// SAMPLE OUTPUT


Related Solutions

Design a class that holds the following personal data: name and phone number. Write appropriate accessor...
Design a class that holds the following personal data: name and phone number. Write appropriate accessor and mutator methods. Also, design a program that creates two instances of the class. One instance should hold your information, and the other should hold your friends information. phone numbers should be fake.
Develop a java program with a class named friend with data members like name, phno and...
Develop a java program with a class named friend with data members like name, phno and hobby. Use Parameterized constructor to create two friend objects and invoke checkhobby method which takes only one parameter, to find whether they have same hobby or different hobbies
Program Specification Design an inventory class that stores the following members: serialNum: An integer that holds...
Program Specification Design an inventory class that stores the following members: serialNum: An integer that holds a part's serial number. manufactDate: A member that holds the date the part was manufactured. lotNum: An integer that holds the part's lot number. The class should have appropriate setter and getter functions. Next, design a stack class that can hold objects of the class described above. If you wish, you may use the linked list from program 5 as a basis for designing...
Design a ship class that has the following data fields: A data field for the name...
Design a ship class that has the following data fields: A data field for the name of the ship (a string). A data field for the year that the ship was built (a String). A constructor and appropriate accessors and mutators. A toString method that displays the ship’s name and the year it was built. Design a CruiseShip class that extends the Ship class. The CruiseShip class should have the following member: A field for the maximum number of passengers...
C++ Design a class named TermPaper that holds an author's name, the subject of the paper,...
C++ Design a class named TermPaper that holds an author's name, the subject of the paper, and an assigned letter grade. Include methods to set the values for each data field and display the values for each data field. Create the class diagram and write the pseudocode that defines the class. Pseudocode help please
Design a class that holds the following data regarding a music album: artist, title, number of...
Design a class that holds the following data regarding a music album: artist, title, number of tracks, and year released. Write appropriate accessor and mutator methods. Also, write a program that creates three instances of the class. Each instance will hold information about a different music album. Make sure to display all of the information for all three albums to the screen in an organized manner. **Using python**
Design a class named Pet, which should have the following fields: Name – The name field...
Design a class named Pet, which should have the following fields: Name – The name field holds the name of a pet. Type – The type field holds the type of animal that is the pet. Example values are “Dog”, “Cat”, and “Bird”. Age – The age field holds the pet’s age. The Pet class should also have the following methods: setName – The setName method stores a value in the name field. setType – The setType method stores a...
Description: In this program, you'll reuse the Monster data type you wrote in LA11A. Then, you'll...
Description: In this program, you'll reuse the Monster data type you wrote in LA11A. Then, you'll write a function that accepts a Monster as an argument by reference, then print the Monster to the screen. Again, this will be structured as a guided multiple choice quiz where you will choose the appropriate code for a program. After you have gotten a perfect score, write out the program and compile and run it to see it in action. Instructions: Choose the...
Create a class that holds data about a job applicant. Include a name, a phone number,...
Create a class that holds data about a job applicant. Include a name, a phone number, and four Boolean fields that represent whether the applicant is skilled in each of the following areas: word processing, spreadsheets, databases, and graphics: Include a constructor that accepts values for each of the fields. Also include a get method for each field. Create an application that instantiates several job applicant objects and pass each in turn to a Boolean method that determines whether each...
a. Design a class named ItemForSale that holds data about items placed for sale on Carlos's...
a. Design a class named ItemForSale that holds data about items placed for sale on Carlos's List, a classified advertising website. Fields include an ad number, item description, asking price, and phone number. Include get and set methods for each field. Include a static method that displays the website's motto ("Sell Stuff Locally!"). Include two overloaded constructors as follows: A default constructor that sets the ad number to 101, the asking price to $1, and the item description and phone...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT