SlideShare a Scribd company logo
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;
/**
* Read a .dat file and reverse it.
* CPS 350
*/
public class Reverse {
public static void main(String[]args) {
if (args.length != 3) {
System.err.println(" Incorrect number of arguments");
System.err.println(" Usage: ");
System.err.
println("tjava Reverse <stack type> <input file>
<output file>");
System.exit(1);
}
boolean useList = true;
if (args[0].compareTo("list")==0)
useList = true;
else if (args[0].compareTo("array")==0)
useList = false;
else {
System.err.println("tSaw "+args[0]+" instead of list or
array as first argument");
System.exit(1);
}
try {
//
// Set up the input file to read, and the output file to
write to
//
BufferedReader fileIn =
new BufferedReader(new FileReader(args[1]));
PrintWriter fileOut =
new PrintWriter(new
BufferedWriter(new FileWriter(args[2])));
//
// Read the first line of the .dat file to get sample rate.
// We want to store the sample rate value in a variable,
// but we can ignore the "; Sample Rate" part of the line.
// Step through the first line one token (word) at a time
// using the StringTokenizer. The fourth token is the
one
// we want (the sample rate).
//
StringTokenizer str;
String oneLine;
int sampleRate;
String strJunk;
oneLine = fileIn.readLine();
str = new StringTokenizer(oneLine);
strJunk = str.nextToken(); // Read in semicolon
strJunk = str.nextToken(); // Read in "Sample"
strJunk = str.nextToken(); // Read in "Rate"
// Read in sample rate
sampleRate = Integer.parseInt(str.nextToken());
//
// Read in the remainder of the file on line at a time.
// The values in the first column are thrown away.
// Place values from the second column on the stack.
// Stop reading if we reach the end of the file.
//
DStack s;
if (useList)
s = new ListStack();
else
s = new ArrayStack();
String timestep;
double data;
int count = 0;
while ((oneLine = fileIn.readLine()) != null) {
if (oneLine.charAt(0) == ';') {
continue;
}
str = new StringTokenizer(oneLine);
// Read in time step value from first column
timestep = str.nextToken();
// Read in data value from second column
data = Double.parseDouble(str.nextToken());
s.push(data);
count++;
}
System.out.println(count+" samples in file");
//
// Print the data values to output .dat file.
// First, output the header line:
// "; Sample Rate <sample rate>"
//
fileOut.println("; Sample Rate " + sampleRate);
// Since the first column consists of numbers which start
// at 0 and increase by 1/sampleRate every time slice,
we'll
// just use numSteps to recalculate these numbers.
int numSteps = 0;
// Finally, we print the values in reverse order (by
popping
// them off the stack). The first column consists of
numbers
// which start at 0 and increase by 1/sampleRate per
row, so
// we'll use numSteps/sampleRate to recalculate the
appropriate
// values. Print a tab for uniform spacing.
while (!s.isEmpty()) {
fileOut.println((double) numSteps / sampleRate +
"t" +
s.pop());
numSteps++;
}
//
// Close the files
//
fileIn.close();
fileOut.close();
} catch(IOException ioe) {
System.err.
println
("Error opening/reading/writing input or output file.");
System.exit(1);
} catch(NumberFormatException nfe) {
System.err.println(nfe.toString());
System.err.println("Error in file format");
System.exit(1);
}
}
}
/**
* Interface for a stack of primitive doubles.
* CPS 350
*
* NOTE: You will
* need to write something better for your implementations.
*/
public interface DStack {
/**
* is empty?
*/
public boolean isEmpty();
/**
* push
*/
public void push(double d);
/**
* pop
* @return the deleted value
* @throws EmptyStackException if stack is empty
*/
public double pop();
/**
* peek
* @throws EmptyStackException if stack is empty
*/
public double peek();
}
CPS 350: Assignment 1
Due 11:55 pm, 2/1/2017 (100 pts)
No late submission will be accepted
Receive 5 bonus points if turn in the complete work without
errors at least one day before deadline
Receive an F for this course if any academic dishonesty occurs
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 (70 points)
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 (10 points)
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
0 0
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
http://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 (20 points)
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.
3. Grading notes
If your program does not compile, you receive zero points for
that program. Additional
deductions:
1. (5 points) Your code does not follow the style guide
discussed in class/textbook.
2. (30 points) Your code does not have author name, date,
purpose of this program,
comments on the variables and methods, etc.
4. Turn in
ZIP the following files. Submit the ZIP to isidore.
• ArrayStack.java
• ListStack.java
• ListStackNode.java, the linked-list node for use with your
ListStack class. However,
you are also free to use an inner class inside ListStack in which
case you will not have a
separate file.
• Write answers for 2.4) Questions in a word file. Print the word
file and submit it in class.

More Related Content

Similar to import java.io.BufferedReader;import java.io.BufferedWriter;.docx

CMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docx
CMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docxCMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docx
CMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docxmary772
 
(2) c sharp introduction_basics_part_i
(2) c sharp introduction_basics_part_i(2) c sharp introduction_basics_part_i
(2) c sharp introduction_basics_part_iNico Ludwig
 
Description 1) Create a Lab2 folder for this project2.docx
Description       1)  Create a Lab2 folder for this project2.docxDescription       1)  Create a Lab2 folder for this project2.docx
Description 1) Create a Lab2 folder for this project2.docxtheodorelove43763
 
ch06-file-processing.ppt
ch06-file-processing.pptch06-file-processing.ppt
ch06-file-processing.pptMahyuddin8
 
PAGE 1Input output for a file tutorialStreams and File IOI.docx
PAGE  1Input output for a file tutorialStreams and File IOI.docxPAGE  1Input output for a file tutorialStreams and File IOI.docx
PAGE 1Input output for a file tutorialStreams and File IOI.docxalfred4lewis58146
 
OverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docxOverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docxalfred4lewis58146
 
Change the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdfChange the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdfsecunderbadtirumalgi
 
Question 1 has already been posted to Chegg and I am waiting for the.pdf
Question 1 has already been posted to Chegg and I am waiting for the.pdfQuestion 1 has already been posted to Chegg and I am waiting for the.pdf
Question 1 has already been posted to Chegg and I am waiting for the.pdfanjandavid
 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfinfo309708
 
r,rstats,r language,r packages
r,rstats,r language,r packagesr,rstats,r language,r packages
r,rstats,r language,r packagesAjay Ohri
 
1 of 9 CSCE 3600 Systems Programming Major Assignm.docx
  1 of 9 CSCE 3600 Systems Programming  Major Assignm.docx  1 of 9 CSCE 3600 Systems Programming  Major Assignm.docx
1 of 9 CSCE 3600 Systems Programming Major Assignm.docxShiraPrater50
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxdunhamadell
 

Similar to import java.io.BufferedReader;import java.io.BufferedWriter;.docx (20)

CMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docx
CMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docxCMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docx
CMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docx
 
Basic input-output-v.1.1
Basic input-output-v.1.1Basic input-output-v.1.1
Basic input-output-v.1.1
 
(2) c sharp introduction_basics_part_i
(2) c sharp introduction_basics_part_i(2) c sharp introduction_basics_part_i
(2) c sharp introduction_basics_part_i
 
Description 1) Create a Lab2 folder for this project2.docx
Description       1)  Create a Lab2 folder for this project2.docxDescription       1)  Create a Lab2 folder for this project2.docx
Description 1) Create a Lab2 folder for this project2.docx
 
ch06-file-processing.ppt
ch06-file-processing.pptch06-file-processing.ppt
ch06-file-processing.ppt
 
Java 3 Computer Science.pptx
Java 3 Computer Science.pptxJava 3 Computer Science.pptx
Java 3 Computer Science.pptx
 
IO and threads Java
IO and threads JavaIO and threads Java
IO and threads Java
 
PAGE 1Input output for a file tutorialStreams and File IOI.docx
PAGE  1Input output for a file tutorialStreams and File IOI.docxPAGE  1Input output for a file tutorialStreams and File IOI.docx
PAGE 1Input output for a file tutorialStreams and File IOI.docx
 
srgoc
srgocsrgoc
srgoc
 
15. text files
15. text files15. text files
15. text files
 
OverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docxOverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docx
 
Aggregate.pptx
Aggregate.pptxAggregate.pptx
Aggregate.pptx
 
Tech talk
Tech talkTech talk
Tech talk
 
Keras and TensorFlow
Keras and TensorFlowKeras and TensorFlow
Keras and TensorFlow
 
Change the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdfChange the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdf
 
Question 1 has already been posted to Chegg and I am waiting for the.pdf
Question 1 has already been posted to Chegg and I am waiting for the.pdfQuestion 1 has already been posted to Chegg and I am waiting for the.pdf
Question 1 has already been posted to Chegg and I am waiting for the.pdf
 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
 
r,rstats,r language,r packages
r,rstats,r language,r packagesr,rstats,r language,r packages
r,rstats,r language,r packages
 
1 of 9 CSCE 3600 Systems Programming Major Assignm.docx
  1 of 9 CSCE 3600 Systems Programming  Major Assignm.docx  1 of 9 CSCE 3600 Systems Programming  Major Assignm.docx
1 of 9 CSCE 3600 Systems Programming Major Assignm.docx
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docx
 

More from wilcockiris

Barbara Silva is the CIO for Peachtree Community Hospital in Atlanta.docx
Barbara Silva is the CIO for Peachtree Community Hospital in Atlanta.docxBarbara Silva is the CIO for Peachtree Community Hospital in Atlanta.docx
Barbara Silva is the CIO for Peachtree Community Hospital in Atlanta.docxwilcockiris
 
BARGAIN CITY Your career is moving along faster than you e.docx
BARGAIN CITY Your career is moving along faster than you e.docxBARGAIN CITY Your career is moving along faster than you e.docx
BARGAIN CITY Your career is moving along faster than you e.docxwilcockiris
 
Barbara schedules a meeting with a core group of clinic  managers. T.docx
Barbara schedules a meeting with a core group of clinic  managers. T.docxBarbara schedules a meeting with a core group of clinic  managers. T.docx
Barbara schedules a meeting with a core group of clinic  managers. T.docxwilcockiris
 
Barbara schedules a meeting with a core group of clinic managers.docx
Barbara schedules a meeting with a core group of clinic managers.docxBarbara schedules a meeting with a core group of clinic managers.docx
Barbara schedules a meeting with a core group of clinic managers.docxwilcockiris
 
Barbara schedules a meeting with a core group of clinic managers. Th.docx
Barbara schedules a meeting with a core group of clinic managers. Th.docxBarbara schedules a meeting with a core group of clinic managers. Th.docx
Barbara schedules a meeting with a core group of clinic managers. Th.docxwilcockiris
 
Barbara Rosenwein, A Short History of the Middle Ages 4th edition (U.docx
Barbara Rosenwein, A Short History of the Middle Ages 4th edition (U.docxBarbara Rosenwein, A Short History of the Middle Ages 4th edition (U.docx
Barbara Rosenwein, A Short History of the Middle Ages 4th edition (U.docxwilcockiris
 
BARBARA NGAM, MPAShoreline, WA 98155 ▪ 801.317.5999 ▪ [email pro.docx
BARBARA NGAM, MPAShoreline, WA 98155 ▪ 801.317.5999 ▪ [email pro.docxBARBARA NGAM, MPAShoreline, WA 98155 ▪ 801.317.5999 ▪ [email pro.docx
BARBARA NGAM, MPAShoreline, WA 98155 ▪ 801.317.5999 ▪ [email pro.docxwilcockiris
 
Banks 5Maya BanksProfessor Debra MartinEN106DLGU1A2018.docx
Banks    5Maya BanksProfessor Debra MartinEN106DLGU1A2018.docxBanks    5Maya BanksProfessor Debra MartinEN106DLGU1A2018.docx
Banks 5Maya BanksProfessor Debra MartinEN106DLGU1A2018.docxwilcockiris
 
Banking industry•Databases that storeocorporate sensiti.docx
Banking industry•Databases that storeocorporate sensiti.docxBanking industry•Databases that storeocorporate sensiti.docx
Banking industry•Databases that storeocorporate sensiti.docxwilcockiris
 
BAOL 531 Managerial AccountingWeek Three Article Research Pape.docx
BAOL 531 Managerial AccountingWeek Three Article Research Pape.docxBAOL 531 Managerial AccountingWeek Three Article Research Pape.docx
BAOL 531 Managerial AccountingWeek Three Article Research Pape.docxwilcockiris
 
bankCustomer1223333SmithJamesbbbbbb12345 Abrams Rd Dallas TX 75043.docx
bankCustomer1223333SmithJamesbbbbbb12345 Abrams Rd Dallas TX 75043.docxbankCustomer1223333SmithJamesbbbbbb12345 Abrams Rd Dallas TX 75043.docx
bankCustomer1223333SmithJamesbbbbbb12345 Abrams Rd Dallas TX 75043.docxwilcockiris
 
Barbara and Judi entered into a contract with Linda, which provi.docx
Barbara and Judi entered into a contract with Linda, which provi.docxBarbara and Judi entered into a contract with Linda, which provi.docx
Barbara and Judi entered into a contract with Linda, which provi.docxwilcockiris
 
bappsum.indd 614 182014 30258 PMHuman Reso.docx
bappsum.indd   614 182014   30258 PMHuman Reso.docxbappsum.indd   614 182014   30258 PMHuman Reso.docx
bappsum.indd 614 182014 30258 PMHuman Reso.docxwilcockiris
 
Bank ReservesSuppose that the reserve ratio is .25, and that a b.docx
Bank ReservesSuppose that the reserve ratio is .25, and that a b.docxBank ReservesSuppose that the reserve ratio is .25, and that a b.docx
Bank ReservesSuppose that the reserve ratio is .25, and that a b.docxwilcockiris
 
Bank Services, Grading GuideFIN366 Version 21Individual.docx
Bank Services, Grading GuideFIN366 Version 21Individual.docxBank Services, Grading GuideFIN366 Version 21Individual.docx
Bank Services, Grading GuideFIN366 Version 21Individual.docxwilcockiris
 
Baldwins Kentucky Revised Statutes AnnotatedTitle XXXV. Domesti.docx
Baldwins Kentucky Revised Statutes AnnotatedTitle XXXV. Domesti.docxBaldwins Kentucky Revised Statutes AnnotatedTitle XXXV. Domesti.docx
Baldwins Kentucky Revised Statutes AnnotatedTitle XXXV. Domesti.docxwilcockiris
 
Bank confirmations are critical to the cash audit. What information .docx
Bank confirmations are critical to the cash audit. What information .docxBank confirmations are critical to the cash audit. What information .docx
Bank confirmations are critical to the cash audit. What information .docxwilcockiris
 
BalShtBalance SheetBalance SheetBalance SheetBalance SheetThe Fran.docx
BalShtBalance SheetBalance SheetBalance SheetBalance SheetThe Fran.docxBalShtBalance SheetBalance SheetBalance SheetBalance SheetThe Fran.docx
BalShtBalance SheetBalance SheetBalance SheetBalance SheetThe Fran.docxwilcockiris
 
BAM 515 - Organizational Behavior(Enter your answers on th.docx
BAM 515 - Organizational Behavior(Enter your answers on th.docxBAM 515 - Organizational Behavior(Enter your answers on th.docx
BAM 515 - Organizational Behavior(Enter your answers on th.docxwilcockiris
 
BalanchineGeorge Balanchine is an important figure in the histor.docx
BalanchineGeorge Balanchine is an important figure in the histor.docxBalanchineGeorge Balanchine is an important figure in the histor.docx
BalanchineGeorge Balanchine is an important figure in the histor.docxwilcockiris
 

More from wilcockiris (20)

Barbara Silva is the CIO for Peachtree Community Hospital in Atlanta.docx
Barbara Silva is the CIO for Peachtree Community Hospital in Atlanta.docxBarbara Silva is the CIO for Peachtree Community Hospital in Atlanta.docx
Barbara Silva is the CIO for Peachtree Community Hospital in Atlanta.docx
 
BARGAIN CITY Your career is moving along faster than you e.docx
BARGAIN CITY Your career is moving along faster than you e.docxBARGAIN CITY Your career is moving along faster than you e.docx
BARGAIN CITY Your career is moving along faster than you e.docx
 
Barbara schedules a meeting with a core group of clinic  managers. T.docx
Barbara schedules a meeting with a core group of clinic  managers. T.docxBarbara schedules a meeting with a core group of clinic  managers. T.docx
Barbara schedules a meeting with a core group of clinic  managers. T.docx
 
Barbara schedules a meeting with a core group of clinic managers.docx
Barbara schedules a meeting with a core group of clinic managers.docxBarbara schedules a meeting with a core group of clinic managers.docx
Barbara schedules a meeting with a core group of clinic managers.docx
 
Barbara schedules a meeting with a core group of clinic managers. Th.docx
Barbara schedules a meeting with a core group of clinic managers. Th.docxBarbara schedules a meeting with a core group of clinic managers. Th.docx
Barbara schedules a meeting with a core group of clinic managers. Th.docx
 
Barbara Rosenwein, A Short History of the Middle Ages 4th edition (U.docx
Barbara Rosenwein, A Short History of the Middle Ages 4th edition (U.docxBarbara Rosenwein, A Short History of the Middle Ages 4th edition (U.docx
Barbara Rosenwein, A Short History of the Middle Ages 4th edition (U.docx
 
BARBARA NGAM, MPAShoreline, WA 98155 ▪ 801.317.5999 ▪ [email pro.docx
BARBARA NGAM, MPAShoreline, WA 98155 ▪ 801.317.5999 ▪ [email pro.docxBARBARA NGAM, MPAShoreline, WA 98155 ▪ 801.317.5999 ▪ [email pro.docx
BARBARA NGAM, MPAShoreline, WA 98155 ▪ 801.317.5999 ▪ [email pro.docx
 
Banks 5Maya BanksProfessor Debra MartinEN106DLGU1A2018.docx
Banks    5Maya BanksProfessor Debra MartinEN106DLGU1A2018.docxBanks    5Maya BanksProfessor Debra MartinEN106DLGU1A2018.docx
Banks 5Maya BanksProfessor Debra MartinEN106DLGU1A2018.docx
 
Banking industry•Databases that storeocorporate sensiti.docx
Banking industry•Databases that storeocorporate sensiti.docxBanking industry•Databases that storeocorporate sensiti.docx
Banking industry•Databases that storeocorporate sensiti.docx
 
BAOL 531 Managerial AccountingWeek Three Article Research Pape.docx
BAOL 531 Managerial AccountingWeek Three Article Research Pape.docxBAOL 531 Managerial AccountingWeek Three Article Research Pape.docx
BAOL 531 Managerial AccountingWeek Three Article Research Pape.docx
 
bankCustomer1223333SmithJamesbbbbbb12345 Abrams Rd Dallas TX 75043.docx
bankCustomer1223333SmithJamesbbbbbb12345 Abrams Rd Dallas TX 75043.docxbankCustomer1223333SmithJamesbbbbbb12345 Abrams Rd Dallas TX 75043.docx
bankCustomer1223333SmithJamesbbbbbb12345 Abrams Rd Dallas TX 75043.docx
 
Barbara and Judi entered into a contract with Linda, which provi.docx
Barbara and Judi entered into a contract with Linda, which provi.docxBarbara and Judi entered into a contract with Linda, which provi.docx
Barbara and Judi entered into a contract with Linda, which provi.docx
 
bappsum.indd 614 182014 30258 PMHuman Reso.docx
bappsum.indd   614 182014   30258 PMHuman Reso.docxbappsum.indd   614 182014   30258 PMHuman Reso.docx
bappsum.indd 614 182014 30258 PMHuman Reso.docx
 
Bank ReservesSuppose that the reserve ratio is .25, and that a b.docx
Bank ReservesSuppose that the reserve ratio is .25, and that a b.docxBank ReservesSuppose that the reserve ratio is .25, and that a b.docx
Bank ReservesSuppose that the reserve ratio is .25, and that a b.docx
 
Bank Services, Grading GuideFIN366 Version 21Individual.docx
Bank Services, Grading GuideFIN366 Version 21Individual.docxBank Services, Grading GuideFIN366 Version 21Individual.docx
Bank Services, Grading GuideFIN366 Version 21Individual.docx
 
Baldwins Kentucky Revised Statutes AnnotatedTitle XXXV. Domesti.docx
Baldwins Kentucky Revised Statutes AnnotatedTitle XXXV. Domesti.docxBaldwins Kentucky Revised Statutes AnnotatedTitle XXXV. Domesti.docx
Baldwins Kentucky Revised Statutes AnnotatedTitle XXXV. Domesti.docx
 
Bank confirmations are critical to the cash audit. What information .docx
Bank confirmations are critical to the cash audit. What information .docxBank confirmations are critical to the cash audit. What information .docx
Bank confirmations are critical to the cash audit. What information .docx
 
BalShtBalance SheetBalance SheetBalance SheetBalance SheetThe Fran.docx
BalShtBalance SheetBalance SheetBalance SheetBalance SheetThe Fran.docxBalShtBalance SheetBalance SheetBalance SheetBalance SheetThe Fran.docx
BalShtBalance SheetBalance SheetBalance SheetBalance SheetThe Fran.docx
 
BAM 515 - Organizational Behavior(Enter your answers on th.docx
BAM 515 - Organizational Behavior(Enter your answers on th.docxBAM 515 - Organizational Behavior(Enter your answers on th.docx
BAM 515 - Organizational Behavior(Enter your answers on th.docx
 
BalanchineGeorge Balanchine is an important figure in the histor.docx
BalanchineGeorge Balanchine is an important figure in the histor.docxBalanchineGeorge Balanchine is an important figure in the histor.docx
BalanchineGeorge Balanchine is an important figure in the histor.docx
 

Recently uploaded

INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfbu07226
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasiemaillard
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfVivekanand Anglo Vedic Academy
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resourcesaileywriter
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxbennyroshan06
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfjoachimlavalley1
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...Nguyen Thanh Tu Collection
 
Forest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDFForest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDFVivekanand Anglo Vedic Academy
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxRaedMohamed3
 
NLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptxNLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptxssuserbdd3e8
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxricssacare
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasiemaillard
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptxmansk2
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleCeline George
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportAvinash Rai
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPCeline George
 

Recently uploaded (20)

INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
Forest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDFForest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDF
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
NLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptxNLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptx
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 

import java.io.BufferedReader;import java.io.BufferedWriter;.docx

  • 1. import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.StringTokenizer; /** * Read a .dat file and reverse it. * CPS 350 */ public class Reverse { public static void main(String[]args) { if (args.length != 3) { System.err.println(" Incorrect number of arguments"); System.err.println(" Usage: ");
  • 2. System.err. println("tjava Reverse <stack type> <input file> <output file>"); System.exit(1); } boolean useList = true; if (args[0].compareTo("list")==0) useList = true; else if (args[0].compareTo("array")==0) useList = false; else { System.err.println("tSaw "+args[0]+" instead of list or array as first argument"); System.exit(1); } try {
  • 3. // // Set up the input file to read, and the output file to write to // BufferedReader fileIn = new BufferedReader(new FileReader(args[1])); PrintWriter fileOut = new PrintWriter(new BufferedWriter(new FileWriter(args[2]))); // // Read the first line of the .dat file to get sample rate. // We want to store the sample rate value in a variable, // but we can ignore the "; Sample Rate" part of the line. // Step through the first line one token (word) at a time // using the StringTokenizer. The fourth token is the one // we want (the sample rate). //
  • 4. StringTokenizer str; String oneLine; int sampleRate; String strJunk; oneLine = fileIn.readLine(); str = new StringTokenizer(oneLine); strJunk = str.nextToken(); // Read in semicolon strJunk = str.nextToken(); // Read in "Sample" strJunk = str.nextToken(); // Read in "Rate" // Read in sample rate sampleRate = Integer.parseInt(str.nextToken()); // // Read in the remainder of the file on line at a time. // The values in the first column are thrown away.
  • 5. // Place values from the second column on the stack. // Stop reading if we reach the end of the file. // DStack s; if (useList) s = new ListStack(); else s = new ArrayStack(); String timestep; double data; int count = 0; while ((oneLine = fileIn.readLine()) != null) { if (oneLine.charAt(0) == ';') { continue; } str = new StringTokenizer(oneLine);
  • 6. // Read in time step value from first column timestep = str.nextToken(); // Read in data value from second column data = Double.parseDouble(str.nextToken()); s.push(data); count++; } System.out.println(count+" samples in file"); // // Print the data values to output .dat file. // First, output the header line: // "; Sample Rate <sample rate>" // fileOut.println("; Sample Rate " + sampleRate);
  • 7. // Since the first column consists of numbers which start // at 0 and increase by 1/sampleRate every time slice, we'll // just use numSteps to recalculate these numbers. int numSteps = 0; // Finally, we print the values in reverse order (by popping // them off the stack). The first column consists of numbers // which start at 0 and increase by 1/sampleRate per row, so // we'll use numSteps/sampleRate to recalculate the appropriate // values. Print a tab for uniform spacing. while (!s.isEmpty()) { fileOut.println((double) numSteps / sampleRate + "t" + s.pop());
  • 8. numSteps++; } // // Close the files // fileIn.close(); fileOut.close(); } catch(IOException ioe) { System.err. println ("Error opening/reading/writing input or output file."); System.exit(1); } catch(NumberFormatException nfe) { System.err.println(nfe.toString()); System.err.println("Error in file format"); System.exit(1);
  • 9. } } } /** * Interface for a stack of primitive doubles. * CPS 350 * * NOTE: You will * need to write something better for your implementations. */ public interface DStack { /** * is empty? */ public boolean isEmpty(); /**
  • 10. * push */ public void push(double d); /** * pop * @return the deleted value * @throws EmptyStackException if stack is empty */ public double pop(); /** * peek * @throws EmptyStackException if stack is empty */ public double peek(); }
  • 11. CPS 350: Assignment 1 Due 11:55 pm, 2/1/2017 (100 pts) No late submission will be accepted Receive 5 bonus points if turn in the complete work without errors at least one day before deadline Receive an F for this course if any academic dishonesty occurs 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
  • 12. 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 (70 points) 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
  • 13. 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 (10 points) 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
  • 14. 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 0 0
  • 15. 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
  • 16. 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 http://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
  • 17. 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.
  • 18. 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 (20 points) 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
  • 19. 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();
  • 20. 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
  • 21. } // 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. 3. Grading notes If your program does not compile, you receive zero points for that program. Additional deductions: 1. (5 points) Your code does not follow the style guide discussed in class/textbook. 2. (30 points) Your code does not have author name, date, purpose of this program, comments on the variables and methods, etc. 4. Turn in
  • 22. ZIP the following files. Submit the ZIP to isidore. • ArrayStack.java • ListStack.java • ListStackNode.java, the linked-list node for use with your ListStack class. However, you are also free to use an inner class inside ListStack in which case you will not have a separate file. • Write answers for 2.4) Questions in a word file. Print the word file and submit it in class.