Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please Explain, Thanks Person.Java package people; import java.time.LocalDate; public class Person { protected int bYear; protected String name; public Person() { LocalDate today = LocalDate.now();

Please Explain, Thanks

image text in transcribed

Person.Java

package people;

import java.time.LocalDate;

public class Person { protected int bYear; protected String name; public Person() { LocalDate today = LocalDate.now(); name = "default"; bYear = today.getYear(); } public Person(String initName, int birthYear) { name = initName; bYear = birthYear; } public int age() { LocalDate today = LocalDate.now(); return today.getYear() - bYear; } public String toString() { return String.format("Name: %s, birth year: %d", name, bYear); } }

AdultStudent.Java

package people;

import java.time.LocalDate;

// Put your name here // Put your collaborator(s) name(s) here

public class AdultStudent extends Person implements Comparable{

private String major; private final int AGE_MAJ = 18; public AdultStudent() {

} public AdultStudent(String n, int y, String m) {

} public int compareTo(AdultStudent other) { // A stub -- remove when you write the method return 0; } public String toString() { // A stub -- remove when you write the method return ""; } }

HW7.Java

package hw7;

import people.AdultStudent;

public class Hw7 {

public static void main(String[] args) { AdultStudent[] students = new AdultStudent[3]; students[0] = new AdultStudent("Joon", 1994, "art history"); students[1] = new AdultStudent(); students[2] = new AdultStudent("Gertrude", 2007, "digital cinema"); System.out.println("The students:"); for (int i = 0; i > int findMax(T[] values) { int maxPosition = 0; for (int index = 1; index 0) maxPosition = index; } return maxPosition; } }

For this assignment you will write a subclass AdultStudent of the Person class. The Person class is a slightly modified version of the class we discussed, and the Person java file you should use is included in the zip files uploaded to D2L. Also on D2L is a template for the AdultStudent class in the file AdultStudentjava. Please start the assignment by downloading those two files The AdultStudent class has one private instance variable major which is a String. It also has a private constant AGE_MAJ which is set to 18 and represents the age of majority in the United States. You are not allowed to create any extra variables in the class, other than variables local to the methods For the assignment, you will write the AdultStudent class by writing the following methods 1. public AdultStudent0: The default constructor for the class. It sets the name to 'default". It sets the year to the current year minus AGE _MAJ. It should obtain the current ycar by using the LocalDate class (or cquivalcnt-- contact me by cmail if you are using Java 7 since LocalDate is only available starting with Java 8). Solutions that hard-code 2018 into the constructor will not carn full credit. It should also set the major to "computer science" 2. public AdultStudent(String n, int y, String m): The parameterized constructor for the class. It sets the major using m and the name using n. It checks if the birth year y is valid for a person who would need to be at least AGE_MAJ years old as of the current year. (Again note that the current year should be obtained using the LocalDate class or equivalent. Any solutions that hard-code particular years into this method will not earn full credit). If y is valid for an at-least AGE MAJ-year-old person, then it uses y to set bYear. Otherwise it sets bYear to the current year minus AGE MAJ (to make the person AGE_MAJ years old as of this year) 3. public toString0: This method returns a String that displays the AdultStudent's name, birth year, and major. See the output from the driver program below to see examples of this. Note that you must return a String that looks precisely like the examples shown below. Also note that the toString method of the Person class must be called to get the part of the String representing the name and birth year. Solutions that do not call the toString method of the Person class will earn very little credit. 4. public int compareTo(AdultStudent other): This method allows the class to implement the Comparable interface. It compares AdultStudents via ages. If the calling AdultStudent is younger than other, then the method returns a value 0. If the two AdultStudent objects have the same age, the method returns 0. The method must call the age mcthod of the Person class. Solutions that do not call the age method will carn very little credit. I have provided a driver program Hw7java to help you test your code which has been posted to D2L. Be aware that the grader may add to that program when grading, so if you feel that any of your methods haven't been tested effectivcly by the driver program, please modify as necessary. However, you should only submit the AdultStudent class Below is the sample output that the test program produces for my solutions to the AdultStudent class: The students Name: Joon, birth year: 1994, major: art history Name: default, birth year: 2000, major: computer science Name: Gertrude, birth ycar: 2000, major: digital cinema The largest element in the AdultStudent array is: Name: Joon, birth year: 1994, major: art history

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions

Question

Stages of a Relationship?

Answered: 1 week ago