Question: Using JavaStacks and Exception ClassesA stack is a type of data collection on which things can be pushed and popped . For example, a stack

Using JavaStacks and Exception ClassesA stack is a type of data collection on which things can be pushed and popped. For example, a stack of plates can have a plate added (or pushed) onto the stack, and a plate removed (or popped) from the stack. Plates are pushed onto or popped off of the stack one at a time. The last plate pushed onto the stack is the first plate popped off of the stack. This type of structure is known as LIFO last in, first out.In this project, you should create a stack that will hold objects of type Person. The stack itself will be implemented using a class named PersonStack.Details of the Person classDownload the Person class. Make sure that it compiles in your project.//Person.javapublic class Person {// Instance Variables
private String name ;
private String occupation ;/**
* Full constructor that takes the person's name and birth date
*
* Precondition: Neither theName nor theDate is null.
* @param theName the name of the person
* @param theDate the birthdate of the person
*/
public Person(String newName, String newOccupation){
name = newName ;
occupation = newOccupation ;
}
/**
* Copy constructor takes another Person as a template.
* @param originalPerson which serves as the source of properties to copy
*/
public Person(Person originalPerson){
name = originalPerson.name ;
occupation = originalPerson.occupation ;
}
/**
* Getter for the name of the person
* @return the name of the person
*/
public String getName(){
return name ;
}
/**
* Getter for the occupationn of the person
* @return the (String) occupation of the person
*/
public String getOccupation(){
return occupation ;
}
/**
* Setter for occupation of this person
* @param newOccupation the current occupation of the person
*/
public void setName(String newName){
if (newName == null){
System.out.println("Fatal Error setting person's name.") ;
System.exit(0) ;
}
name = newName ;
}
/**
* Setter for the occupation of the person
* @param newOccupation the new occupation of the person
*/
public void setOccupation(String newOccupation){
occupation = newOccupation ;
}
/**
* Returns a String with the name and occupation of the person
* @return the name and birth date of the person
*/
public String toString(){
return ("Name: "+ name +" Occupation: "+ occupation) ;
}
/**
* Returns true if the date and occupation of this Person are the same as those
* of the Person object passed as a parameter.
* @return true if this person's name and occupation are the same as those of the parameter.
*/
public boolean equals(Object anObject){
if (anObject == null || getClass()!= anObject.getClass()){
return false ;
}
Person otherPerson =(Person) anObject ;
return (name.equals(otherPerson.name) &&
occupation.equals(otherPerson.occupation)) ;
}
}Details of the three Exception classesThe three Exception classes in this project are:PersonStack is full object not added.(The other constructor saves the message passed as a parameter.)PersonStack is empty no object to return.Object is not a Person object not pushed.Each of these three class extends Exception, so they are checked, and must appear inside a try-catch statement.Create these three classes. Follow the same procedure that you used to create the TornadoException class above.Details of the PersonStack classNext, you should define a class called PersonStack, which will implement the stack containing an array of Person objects.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!