(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
(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...
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
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 3 images
Recommended textbooks for you
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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
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
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY