Question

Write a class that analyzes data you have stored in a text file. Your data represents...

Write a class that analyzes data you have stored in a text file. Your data represents the ages of the individuals in your fictitious community. The data is stored, one per line, in a text file. For example,

File name:

myData.txt

Contents:

45

18

6.5

3

5

sdtypo#

18

10

The number of lines in your text file must fall somewhere between 20 and 100 lines. Some of the lines must hold character strings that are not convertible to integers, with at least one being a decimal number and one being a random sequence of characters. (Let us think of these as typos or bad data). Your class' constructor must open your file for scanning. It must pull the data one line at a time. If the line holds bad data (or an integer that is less than 0 or greater than 120), it should throw an exception, print an error message to the console, skip the bad data, and continue scanning your file without crashing. The ages (i.e., good data) that you encounter should be stored in an array list that is a private instance variable of your class.
Your class must contain an instance method that return the average age of your population.

public double averageAge(){

//..

}

Your class must contain an instance method that returns the highest age of your population.

public int highestAge(){

//..

}

Your class must contain an instance method that returns the lowest age of your population.

public int lowestAge(){

//..

}

Your class must contain an instance method that takes as input an integer lower bound and an integer upper bound and returns the percentage of individuals whose age falls between the lower bound and the upper bound, inclusively.

public double percentBetween(int lowerBound, int upperBound){

//..

}

Use exception handing to catch (without crashing) those situations where the user's supplied values for upperBound and lowerBound are illegal (e.g., if the user's lower bound is greater than the upper bound).

Write a tester to test your class. Your tester must allow the user to evaluate the above 4 methods by asking your program for the average age, the lowest age, the highest ages, and the fraction of your population whose age falls between a user-supplied upper bound and lower bound.

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Write a class that analyzes data you have stored in a text file. Your data represents...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Instructions C++ programming Your task is to write a class called Data, stored in a file...

    Instructions C++ programming Your task is to write a class called Data, stored in a file named Data.h. Your class should be able to store a collection (vector) of integers. In addition to the appropriate constructors, your class should also have the following methods. void add (int number); Adds a number to the data set. void print (); Prints out the entire data set on a single line, separated by space. void sort (); Sorts the data set in ascending...

  • In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list of objects. Also, this lab specification tells you only what to do, you now have more responsibility to...

    In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list of objects. Also, this lab specification tells you only what to do, you now have more responsibility to design how to do it. Problem description You are given a text file called 'Students.txt' that contains information on many students. Your program reads the file, creating many Student objects, all of which will be stored into an array list of Student objects, in the Students...

  • When we test your Fraction.java we will use the given FractionTester.java file. Your Fraction.java file -MUST-...

    When we test your Fraction.java we will use the given FractionTester.java file. Your Fraction.java file -MUST- work perfectly with the supplied FractionTester.java file. You may NOT modify the FractionTester to make your Fraction class work right. Starter Fraction File: Fraction.java ADD METHODS TO THIS FILE. HAND IN THIS FILE ONLY. Given/Completed Tester File: FractionTester.java DO NOT MODIFY. DO NOT HAND IN. You are to add the following methods to the given Fraction.java file public Fraction add( Fraction other) returns a...

  • In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list...

    In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list of objects. Also, this lab specification tells you only what to do, you now have more responsibility to design how to do it. Problem description You are given a text file called 'Students.txt' that contains information on many students. Your program reads the file, creating many Student objects, all of which will be stored into an array list of Student objects, in the Students...

  • In Java Programming chapter 6 Make a class that represents a file. This class will have...

    In Java Programming chapter 6 Make a class that represents a file. This class will have the ability to calculate the number of lines in that file and the ability to search through the file. UML diagram: -filename:String +FileStats(String fname) +getNumMatchingWords(String wordtoFind) : int +getNumLines() : int The getNumMatchingWords method will take a bit of text and determine how many lines contain that text. Make the comparison not care about case. View required output Test Case 1 Files in the...

  • Create a DataEntryException class whose getMessage() method returns information about invalid integer data. Write a program...

    Create a DataEntryException class whose getMessage() method returns information about invalid integer data. Write a program named GetIDAndAge that continually prompts the user for an ID number and an age until a terminal 0 is entered for both. If the ID and age are both valid, display the message ID and Age OK. Throw a DataEntryException if the ID is not in the range of valid ID numbers (0 through 999), or if the age is not in the range...

  • (JAVA) Use the Pet.java program from the original problem (down below) Compile it. Create a text...

    (JAVA) Use the Pet.java program from the original problem (down below) Compile it. Create a text file named pets10.txt with 10 pets (or use the one below). Store this file in the same folder as your “class” file(s). The format is the same format used in the original homework problem. Each line in the file should contain a pet name (String), a comma, a pet’s age (int) in years, another comma, and a pet’s weight (double) in pounds. Perform the...

  • Follow the directions in the TODO statements of RandomGenerator.java (attached). Submit your altered RandomGenerator.java file. public...

    Follow the directions in the TODO statements of RandomGenerator.java (attached). Submit your altered RandomGenerator.java file. public class RandomGenerator { public static void main(String[] args) { //TODO: Create a Scanner object to read keyboard input. //TODO: Ask the user a lower and upper bound. //TODO: Ask the user for the number of random integers to generate. //TODO: Generate random integers of the desired length and bound. //TODO: Print the average, max, min, count, and sum of the integers. } } 1....

  • Java using data structures The objective is to create your own Hash Table class to hold...

    Java using data structures The objective is to create your own Hash Table class to hold a list of employees and their ID numbers. I've provided the TableEntry class which will be each data object in the hash table. The list of employees will be provided as a .txt file and must be read with the code. please create a .txt file called Employees.txt with the info provided so that the java code can read it in. Employees.txt: (No WhiteSpace...

  • Create a UML diagram to help design the class described in exercise 3 below. Do this...

    Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? 3. Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT