(Java) 7.1 Code: Look at the following Person.java class code: class Person{ public String name; public int age; public String gender; public void greeting() { System.out.println( "Hi, my name is " + name + "!"); } public void greeting(String otherName) { System.out.println("Hi, " + otherName + "!"); } public void printPerson () { System.out.println("Name: "+name); System.out.println("Age: "+age); System.out.println("Gender: "+gender); System.out.println(); } }   Alter the member variables to make the access modifier private. For example: private String name; //You alter the rest Next, write accessor and mutator methods to allow users to access and modify the data stored in the instance variables. For example: public String getName() {     return name; }   public void setName(String theName) {     name = theName; } image source Note: As shown the mutator method definition above, please try to avoid "shadowing" Copy and paste the new test file below into PersonTest.java (you can erase the old contents of the file). Then add the method calls were indicated in below in bold. /** * PersonTest.java, Activity 7.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;         int age;         Person person = new Person();                 System.out.print("Welcome!\n\nEnter your name: ");         name = input.nextLine(); //call setName here         System.out.println("You entered: " + //call getName here + "\n");         System.out.print("Enter your age: ");         age = input.nextInt();         //call setAge here         System.out.println("You entered: " + //call getAge here + "\n");                 System.out.print("Enter your gender: "); input.nextLine(); //clear '\n' left behind by input.nextInt()        gender = input.nextLine();         //call setGender here         System.out.println("You entered: " + //call getGender here + "\n");         System.out.println("Your Summary:\n" + person.printPerson); //fix mistake on this line     } } When you get the correct output (as shown below), upload Person.java and PersonTest.java to Canvas Sample Output (Note that user input may vary):   Welcome! Enter your name: Marta Gomez You entered: Marta Gomez Enter your age: 25 You entered: 25 Enter your gender: Non binary You entered: Non binary Your Summary: Name: Marta Gomez Age: 25 Gender: Non binar

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

(Java)

7.1

Code:

  • Look at the following Person.java class code:

class Person{
public String name;
public int age;
public String gender;

public void greeting() {
System.out.println( "Hi, my name is " + name + "!");
}
public void greeting(String otherName)
{
System.out.println("Hi, " + otherName + "!");
}
public void printPerson () {
System.out.println("Name: "+name);
System.out.println("Age: "+age);
System.out.println("Gender: "+gender);
System.out.println();
}

}

 

    • Alter the member variables to make the access modifier private. For example:
    private String name;
    //You alter the rest
    • Next, write accessor and mutator methods to allow users to access and modify the data stored in the instance variables. For example:
    public String getName() {
        return name;
    }
     
    public void setName(String theName) {
        name = theName;
    }

    image source

    • Note: As shown the mutator method definition above, please try to avoid "shadowing"
    • Copy and paste the new test file below into PersonTest.java (you can erase the old contents of the file).
    • Then add the method calls were indicated in below in bold.
    /**
    * PersonTest.java, Activity 7.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;
            int age;
            Person person = new Person();
           
            System.out.print("Welcome!\n\nEnter your name: ");
            name = input.nextLine();
    //call setName here
            System.out.println("You entered: " + //call getName here + "\n");

            System.out.print("Enter your age: ");
            age = input.nextInt();
            //call setAge here
            System.out.println("You entered: " + //call getAge here + "\n");
           
            System.out.print("Enter your gender: ");
    input.nextLine(); //clear '\n' left behind by input.nextInt()
           gender = input.nextLine();
            //call setGender here

            System.out.println("You entered: " + //call getGender here + "\n");
            System.out.println("Your Summary:\n" + person.printPerson); //fix mistake on this line
        }
    }
    • When you get the correct output (as shown below), upload Person.java and PersonTest.java to Canvas
    Sample Output (Note that user input may vary):
     
    Welcome!

    Enter your name: Marta Gomez
    You entered: Marta Gomez

    Enter your age: 25
    You entered: 25

    Enter your gender: Non binary
    You entered: Non binary

    Your Summary:
    Name: Marta Gomez
    Age: 25
    Gender: Non binary
Class: Person
Name(lirstName, lastName]
Age
Gender
Instantiation
Interests
Biof "(Name) is (Agel years old. They like [interests]" }
Greeting{ "Hil I'm [Namej". }
Object: person1
Name[Bob, Smith]
Age: 32
Gender: Male
Interests: Music, Skiing
Biof "Bob Smith is 32 years old. He likes Music and Skiling."}
Greeting{ "Hil I'm Bob."}
Object: person2
Name[Diana, Cope]
Age: 28
Gender. Female
Interests: Kickboxing, Brewing
Biof "Diana Cope is 28 years old. She likes Kickboxing and Browing."}
Greeting( "Hi I'm Diana.")
Transcribed Image Text:Class: Person Name(lirstName, lastName] Age Gender Instantiation Interests Biof "(Name) is (Agel years old. They like [interests]" } Greeting{ "Hil I'm [Namej". } Object: person1 Name[Bob, Smith] Age: 32 Gender: Male Interests: Music, Skiing Biof "Bob Smith is 32 years old. He likes Music and Skiling."} Greeting{ "Hil I'm Bob."} Object: person2 Name[Diana, Cope] Age: 28 Gender. Female Interests: Kickboxing, Brewing Biof "Diana Cope is 28 years old. She likes Kickboxing and Browing."} Greeting( "Hi I'm Diana.")
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY