Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

its all juts one question but with different parts, i want to confirm some stuff 1. Suppose you have a Java class called Person satisfying

its all juts one question but with different parts, i want to confirm some stuff image text in transcribed
image text in transcribed
1. Suppose you have a Java class called Person satisfying the following specifications: A Person object cannot be created without a Person being a more specific type of Person. A Person has a name (a String) and an age (a non-negative int). The class variables (data fields) for these are called name and age respectively. The Person class keeps track of the total number of people (number of instances of Person) the program has created in a variable called population. It also has a get method for population The constructor for Person (which is public) takes as parameters the name and age of the Person (in that order) and initialize its name and age fields to these. If the class user tries to set the age to a negative number, then it throws an IllegalArgumentException. The constructor must also update variable population because a new person is being created The class user can view a Person's name (using a get method), but they cannot modify a Person's name. The class user can view and modify the age of a person though a get and a set method for it. If the class user tries to set the age to a negative number, then the set method throws an IllegalArgumentException. The Person class has a method called favoriteInt() that returns the person's favorite integer (an int). This method may be overridden by subclasses of Person. Its default implementation (the one in the Person class) returns 100 minus the age of the person. The Person class does not extend or implement any other data type (except for Object, because this is the default). (a) (4 points) Should class Person be abstract or not? Explain your reasoning. (b) (4 points) Should the data field population be static or non-static? Explain your rea- soning, (c) (4 points) Should the get method for name be static or non-static? Explain your reason- (d) (4 points) Should the data field age be public or private? Explain your reasoning. (e) (4 points) Can the data field name be declared final? Explain your reasoning. (1) (4 points) Can method favoriteInt() be declared final? Explain why or why not. (g) (10 points) Write the constructor for class Person. (Write your code in your file for this exam)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions

Question

How would you establish the value of learning this material?

Answered: 1 week ago