Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help please for this java adventures assignment! Thank you! Write a test program (i.e. main) that: a.Opens the test file Adventures.txt for reading.b.

Can someone help please for this java adventures assignment! Thank you!

Write a test program (i.e. main) that: a.Opens the test file Adventures.txt for reading.b. Creates a polymorphic array to store the adventures. The 1st value in the file indicates how big to make the array. Be sure to use a regular array, NOT an array list.c.For each line in the file:i. Read the type (Zipline, Snorkel, Helicopter), time, and price of the adventure.ii. Create specific adventure object (the type indicates the kind of object to create).iii. Place the adventure object into the polymorphic adventures array. d. AFTER all lines in the file have been read and all adventure objects are in the array:i. Iterate through the adventures array and for each adventure display its type, time, price, and description in a table. ii. See output section at end of document for an example table. e. Create an AdventureCompany objecti. Create an adventure company 1. Call constructor with the specific niche set of Snorkelii. Setup the adventure company 1. Use the adventures in polymorphic array that match the companys niche.2. Use the setupCompany method in the AdventureCompany classiii. Print the adventure company details 1. Use the printCompanyDetails method in AdventureCompany class7. Test file information:a.Run your code on the provided file Adventures.txtb. This file is an example so DO NOT assume that your code should work for only 8 adventures in the order specified in the file.8Number of adventuresZipline 4.5 210Snorkel 4.25 190Zipline 5 225Details for each adventureHelicopter 6 420See (d) below for details aboutHelicopter 2.25 350the format for these lines.Snorkel 4.5 135Helicopter 4.25 599Snorkel 4 260c.1st line is an integer value representing the number of adventures in the file.d. Remaining lines contain details for each adventure. The format of each line is as follows: Type Time Price Zipline 4.5 210Classes Adventure ClassDescription oClass that represents a generic type of adventure.oSuperclass in the hierarchy.Private Data Fieldsotype - Stringrepresenting the type of adventure (zipline, snorkel, helicopter)otime double representing the number of hours the adventure takesoprice double representing the cost of the adventurePublic MethodsoConstructor: public Adventure(String type, double time, double price) Creates an adventure by initializing instance variables type, time, and price to the incoming values for type, time, and price. oGettersOne for each instance variable - type, time, priceoSettersNo setters are needed (this is being done on purpose so do not include setters)opublic String description()Returns a string that describes the adventure.Zipline, Snorkel, Helicopter SubclassesDescription oEach class represents a specific adventure.oEach class must be a subclass of Adventure.Private Data FieldsoNonePublic MethodsoConstructorsThe time and price are the only two incoming values.Inside each constructor the type of adventure is known, so type is not passed in.That is, in the Zipline constructor, you know that the type of adventure being created is a Zipline adventure.public Zipline(double time, double price) { ... }oEach subclass must override the description() method in the Adventure class. @OverridepublicString description() Use the following descriptions for each specific adventure:Adventure TypeDescriptionZiplinePut on a harness, connect to a cable, enjoy an aerial viewSnorkelUse a diving mask & breathing tube, enjoy underwater worldHelicopterWatch the world unfold from a bird's eye viewAdventureCompany Description oClass that represents an adventure company that provides only 1 specific adventure.Private Data Fieldsoniche String representing the one specific adventure this company specializes inoavailableAdventures array of specific adventures that are available from this company oGettersOne for each instance variable - type, time, priceoSettersNo setters are needed (this is being done on purpose so do not include setters)opublic String description()Returns a string that describes the adventure.Zipline, Snorkel, Helicopter SubclassesDescription oEach class represents a specific adventure.oEach class must be a subclass of Adventure.Private Data FieldsoNonePublic MethodsoConstructorsThe time and price are the only two incoming values.Inside each constructor the type of adventure is known, so type is not passed in.That is, in the Zipline constructor, you know that the type of adventure being created is a Zipline adventure.public Zipline(double time, double price) { ... }oEach subclass must override the description() method in the Adventure class. @OverridepublicString description() Use the following descriptions for each specific adventure:Adventure TypeDescriptionZiplinePut on a harness, connect to a cable, enjoy an aerial viewSnorkelUse a diving mask & breathing tube, enjoy underwater worldHelicopterWatch the world unfold from a bird's eye viewAdventureCompany Description oClass that represents an adventure company that provides only 1 specific adventure.Private Data Fieldsoniche String representing the one specific adventure this company specializes inoavailableAdventures array of specific adventures that are available from this company This assignment is not for distribution online or by any other means. Copyright M. Gonzalez UCCSPublic MethodsoConstructor: public AdventureCompany(String niche) Creates an adventure company that specializes in a specific niche.Initializes instance variable niche to incoming niche oGetters/SettersNoneopublic void setupCompany (Adventure[] adventures)The adventure company specializes in 1 specific adventure which is stored in the instance variable niche when the company is created.This method 1st determines how many adventures in the incoming array that match its niche. Next, the method creates and fills the adventure companys array (availableAdventures) with the adventures in the incoming array that match its niche. opublic void printCompanyDetails()Displays these details:Niche the company specializes inNumber of adventures it providesType, time, and price of each adventure it providesMust Dos and TipsMust Do: GeneralUse an array to store the adventures not an ArrayList.Type, time, and price instance variables must be defined only in the superclass Adventure.oThis is done because these values are common for all adventures.In each class, all instance variables must be private.Provide pseudocode for main. Pseudocode for classes is not necessary.Must Not Do:Do not include setters in the Adventure superclass.Tip: Build the classes firstBefore writing the code in main, build as much of the classes as possible.You need to create at least a skeleton of each class before you can write the code in main to create the adventures.Tip: Reading from filesWhen reading from a file, use the methods on the Scanner class to obtain the different pieces of data in the file. DO NOT read one entire line and then parse the line to get the different values. The Scanner methods will do the parsing for you. Tips: ExceptionsYou may have learned about try/catch blocks in your Java class.Exceptions are important, but they add complexity to code, which is unnecessary at this point. To eliminate the need for added complexity and the use of try/catch blocks, have main throw an IOExceptionpublicstaticvoid main(String[] args) throws IOException {Tip: Please place all classes into one Java file. To do so, the layout should be as follows:publicclass Assignment2 { publicstaticvoid main(String[] args) throws IOException {// Code to create array of adventures and read adventures from the file } //main} // Assignment2Note this is the end of your assignment 2 New classes go AFTER this pointNew classes do not include public keywordclass Adventure { // Details for the adventure class go here} // Adventureclass Zipline extends Adventure { // Details for the zipline class go here} // Zipline// Add remaining classes hereOutputIf your program is using inheritance and polymorphism correctly, your output will look like the following when running against the test file Adventures.txt Output - Example----------------------------------------------------------------------------------------------TypeTimePriceDescription----------------------------------------------------------------------------------------------Zipline 4.50 $210.00Put on a harness, connect to a cable, enjoy an aerial viewSnorkel 4.25 $190.00Use a diving mask & breathing tube, enjoy underwater worldZipline 5.00 $225.00Put on a harness, connect to a cable, enjoy an aerial viewHelicopter6.00 $420.00Watch the world unfold from a bird's eye viewHelicopter2.25 $350.00Watch the world unfold from a bird's eye viewSnorkel 4.50 $135.00Use a diving mask & breathing tube, enjoy underwater worldHelicopter4.25 $599.00Watch the world unfold from a bird's eye viewSnorkel 4.00 $260.00Use a diving mask & breathing tube, enjoy underwater worldCS1450 Adventures--------------------------------------------Company's niche: Snorkel adventuresAdventures available: 3Snorkel --- 4.25 hours --- $190.00Snorkel --- 4.50 hours --- $135.00Snorkel --- 4.00 hours --- $260.00

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

Power Bi And Azure Integrating Cloud Analytics For Scalable Solutions

Authors: Kiet Huynh

1st Edition

B0CMHKB85L, 979-8868959943

More Books

Students also viewed these Databases questions

Question

2. What is the meaning and definition of Banking?

Answered: 1 week ago

Question

3.What are the Importance / Role of Bank in Business?

Answered: 1 week ago

Question

2. Are my sources up to date?

Answered: 1 week ago