Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2 OwIPopulation Class Next, we'll need to create an Object type to model a population of owls. So far in class, you've probably been dealing

image text in transcribedimage text in transcribed

2 OwIPopulation Class Next, we'll need to create an Object type to model a population of owls. So far in class, you've probably been dealing primarily with arrays of primitive types, such as int []. However, Java arrays are capable of storing any type, including Object types defined in classes. For example, if we have a collection of 0wl objects that we would like to consider as a single population, we can store them in an array. This array's type will be 0w1 []. Each index in that array will store a single Owl object, and you will be able to access each owl in the array using array notation. For example, if we have an array of owl objects called owlArray and would like to change the age of the owl in index 0 , we can use owlArray [0]. setAge(). For this milestone, modify the given Ow1Population class. This class will have the variables private String filename and private Owl [] data. The OwlPopulation constructor should take in a file name as a parameter and call the following method. - public int populateData() - this will read in the CSV file and construct the 0wl objects to put into the 0wlPopulation's data attribute. populateData should return the number of Owls in the OwlPopulation. n order to read in the CSV file, we will again utilize the Scanner class. The populateData method s partially filled out for you. It already reads in a file line by line. You may modify this code to ise in your OwlPopulation class. Hint: A CSV file (comma-separated-value file), as its name suggests, separates each value with a comma. In this file, each line contains the [name, age, weight] attributes for an individual owl. The following methods may be useful to you in parsing the file: - split(String delimiter) is called on a String. It splits the string into an array of substrings delimited by an argument passed in. - Integer.parseInt(String num) and Double.parseDouble(String num) both take in a String object and return an int and double version of the String input respectively. Note: The two CSV files can be found here. Make sure to open both CSV files in IntelliJ and observe their layout. Microsoft Excel, Google Sheets, and the file preview in Canvas do not show them accurately! Additionally, remember to put the CSV files in the top level folder for this lab, lab4. This will be important for interpreting the file path correctly. Milestone 2: Show an OwlPopulation being constructed correctly using the provided CSV files. Print the number of owls in the population to the console. For reference, Population 1 should contain 89 members, while Population 2 should contain 67

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

SQL For Data Science Data Cleaning Wrangling And Analytics With Relational Databases

Authors: Antonio Badia

1st Edition

3030575918, 978-3030575915

More Books

Students also viewed these Databases questions

Question

Why is there a need for Trade Unions? Explain in your words.

Answered: 1 week ago