Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

JAVA

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 inUseFamily.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 (1.0%)

Write the Family class (2.0%)

Here is 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(); } //----------------------------------------------------------------------------- } //=============================================================================

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions