Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Florida Department of Children and Families need a new program to track information about families they are dealing with. They have already written the

The Florida Department of Children and Families need a new program to track information about families they are dealing with. They have already written the main method (that you may not change) and placed it in UseFamily.java. You'll see that for each family they need information about:

The number of people

The names and ages of the members

The total age

Additionally, they need to be able to:

Add people to a family

Track age increments by specifying that it's someone's birthday

Print out the information about the family members

Write two instantiable classes that will allow the main method to work:

A Person class that contains:

Instance variables to store the name and age of a person

A default constructor, and a constructor that takes a name and age to initialize the instance variables.

A toString method to return a string representation of the person, formatted ala "Fred is 32 years old".

A mutator method to increment the age of the person

An accessor method to return the name the person

An accessor method to return the age the person

UsePerson.java can be used to test your Person class.

A Family class that contains:

Instance variables to store the information about the people (maximally 10 people per family)

A default constructor that intializes the instance variables to a family of 0 people

An IO method to display the family

A mutator method to add a person to the family (returning false if there's no more space in the family)

A mutator method that makes the necessary changes for a birthday

An accessor method to return the number of people

An accessor method to return the total age of the people

Here's what a sample run should look like (with the keyboard input shown in italics) ...

Enter name of next person : Fred How old is that person : 32 Enter name of next person : Wilma How old is that person : 27 Enter name of next person : Pebbles How old is that person : 4 Enter name of next person : Barney How old is that person : 8 Enter name of next person : STOP There are 4 people in the family, with a total age of 71 Fred is 32 years old Wilma is 27 years old Pebbles is 4 years old Barney is 8 years old Whos birthday is it? : Wilma There are 4 people in the family, with a total age of 72 Fred is 32 years old Wilma is 28 years old Pebbles is 4 years old Barney is 8 years old 

You must ...

Write the Person class

Write the Family class

UseFamily.java

import java.util.Scanner; //============================================================================= public class UseFamily { //----------------------------------------------------------------------------- private static Scanner keyboard = new Scanner(System.in); private static final String SENTINEL = "STOP"; //----------------------------------------------------------------------------- public static void main(String[] args) { Family myFamily = new Family(); String name; int age; //----Get family information do { System.out.print("Enter name of next person : "); name = keyboard.nextLine(); if (!name.equalsIgnoreCase(SENTINEL)) { System.out.print("How old is that person : "); age = keyboard.nextInt(); keyboard.nextLine(); if (!myFamily.addPerson(name,age)) { System.out.println("ERROR: Cannot add person"); name = SENTINEL; } } } while (!name.equalsIgnoreCase(SENTINEL)); //----Print family information System.out.println("There are " + myFamily.getNumberOfPeople() + " people in the family, with a total age of " + myFamily.getTotalAge()); myFamily.display(); //----Let one person have a birthday System.out.print("Whos birthday is it? : "); name = keyboard.nextLine(); myFamily.birthday(name); //----Print family information System.out.println("There are " + myFamily.getNumberOfPeople() + " people in the family, with a total age of " + myFamily.getTotalAge()); myFamily.display(); } //----------------------------------------------------------------------------- } //=============================================================================

UsePerson.java

import java.util.Scanner; //============================================================================= public class UsePerson { //----------------------------------------------------------------------------- private static Scanner keyboard = new Scanner(System.in); //----------------------------------------------------------------------------- public static void main(String[] args) { Person onePerson; String name; int age; //----Get person information System.out.print("Enter name of person : "); name = keyboard.nextLine(); System.out.print("How old is that person : "); age = keyboard.nextInt(); keyboard.nextLine(); onePerson = new Person(name,age); //----Print person information System.out.println(onePerson); //----Let person have a birthday onePerson.incrementAge(); System.out.println(onePerson); //----Print person information via accessors System.out.println("Raw access shows that " + onePerson.getName() + " is " + onePerson.getAge() + " years old"); } //----------------------------------------------------------------------------- } //=============================================================================

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 Using Entity Relationship Diagrams

Authors: Sikha Saha Bagui, Richard Walsh Earp

3rd Edition

103201718X, 978-1032017181

More Books

Students also viewed these Databases questions

Question

=+is irrational.

Answered: 1 week ago

Question

recognise typical interviewer errors and explain how to avoid them

Answered: 1 week ago

Question

identify and evaluate a range of recruitment and selection methods

Answered: 1 week ago

Question

understand the role of competencies and a competency framework

Answered: 1 week ago