Add a static variable to the top of your Person class: private static int numPersons = 0; Next, add two static methods to access and update the value of the numPersons variable: Write a static access method as follows: This accessor method is named getNumPersons It is a static method It returns an int The body of the method returns the value of the numPersons variable Write a static mutator method as follows: This mutator method is named updateNumPersons It is a static method It returns nothing The body of the method increments the value of numPersons by 1 Copy and paste the new test file below into PersonTest.java (you can erase the old contents of the file): /** * PersonTest.java, Activity 10.1 * @author * CIS 36B */

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

(Java)

Check to see if you get the correct final output!

You will use the following code from Person.java class:

import java.util.Scanner;

import java.io.*;

 

class Person {

publicStringname;

publicintage;

publicStringgender;

 

// add additional member

privateAddressaddress;

 

// default constructor

publicPerson(){

name="unkonwn";

age=0;

gender="NA";

address=newAddress();

}

 

// argument constructor

publicPerson(Stringname,intage,Stringgender,Addressaddress){

this.name=name;

this.age=age;

this.gender=gender;

this.address=address;

}

 

publicvoidgreeting(){

System.out.println("Hi, my name is " + name + "!");

}

 

publicvoidgreeting(StringotherName){

System.out.println("Hi, " + otherName + "!");

}

 

publicvoidsetName(Stringname){

this.name=name;

}

 

publicvoidsetAge(intage){

this.age=age;

}

 

publicvoidsetGender(Stringgender){

this.gender=gender;

}

 

publicStringgetName(){

returnthis.name;

}

 

publicintgetAge(){

returnthis.age;

}

 

publicStringgetGender(){

returnthis.gender;

}

 

publicAddressgetAddress(){

// fill in method body here

returnaddress;

}

 

publicvoidsetAddress(Addressa){

// fill in method body here

address=a;

}

 

@Override

publicStringtoString(){

return"Name: "+name+"\nAge: "+age+"\nGender: "+gender+"\nAddress: "+address;// fill in here!;

}

}

 

  • Add a static variable to the top of your Person class:
private static int numPersons = 0;
  • Next, add two static methods to access and update the value of the numPersons variable:
  • Write a static access method as follows:
    • This accessor method is named getNumPersons
    • It is a static method
    • It returns an int
    • The body of the method returns the value of the numPersons variable
  • Write a static mutator method as follows:
    • This mutator method is named updateNumPersons
    • It is a static method
    • It returns nothing
    • The body of the method increments the value of numPersons by 1
  • Copy and paste the new test file below into PersonTest.java (you can erase the old contents of the file):

/**
* PersonTest.java, Activity 10.1
* @author
* CIS 36B
*/

import java.util.Scanner;

public class PersonTest {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String name, gender, street;
        int age, number;
        Person person1;
     
        System.out.print("Welcome!\n\nEnter your name: ");
        name = input.nextLine();
       
        System.out.print("Enter your age: ");
        age = input.nextInt();
       
        System.out.print("Enter your gender: ");
        gender = input.next();
        
        System.out.print("Enter the street number of your address: ");
        number = input.nextInt();
       
        System.out.print("Enter the name of your street: ");
        input.nextLine();
        street = input.nextLine();
        
        Address address = new Address(number, street);
       
        person1 = new Person(name, age, gender, address);
        Person.updateNumPersons();
        System.out.println("\nYour Summary:\n" + person1);
       
        Person person2 = new Person(person1);
        person2.setName("C.J. Nguyen");
        Address a = new Address(42, "South 3rd St");
        person2.setAddress(a);
        Person.updateNumPersons();
        
        System.out.println("\nAnother student with your "
            + "same age and gender: \n" + person2);
        
        System.out.println("\nTotal num persons: " + Person.getNumPersons());
        input.close();

    }
}

  • When you get the correct output (as shown below), upload Address.java and Person.java to Canvas

Sample Output (Note that user input may vary):

 

Welcome!

Enter your name: Xing Li
Enter your age: 39
Enter your gender: M
Enter the street number of your address: 555
Enter the name of your street: W. Harlem Ave

Your Summary:
Name: Xing Li
Age: 39
Gender: M
Address: 555 W. Harlem Ave

Another student with your same age and gender:
Name: C.J. Nguyen
Age: 39
Gender: M
Address: 42 South 3rd St

Total num persons: 2

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education