(Java) Look at the following Person.java code import java.util.Scanner; import java.io.*; 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 + "!");     }     @Override     public String toString() {         System.out.println("Name: " + name);         System.out.println("Age: " + age);         System.out.println("Gender: " + gender);         return "";     }     public void setName(String name) {         this.name = name;     }     public void setAge(int age) {         this.age = age;     }     public void setGender(String gender) {         this.gender = gender;     }     public String getName() {         return this.name;     }     public int getAge() {         return this.age;     }     public String getGender() {         return this.gender;     } } Now, add two constructors to your class as specified below: The first constructor is a default constructor It takes in no parameters It sets the the name field to have a default value of "name unknown" It sets the age field to have a default value of 0 It sets the gender field to have a default value of "gender unknown" The second constructor overloads the first It takes in 3 parameters - a String for the name, an int for the age, a String for the gender It assigns name, age and gender the values passed in as parameters Copy and paste the new test file below into PersonTest.java (you can erase the old contents of the file): /** * PersonTest.java * @author * CIS 36B,  Activity 8.1 */ 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;               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: "); input.nextLine();        gender = input.nextLine();                 person = //call 3-argument constructor here         System.out.println("\nYour Summary:\n" + person);     } } 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: Antonia Li Enter your age: 29 Enter your gender: Female Your Summary: Name: Antonia Li Age: 29 Gender: Female

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)

Look at the following Person.java code

import java.util.Scanner;
import java.io.*;

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 + "!");
    }

    @Override
    public String toString() {
        System.out.println("Name: " + name);
        System.out.println("Age: " + age);
        System.out.println("Gender: " + gender);
        return "";
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getName() {
        return this.name;
    }

    public int getAge() {
        return this.age;
    }

    public String getGender() {
        return this.gender;
    }
}

  • Now, add two constructors to your class as specified below:
  • The first constructor is a default constructor
    • It takes in no parameters
    • It sets the the name field to have a default value of "name unknown"
    • It sets the age field to have a default value of 0
    • It sets the gender field to have a default value of "gender unknown"
  • The second constructor overloads the first
    • It takes in 3 parameters - a String for the name, an int for the age, a String for the gender
    • It assigns name, age and gender the values passed in as parameters
  • Copy and paste the new test file below into PersonTest.java (you can erase the old contents of the file):
/**
* PersonTest.java
* @author
* CIS 36B,  Activity 8.1
*/

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;
     
        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: ");
input.nextLine();
       gender = input.nextLine();
       
        person = //call 3-argument constructor here

        System.out.println("\nYour Summary:\n" + person);
    }
}
  • 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: Antonia Li
Enter your age: 29
Enter your gender: Female

Your Summary:
Name: Antonia Li
Age: 29
Gender: Female
 
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 3 images

Blurred answer
Knowledge Booster
Top down approach design
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
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