Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Person.java and PersonApp.java Implement the class Person based on the following

ID: 3668520 • Letter: P

Question

Person.java and PersonApp.java Implement the class Person based on the following UML class diagramThen The toString method should print the person data in the following form: firstName lastName from address (see output example) Note: the default implementation provided by Eclipseis can’t be used. It is too verbose for our purpose. Then test the class in the main method (PersonApp) by doing the following: Create an instance of a person with the following data: Tara Rice Main Street 123 HomeTown, UT 87654 Print the Person object (instance) Change the name of the city to Moab Change the zip code to 84532 Print the updated Person object (instance) again Expected Output: Tara Rice Main Street 123 HomeTown, UT 87654 Tara Rice Main Street 123 Moab, UT 84532

Explanation / Answer

Person.java Class

import java.io.*;

public class Person{

   String firstName;
   String lastName;
   String address;
   String city;
   int zipCode;
  
   // Constructor of the class Person
   public Person(String firstname, String lastname, String addrs, String cty, int zip)
   {
      this.firstName = firstname;
      this.lastName = lastname;
      this.address = addrs;
      this.city = cty;
      this.zipCode = zip;
   }

   public void setFirstName(String firstname)
   {
      firstName = firstname;
   }

   public void setLastName(String lastname)
   {
      lastName = lastname;
   }

   public void setAddress(String addrs)
   {
      address = addrs;
   }

   public void setCity(String cty)
   {
      city = cty;
   }

   public void setZipcode(int zip)
   {
      zipCode = zip;
   }

   /* Print the Person details */
   public void printPerson()
   {
      System.out.println("First Name:"+ firstName );
      System.out.println("Last Name:"+ lastName );
      System.out.println("Address:"+ address );
      System.out.println("City:"+ city );
      System.out.println("Zipcode:"+ zipCode );

   }
}

PersonApp.java Class

import java.io.*;

public class PersonApp
{
   public static void main(String args[])
   {
      /* Create object of person class using constructor
  
      Person personObj = new Person("Tara", "Rice", "Main Street 123", "Home Town, UT", 87654);
  
      personObj.printPerson();
  
      //changing person object value
      personObj.setCity("Moab");
      personObj.setZipcode(84532);
  
      personObj.printPerson();  

   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote