Question: (Java) Open up a new Java project called Activity6 and create a class called Person Inside of the class, define three attributes that a person

(Java)

  • Open up a new Java project called Activity6 and create a class called Person
  • Inside of the class, define three attributes that a person has as variables of the class
    • Name
    • Age
    • Gender
  • Next, define two actions that can be performed as methods of the class:
  • The method is named greeting
    • It takes no parameters
    • It prints out the message "Hi, my name is " + name + "!"
    • It returns nothing
  • The method is named addYear
    • It takes in no parameters
    • It adds one year to the person's age
    • It returns nothing
  • Then, create a new Java file called PersonTest.java.
  • Copy and paste the below test code into PersonTest.java:
/** * @author * CIS 36B, Activity 6.1 */ public class PersonTest { public static void main(String[] args) { Person wen = new Person(); wen.name = "Wen"; wen.age = 19; wen.gender = "male"; wen.greeting(); wen.addYear(); System.out.println("I just turned " + wen.age + " years old."); } }
  • Now, run the program and verify that you get the following output:
Hi, my name is Wen! I just turned 20 years old.
  • When you are getting the correct output, submit your Person.java file

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!