473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

StringPile

CISC 3115
Project 1: StringPile, once again

Introduction

We've talked about the StringPile code a couple times already, so let's finish the job. (If you need a reminder, here is the exercise assignment from earlier.) In this project, your main goal is to complete an implementation of the StringPile class and to write a main program that tests and runs it. But there are a couple additional wrinkles...

Phase One

Complete an implementation of the StringPile class, and write a main program that tests it. Your main program must be in a class called PileTester. In particular, your tester should read from standard input (System.in) and write to standard output (System.out). It should simply call the four StringPile methods in order: first load, then get (and print) the shortest and longest strings, then print the pile in sorted order. So, if your input is

the
beautiful
hippo
Then your output should be
the
beautiful
beautiful
hippo
the
Note that there is NO OTHER OUTPUT.
Also note that all modern operating systems allow you to "redirect" standard input and output to files. So, if your input is in the file input.txt, then the command

java PileTester < input.txt > output.txt
will run PileTester on the data in that file, and write the results to output.txt.
Phase Two

Style and documentation! When you are writing a Java program (or a program in most any language), your main audience is not the computer but other human beings. Your code must be easy for other programmers to read, digest, and comprehend. This is why variable names, whitespace, and other "fussy" things are so important. Indeed, most software companies have their own "style guides" so that everyone's code follows the same conventions, so everyone knows what they're looking at. For this class, I've made a simplified version of Google's Java style guidelines. There are a few items in the guidelines that don't apply to this project (like enum, exceptions, and a few other small things). But everything through section 5 should be pretty clear. Make sure you adhere to this guide!

Section 7 discusses something called "javadoc," which we will talk about later. For now, use "regular comments" and be sure that you document the purpose of: variables, methods, classes; you may also want to document any particularly tricky implementation details.

Phase Three

Finally: timing is everything! We talked a bit about how your choice of implementation will affect how quickly each of your methods run. So, now make a copy of your PileTester class, and call it PileTimer. Java (of course) gives us some tools that help us time the execution of parts of our applications. This page has a somewhat detailed discussion, but here's the deal: we can ask the JVM to record the time before we do something, then again after; if we subtract them, we get the execution time (or something very close) of the task. So we could write

long startTime = System.nanoTime();

// ... do something interesting here ...

long endTime = System.nanoTime();
System.out.println("That took " + (endTime - startTime)/1000000.0 + " milliseconds);
(Note that I divided by a million in floating point to get fractional milliseconds.)
Use this technique to time the four methods you call in PileTimer. These should be, y'know, pretty fast, though the exact timings will depend on your hardware and other factors. If you want to compare, here is the classfile for a class called FastStringPile—your code should work about as quickly as this code does.

(If you want a nice juicy file full of words to test on, try this one.)
Oct 31 '18 #1
1 1932
chaarmann
785 Expert 512MB
Show us what you have done so far (list you code here) and tell us where you are stuck, then we will help. If we spoonfeed you the solution then you won't learn!
Apr 5 '19 #2

Sign in to post your reply or Sign up for a free account.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.