Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started