Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in java Assignment Description The table below shows types of insects with different abilities - pollinators, builders, predators, and decomposers. Each insect has a fixed

in java
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Assignment Description The table below shows types of insects with different abilities - pollinators, builders, predators, and decomposers. Each insect has a fixed set of abilities as is listed in the table with a Y. Type Pollinator Builder Predator Decomposer Honeybee Y Y N N Ladybug Y N NY Y Praying Manis N N Y Specifications 1. Create a Java class called LastNameFirstName Assignment3 2. Follow "CS1450 Programming Assignments Policy" Read the specifications to get an overview of assignment. When writing code, create the classes 1"! 3. Write a test program (i.e. main) that performs the following steps: a. Creates a polymorphic array to store the insect objects. b. For each line in the file insects.txt: i. Read the information for the insect. ii. Create an insect object. ii. Place the insect object into array. c. AFTER all insect objects are in the array, perform these 2 tasks on the array of insects: i. Find the insects that do not help with the decomposition process ii. Find the one insect with the highest level of all abilities combined For task i, create a method that takes the array of all insects and returns an ArrayList of specific insects (non-decomposers). public static ArrayList findDoNotDecompose(Insect[] insects) For task ii, create a method that returns the array index of the most able insect: public static int findMostAble(Insect[] insects) Also create a method to display the abilities of an insect. Display the values of the abilities associated with the insect sent to method. public static void display Abilities(Insect insect) public static void display Abilities(Insect insect) NOTE: be sure to place these 3 methods inside the Assignment3 class, right after main d. Displays on the console the following for each method in step 3c (see output below) Insect's name Insect's type Insect's ability (i.e. pollinator) Insect's purpose (use abstract purpose() method) Insect's numeric ability level 4. Test file information: a. Run your code on the provided test file insects.txt b. This file is an example so DO NOT assume that your code should work for only 5 insects in the order specified in the file. Represents number of Details for insects in file h Honey 9 800 a Flix 0 10 7 10 each insect. See info p Manny 0 0 100 format of the line. a Queen 0 899 I Francis 9080 below about the c. l line is an integer value representing the number of insects in the file d. Remaining lines contain details for each insect. The format is as follows: h Honey 9 8 0 0 Type Predator Decompose Name Pollinate Build Ability Ability Ability Ability e. Note: If any ability is zero (pollinate, build, predator, decompose) then the insect does not have that ability (i.e., it's not part of its nature). For example: Honeybees are not decomposers, so their decompose ability is set to 0. decompose ability is set to 0. Interfaces Pollinator, Builder, Predator, and Decomposer Interfaces Description Each interface represents a specific ability such as pollinator, builder, etc. The specific ability is measured as a numeric value from 0 to 10. . For example, Ants are excellent decomposer with decompose abilities of 10, or 9 etc. but not so good at pollinating so their pollinate ability is a 0. You may assume no two insects will have the same ability levels. Public Methods Pollinator interface has a method named pollinatel Returns integer value representing ability to pollinate Builder interface has a method named buildo Returns integer value representing ability to build nests, etc. Predator interface has a method named predator Returns integer value representing ability to eat other insects/plants Decomposer interface has a method named decomposed Returns integer value representing ability to decompose dead animal/plants Classes Insect Class Description ABSTRACT class that represents a generic insect. Superclass in the hierarchy. Private Data Fields type - String for type of insect (ie. Honeybee, Ladybug, etc.) name - String for insect's name Public Methods Constructor - none - Unlike assignment #2, here setters are provided in the Insect class to set the instance variables so no constructor is needed. the Insect class to set the instance variables so no constructor is needed. Getter for each private data field Setter for each private data field ABSTRACT method purpose Returns string describing insect's purpose. Honeybee, Ladybug, Ant, and Praying Mantis Subclasses Description o Each represents a specific insect - these are the subclasses in the hierarchy. o Each must extend Insect. o Each must implement only the interfaces for the insect's specific abilities. Private Data Fields o Instance variables for each ability the specific insect (subclass) is known for. . For example, a honeybee needs a pollinateAbility and buildAbility (see 1 table above). Public Methods Constructors Takes the name of insect and the values for ONLY the abilities that insect has. Example: Honeybee constructor takes: name, pollinate Ability and buildAbility. public Honeybee(String name, int pollinateAbility, int buildAbility) Subclass implements ONLY the interfaces for the abilities that insect is known for. Example: Honeybee class implements ONLY Pollinator and Builder. This means Honeybee must override pollinate) and build() interface methods Each subclass overrides the purposel) method in the abstract Insect class. . Use the following strings for each insect's purpose. Type Honeybee Purpose Im popular for producing honey but also pollinate 35% of the cost Without me. 1/3 of the food you cat would not be available! Named after the Virgin Mary, I'm considered good luck if and you! ma pest control expert cating up to 5,000 plant pests during my Ladybug Ant Don't squash me. I'm an ecosystem engineert Me and my 20 milli Type Per Honeybee popular de producing honey bula pollinate 35% of the cou! Without me, 13 of the food you call would not be available! Ladybug Named after the Virgin Mary, m e red good luck if I land on voul I'm a pest control expert cating up to 5.000 plant pests during my life pan Don't squash me, I'm an e ste ener! Me and my 20 million friends accelerate decomposite of deadwood, acre soil improve drainase, and eat insects like ticks and termites! Praying Mantis I'm an extreme predator quick enough so catch a fly. Release me in a parden and I'll cat beetles, grasshoppers, crickets and even pesky moths. Am D Tips Must Do Use an array to store the insects you create from the information in the file. Use an ArrayList to return insects from the methods specified in step 3c. Do not assume the file provided is what the grader will use. It is important to learn to not make assumptions when writing code. For example, do not assume there are 5 insects and do not assume the insects will be in the order they are presented in the file. Tip: Casting . The methods find Most Able and display Abilities, need access to an insect's abilities so you will need to call the methods in the interfaces to obtain the abilities. To call a method in the interfaces, casting to Pollinator, Builder, Predator or Decomposer is required. o For example, to obtain the insect's pollinate ability, casting to Pollinator is required. o Why? Because the pollinate method is in the Pollinate interface and not in Insect class. That is, when calling the insect's pollinate method on an insect object, you'll need to cast otherwise you'll get the error: "the method pollinate() is undefined for type Insect Read Liang, section 11.9 Casting Objects and the instanceof Operator o Look at Listing 11.7. it contains both instanceof and casting. This should help you understand what is required to determine which interface you are working with in the findDoNotDecompose, find MostAble. display Abilities. Tip: Build the classes first and Code Incrementally Before writing the code in main, build as much of the Tip: Build the classes first and Code Incrementally Before writing the code in main, build as much of the classes as possible Create a skeleton of each class before you write the code to create insects in main. Next get the code working in bits. Make sure you can read all the data from the file correctly, then create the insect objects, etc. Output Your output will look like the following when running against the provided test file insects.txt INSECTS THAT DON'T HELP WITH DECOMPOSITION! Honey is a Honeybee and does not help with decomposition I'm popular for producing honey but I also pollinate 35% of the crops! Without me, 1/3 of the food you eat would not be available! Pollinating ability 9 Building ability 8 Manny is a Praying Mantis and does not help with decomposition I'm an extreme predator quick enough to catch a fly. Release me in a garden and I'll eat beetles, grasshoppers, crickets and even pesky moths Predator ability 10 Francis is a Ladybug and does not help with decomposition Named after the Virgin Mary, I'm consider good luck if I land on you! I'm a pest control expert eating up to 5,000 plant pests during my life span. Pollinating ability 9 Predator ability 8 INSECT WITH MOST ABILITIES! The winner is Flix the Ant Don't squash me, I'm an ecosystem engineer! Me and my 20 million friends accelerate decomposition of dead wood, aerate soil, improve drainage, and eat insects like Pollinating ability 9 Predator ability 8 INSECT WITH MOST ABILITIES! The winner is Flix the Ant Don't squash me, I'm an ecosystem engineer! Me and my 20 million friends accelerate decomposition of dead wood, aerate soil, improve drainage, and eat insects like ticks and termites! Building ability 10 Predator ability 7 Decomposer ability 10 5 h Honey 9 8 0 a Flix 0 10 7 10 p Manny 0 0 10 0 a Queen 0 8 9 9 1 Francis 9 0 8 0

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

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

More Books

Students also viewed these Databases questions

Question

discuss what an intervention is in relation to work psychology;

Answered: 1 week ago