Question

In: Computer Science

Create HiArrayPerson class to store objects of type class Person (in java ) and Give example

  1. Create HiArrayPerson class to store objects of type class Person (in java ) and Give example

Solutions

Expert Solution

public class HiArrayPerson{
   public static void main(String args[]){
     //create array of person object  
    Person[] obj = new Person[2] ;
 
     //create & initialize actual person objects using constructor
     obj[0] = new Person(100,"ABC");
     obj[1] = new Person(200,"XYZ");
 
     //display the person object data
     System.out.println("Person Object 1:");
     obj[0].showPersonData();
     System.out.println("Person Object 2:");
     obj[1].showPersonData();
  }
}
//Person class with id and name as attributes
class Person{
  int id;
  String name;
  //Person class constructor
  Person(int id, String name){
     this.id = id;
     this.name = name;
  }
  
  public void setId(int id){
      this.id = id;
  }
  
  public int getId(){
      return id;
  }
  
  public void setName(String name){
      this.name = name;
  }
  
  public String getName(){
      return name;
  }
  
  
  public void showPersonData(){
   System.out.print("Person Id = "+ id + "  " + " Person Name = "+name);
   System.out.println();
 }
}

Output:


Related Solutions

java Objective: Create a class. Create objects. Use methods of a class. Create a class BankAccount...
java Objective: Create a class. Create objects. Use methods of a class. Create a class BankAccount to represent a bank account according to the following requirements: A bank account has three attributes: accountnumber, balance and customer name. Add a constructor without parameters. In the initialization of the attributes, set the number and the balance to zero and the customer name to an empty string. Add a constructor with three parameters to initialize all the attributes by specific values. Add a...
Task Create a class called Mixed. Objects of type Mixed will store and manage rational numbers...
Task Create a class called Mixed. Objects of type Mixed will store and manage rational numbers in a mixed number format (integer part and a fraction part). The class, along with the required operator overloads, should be written in the files mixed.h and mixed.cpp. Details and Requirements Finish Lab 2 by creating a Mixed class definition with constructor functions and some methods. The Mixed class should have public member functions Evaluate(), ToFraction(), and Simplify(). The Evaluate() function should return a...
Task CPP Create a class called Mixed. Objects of type Mixed will store and manage rational...
Task CPP Create a class called Mixed. Objects of type Mixed will store and manage rational numbers in a mixed number format (integer part and a fraction part). The class, along with the required operator overloads, should be written in the files mixed.h and mixed.cpp. Details and Requirements Finish Lab 2 by creating a Mixed class definition with constructor functions and some methods. The Mixed class should have public member functions Evaluate(), ToFraction(), and Simplify(). The Evaluate() function should return...
Give an example of how to build an array of objects of a super class with...
Give an example of how to build an array of objects of a super class with its subclass objects. As well as, use an enhanced for-loop to traverse through the array while calling a static method(superclass x). Finally, create a static method for the class that has the parent class reference variable.
Create a generic method to print objects in java. Include a tester class.
Create a generic method to print objects in java. Include a tester class.
Give an example of an inner and outer class. (Java)
Give an example of an inner and outer class. (Java)
Create in Java Create a stack class to store integers and implement following methods: 1- void...
Create in Java Create a stack class to store integers and implement following methods: 1- void push(int num): This method will push an integer to the top of the stack. 2- int pop(): This method will return the value stored in the top of the stack. If the stack is empty this method will return -1. 3- void display(): This method will display all numbers in the stack from top to bottom (First item displayed will be the top value)....
Using Java Summary Create a Loan class, instantiate and write several Loan objects to a file,...
Using Java Summary Create a Loan class, instantiate and write several Loan objects to a file, read them back in, and format a report. Project Description You’ll read and write files containing objects of the Loan class. Here are the details of that class: Instance Variables: customer name (String) annual interest percentage (double) number of years (int) loan amount (double) loan date (String) monthly payment (double) total payments (double) Methods: getters for all instance variables setters for all instance variables...
Create a class of DSA with two pointer objects of Employee and Customer. These objects will...
Create a class of DSA with two pointer objects of Employee and Customer. These objects will represent the head pointer of corresponding linkedlists. Add new data member functions searchCustomer & searchEmployee, to search for customers and employees separately in DSA.
OOPDA in java project. in eclipse Instructions: Create a class called Person with the properties listed:...
OOPDA in java project. in eclipse Instructions: Create a class called Person with the properties listed: int id, String firstName, String middleName, String lastName, String email, String ssn, int age. The Person class should have getters and setters for all properties other than id. (You may use Eclipse to help you auto-generate these.) Person class should also have a getter for id Create a no-arg constructor for Person In addition to these getters and setters, Person should have the following...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT