Consider the class given below. CLEARLY answer the questions that follow: public class InnocentTownsperson { private boolean
Question:
Consider the class given below. CLEARLY answer the questions that follow: public class InnocentTownsperson { private boolean isAlive; private boolean isCollegeStudent; private boolean isTavernKeeper; private long timeLeftToLive; public InnocentTownsperson (boolean isCollegeStudent, long timeLeftToLive) { isAlive = true; this.isCollegeStudent = isCollegeStudent; this.isTavernKeeper = !isCollegeStudent; this.timeLeftToLive = timeLeftToLive; } public boolean isAlive() { return isAlive; } public boolean isCollegeStudent() { return isCollegeStudent; } public void becomeZombie() { isAlive = false; isCollegeStudent = false; isTavernKeeper = false; timeLeftToLive = 0; } public long getTimeLeftToLive() { return timeLeftToLive; } } What is the name of this class? What are the attributes of this class? For each attribute, give the data type. What are the behaviors of this class? Write the code fragment to carry out the following tasks:
- Create the InnocentTownsperson object (make up any data required)
- Using the InnocentTownsperson you created, print out a message stating whether or not this person is a college student
- Make the person into a zombie
Microeconomics An Intuitive Approach with Calculus
ISBN: 978-0538453257
1st edition
Authors: Thomas Nechyba