Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA This project is intended to reverse the contents of a file using a generic stack data structure. You will create a generic Reverser class

image text in transcribedimage text in transcribed

JAVA

This project is intended to reverse the contents of a file using a generic stack data structure. You will create a generic Reverser class that will be used for two different data types: string and float. An object of the reverser class declared as a string reverser will be used to create a reverse poem. Another object of the reverser class, this one declared as a float reverser, will be used to get spell potency values for a maji game. For this project, you will need the generic classes from this module topic: A Gene You will not modify the Stack or Node classes. Instead, you need to create a new generic Reverser class. Requirements for the generic Reverser class: This class must be named Reverser and must be a generic class. Instance members: private object of the Stack class (use the generic data type). Constructor method: instantiate the object of the Stack class with the generic type FileToStack method: o This must have a parameter list that includes the input filename. Read the file and fill the stack using the push method. .StackToFile method: o This must have a parameter list that includes the output filename. o Write the contents of the stack to a different file from the return values of the pop method. The output file should contain the same lines as the input file, but in reverse order. Handle all file-related exceptions outlined in the modules For testing, let's look at why we need the Reverser class. Reverse Poem We need a reverser class to assist poets who are trying to create a reverse poem, or palindrome poem, which is a poem that can be read forwards one way and have a meaning, but also be read backwards and have another different meaning. Here is a great example on YouTube (the reader reverses it): lost Generation A poet needs to input a file that contains a forward poem and get the reverse version of the poem written to another file. If you would like to use the above poem for testing, you can download the forward version of this poem here (click to go to the download pagel: reversePoem.txt Note: each line of the file represents a single string. Maji Game We also need the reverser class to assist with a larger game that includes characters who battle using magical spells. Because each of the spells has a potency value, the spell with the highest potency wins the battle. In one phase of the game, players must stack their spels for a speed battle round. The last spell in the stack is played first. You will use the reverser class to load a file that contains one player's stack of spell potency values into the stack, then print the stack in reverse order to simulate the order each spell potency will be used in the speed round. You can create your own input file, or use this one (click to go to the download page): reverseSpells.txt Note: each line of the file represents a different spell potency value. Requirements for the main class: Reverse Poem Create an object of the reverser class for a poem. This will be a String Reverser object. Call the FileToStack method and pass the filename for the reverseme.txt file. Call the StackToFile method and pass a different filename. Confirm that the output file contains all of the lines from the poem in the input file, but in reverse order Maji Game Create an object of the Reverser class for a stack of floats for the magi spell potency values. This will be a float Reverser object Call the FileToStack method and pass a new filename for the list of magi spell potency values for a single player. Call the StackToFile method and pass a different filename for the maji's output file. Confirm that the output file contains all of the values from the input file, but in reverse order This project is intended to reverse the contents of a file using a generic stack data structure. You will create a generic Reverser class that will be used for two different data types: string and float. An object of the reverser class declared as a string reverser will be used to create a reverse poem. Another object of the reverser class, this one declared as a float reverser, will be used to get spell potency values for a maji game. For this project, you will need the generic classes from this module topic: A Gene You will not modify the Stack or Node classes. Instead, you need to create a new generic Reverser class. Requirements for the generic Reverser class: This class must be named Reverser and must be a generic class. Instance members: private object of the Stack class (use the generic data type). Constructor method: instantiate the object of the Stack class with the generic type FileToStack method: o This must have a parameter list that includes the input filename. Read the file and fill the stack using the push method. .StackToFile method: o This must have a parameter list that includes the output filename. o Write the contents of the stack to a different file from the return values of the pop method. The output file should contain the same lines as the input file, but in reverse order. Handle all file-related exceptions outlined in the modules For testing, let's look at why we need the Reverser class. Reverse Poem We need a reverser class to assist poets who are trying to create a reverse poem, or palindrome poem, which is a poem that can be read forwards one way and have a meaning, but also be read backwards and have another different meaning. Here is a great example on YouTube (the reader reverses it): lost Generation A poet needs to input a file that contains a forward poem and get the reverse version of the poem written to another file. If you would like to use the above poem for testing, you can download the forward version of this poem here (click to go to the download pagel: reversePoem.txt Note: each line of the file represents a single string. Maji Game We also need the reverser class to assist with a larger game that includes characters who battle using magical spells. Because each of the spells has a potency value, the spell with the highest potency wins the battle. In one phase of the game, players must stack their spels for a speed battle round. The last spell in the stack is played first. You will use the reverser class to load a file that contains one player's stack of spell potency values into the stack, then print the stack in reverse order to simulate the order each spell potency will be used in the speed round. You can create your own input file, or use this one (click to go to the download page): reverseSpells.txt Note: each line of the file represents a different spell potency value. Requirements for the main class: Reverse Poem Create an object of the reverser class for a poem. This will be a String Reverser object. Call the FileToStack method and pass the filename for the reverseme.txt file. Call the StackToFile method and pass a different filename. Confirm that the output file contains all of the lines from the poem in the input file, but in reverse order Maji Game Create an object of the Reverser class for a stack of floats for the magi spell potency values. This will be a float Reverser object Call the FileToStack method and pass a new filename for the list of magi spell potency values for a single player. Call the StackToFile method and pass a different filename for the maji's output file. Confirm that the output file contains all of the values from the input file, but in reverse order

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

Sybase Database Administrators Handbook

Authors: Brian Hitchcock

1st Edition

0133574776, 978-0133574777

More Books

Students also viewed these Databases questions