Implement stacks for java double numbers

Assignment Help Basic Computer Science
Reference no: EM13960876

1. Purpose
The purpose of this assignment is to implement a Stack ADT in the two most common ways, an array and a linked list. You will implement stacks for Java double numbers.

2. Description
Your Stack implementations will be used to do sound manipulation, namely reversing a sound clip. This process, called "backmasking," was used by musicians including the Beatles, Jimi Hendrix, and Ozzy Ozbourne. You will write a program that reads a sound file in the .dat format and writes another .dat sound file which is the reverse of the first. The sample code has provided a class Reverse whose main method reads in a .dat sound file, pushes all the sound values on a stack, then pops them all off and writes them into a new .dat sound file. The sample code has also provided an interface DStack, which defines a stack that holds double values. Your first job is to familiarize yourself with these files.

2.1. Implementing the Stack ADT
You need to provide two stack implementations, one using an array and one using a linked list. They should be called ArrayStack and ListStack, respectively. They should implement the DStack interface given to you. Reverse should work and create backward sound files once you complete these two implementations. Your array implementation should start with a small array (say, 10 elements) and resize to use an array twice as large whenever the array becomes full, copying over the elements in the smaller array. While there are convenient Java library methods for copying arrays, for this assignment, use your own loop to copy array elements manually (so you can "see" the work involved in copying).

Both ArrayStack and ListStack should throw an EmptyStackException if pop() or peek() is called when the stack is empty. To use EmptyStackException, add the following line to your file:

import java.util.EmptyStackException;

The only Java class that you should use to complete the implementations of your stacks is java.util.EmptyStackException. You should also use the length field of an array.

2.2. Running Reverse
The Reverse program takes 3 arguments (also known as "command-line arguments"). The first is the word array or list and specifies which implementation to use. The next two are the
input and output .dat file names (you need to include the .dat extension). Running the program will depend on your system; from a command line it will look something like:

java Reverse list in.dat out.dat

In an IDE there is usually a dialog box for setting program parameters which contains a field for the program arguments. (For example, in Netbeans select Build->Run Arguments and a bar will appear at the top of the screen that allows you to type in the arguments. Read more about setting command line parameters in Netbeans.)

To test your program, create short .dat files by hand to aid testing.

Note that Reverse.java just uses your stacks in one particular way: pushing a bunch of elements onto the stack and then popping them all off.

2.3. The .dat File Format
The .dat file format starts with one line describing the sample rate of the sound file. This line is required. The rest of the file is composed of two columns of numbers. The first column consists of the time (measured in seconds) when the sample was recorded, and the second column contains the value of the sample, between -1.0 and 1.0. This is the beginning of a sample .dat file. Notice that the numbers in the first column increase by 1/44100 each step. This is because the sample rate is 44.1kHz.

; Sample Rate 44100 00 2.2675737e-05 0 4.5351474e-05 0 6.8027211e-05 0 9.0702948e-05 0 0.00011337868 0 0.00013605442 0 0.00015873016 0 0.00018140590 0 0.00020408163 0

Note that all you need to do is implement the stacks, as the provided Reverse.java does file input/output for you. We are explaining the format because it will be helpful for writing short files by hand for testing purposes.

In order to play sounds you produce, you need a way to convert between the .dat format and a format that common media players (Windows Media Player, winamp, RealPlayer, etc.) understand, such as .wav.

sox allows you to convert to and from .dat sound files. The .dat files are useful because they are human-readable, text-based, sound files. Many versions of sox are available. You can download the one you need from https://sourceforge.net/projects/sox/files/sox/ by clicking on the folder for the most recent version (e.g., "Download sox-14.4.2-win32.exe (2.7 MB)") and then downloading the correct file for your operating system.

The Windows and Mac version are also a command-line program and work in the same way as the UNIX version described below. See below for some pointers on using it.

For those of you who are not familiar with command-line operations, here is how to use the sox program from Windows.
1. download the "sox12181" zip file from SourceForge. Unzip and extract the sox file to your desktop.
2. In windows: click Start -> All Programs -> Accessories -> Command Prompt. A command-line window should appear.
3. In the Command Prompt window, type: cd desktop
4. In the Command Prompt window: (with the sound file you wish to convert on the desktop as well), type sox secret.wav secret.dat
5. Now you should see the converted file secret.dat on your desktop.

The general strategy for using sox is as follows.
1. Take a .wav sound file of your choosing, e.g., mysong.wav. This sound shouldn't be longer than a few seconds, or your program will run out of memory.
2. Convert it to a .dat file: sox mysong.wav mysong.dat
3. Manipulate it with the program you will write: java Reverse list mysong.dat mysong-reversed.dat
4. Convert it back to a .wav file: sox mysong-reversed.dat mysong-reversed.wav
5. Listen to it with your favorite sound player.

That's all there is to it! You may send your reversed secret .dat file to your classmate and ask him/her to reverse it and find the original message

2.4. Questions
Submit a report (in word or pdf), answering the questions below.
1. How did you test that your stack implementations were correct?
2. Your array stacks start with a small array and double in size if they become full. For
a .dat file with 1 million lines, how many times would this resizing occur? What about with 1 billion lines or 1 trillion lines (assuming the computer had enough memory)? Explain your answer.
3. Include a description of how your project goes "bonus components" the basic requirements (if it does).
4. What did you enjoy about this assignment? What did you not enjoy? What could you have done better?
5. What else, if anything, would you would like to include related to this homework?
2.5. Bonus Components (5 points) - Shrink the array when needed
The following suggestion is meant for you to try if you finish the requirements early.

Modify your array implementations so that when the array is 3/4 empty, the stack resizes to use an array of half the size.

2.6. Java Help
For this assignment you need to implement an interface, DStack, in two ways. The DStack interface defines a simple stack:
public interface DStack { public boolean isEmpty(); public void push(double d); public double pop();
public double peek(); }

An actual interface includes comments, including a description of how pop() and peek() should behave if they are called when the stack is empty. To implement this interface, write a class as follows:
public class ArrayStack implements DStack {
public ArrayStack() { // Your constructor code
}
public boolean isEmpty() { // Your isEmpty() code
}
public void push(double d) { // Your push() code
}
// continue with the rest of the methods,
// along with any fields, etc. }

The ListStack class should be defined similarly. You should include appropriate comments as needed. In particular, each file should begin with a comment that describes the class in the file, and includes your name and other identifying information.

Reference no: EM13960876

Questions Cloud

Draw tree diagram to illustrate the different possibilities : Draw a tree diagram to illustrate the different possibilities. In hoe many ways will the 2nd , 3rd, and 4th coins all turn heads.
Find the magnitude and direction of the force acting on q : Is there any change in the solution if the sphere is kept at a fixed potential V? What about if the sphere has a total charge Q on its inner and outer surfaces?
Correct match between subpart and regulated material : Which of the following is a correct match between subpart and regulated material? All of the following are exempt under the Act except which group
Riordan manufacturing virtual organization : An increase in spending on items related to hardware, software, and outside IT support services by 4 percentA decrease the overall budget by 2 percent
Implement stacks for java double numbers : Your Stack implementations will be used to do sound manipulation, namely reversing a sound clip. This process, called "backmasking," was used by musicians including the Beatles, Jimi Hendrix, and Ozzy Ozbourne. You will write a program that reads ..
Calculate the surface-charge densities at an arbitrary point : Calculate the surface-charge densities at an arbitrary point on the plane and on the boss, and sketch their behavior as a function of distance (or angle).
How did the employees react to the changes : IBM and Xerox flourished during the 80's with new office machines. How do you think the companies handled the change in the work environment? Why or why not. Cite an example for each company. Try to recall a change in your organization. How did the e..
Find the standard deviation in the given problem : Find the standard deviation. Using the information in the table on home sale prices in the city of Orlando for the month June, find the mean for the grouped data.
Find the force per unit length on the line charge : A line charge with linear charge density T is placed parallel to, and a distance R away from, the axis of a conducting cylinder of radius b held at a fixed voltage such that the potential vanishes at infinity.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  The government should never use fiscal policy

The government should never use fiscal policy to combat business cycle fluctuations coming from changes in autonomous investment if it also wishes to keep longer term movements in the price level to a minimum. Is this claim true, false or uncertain?

  Genetic algorithms can help scientists

Discuss how expert systems, neural networks, and genetic algorithms can help scientists meet medical challenges. Provide an example of each system.

  Write a sample program that asks for the center

Write a sample program that asks for the center and side length, then prints out the square (using the toString method that you inherit from Rectangle) and the area of the square.

  Identify and discuss the technologies that have gone

Identify and discuss the technologies that have gone from analog to digital. What was the reasoning for each conversion? Include a question that responding students can reply to within your initial post(s)

  Create a website consisting of many pages

create a website consisting of many pages organized in groups of pages linked off of the main page. The website hierarchy and key page namesare given

  Give the java statement needed

How do you specify that the color orange will be used as fill when using the Graphics class? Give the Java statement needed.

  What does it mean if they are public or private

When creating classes you have member functions and member variables. What are they and what data types can you use for member variables

  Make a list of the field names and field types

1.Make a list of the field names and field types you plan to include in the table. What fields are you going to put in this table? What are their field types? Would it make sense to reduce any of the field sizes? Do you need to add captions?

  Find out the number of candidate keys

A relation R(ABCDEF) and functional dependency set F={AB->CDEF ,F->C,C->A,B->D,D->E,F->B}. Find out the number of candidate keys

  Calculate population increase

The output then would be that count. You will want to use 2 variables, one for the index of the for loop ( and the counter in the do loop) and the other variable to keep track of your "current" population.

  The concepts of legal writing

In this assignment, we will attemptto utilize some of the concepts of legal writing that we will discuss in class.Below you will find an essay that, to put it mildly, needs a bit of work. Thewording is verbose and uses “slang”. There is no focus or o..

  Normally distributed with a population standard deviation

The heights were recorded for a Simple Random Sample of 270 freshmen. The mean of this sample was 66.5 inches. The heights are known to be Normally Distributed with a population standard deviation of 5.1 inches. Round answers to one decimal plac..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd