rewrite exe class

| October 22, 2018

CIT
38800 Java II

Programming Assignment #04
(Varies according to how used…see last page)

File Handling and Exception
Processing

For this project, you will re- use all
of the files from Project #03 (instructor’s versions…not yours), except the executable
class. Your assignment is to re-code the executable class to read a single (1)
text file and create two (2) text output files. All files must be comma
delimited…commas must separate each input and/or output field with no extra
spaces. To accomplish this task, you also must retain the polymorphic
functionality coded in the Project #03 as supplied by your instructor. The
valid output file (more later) MUSTbe written from a Rocks array
in the same fashion as the screen output was written in Project 03 except this
time it is going to a file.


Note: Write only the four indicated
fields to the output file (see file specifications later) in order to save time
for completion of this project.

• Write
each field in the order indicated at the bottom of this document with NO
headings and no extra spaces formatted as indicated! Use a SINGLE UNIQUE ROW
for each record that is output. Again…each output field must be delimited by a
single comma with no extra spaces.

You must perform the following
tasks:

Create a
console-mode executable class (no GUI in this project; let’s keep it simple)
using the following specifications:


Name
your executable class RockFiles


Prompt the user to enter the full (absolute)
path and filename of the input file to read
o Read the path/file name
from the keyboard and use it for opening and processing the input file

o
The input file will contain an unknown
number of rows up to a maximum of 200 that will contain both good and
bad data

o
Using ONLY File class supplied
methods, test for file’s existence and the fact that it is
a file MUST be verified PRIORto opening the file.

§ If
file does not exist OR if the user entry is not a file,
exit the program immediately (do not try opening the file) and supply an
appropriate message to the screen explaining that they program is terminating
and why.

Hard-code(do
not prompt for & read) the absolute path and name of the first
outputfile.
o
Must be called validRecords.csv
and placed in the root directory of the “D:” drive.
§ Use
code that will allow it to be used on as many platforms as you can; don’t hard
code the separator ( or /)…demonstrated in class.
o
This is where you will write your
“valid” records from your array of type Rocks (the interface from the
last project)…yes, you again are using polymorphism.


Hard-codethe
absolute path and name of a second output file.
o
Must be called suspense.csv and
must also be placed in the root directory of the “D:” drive.
§ This
file will hold ALL records with formatting issues (wrong type of data in a
field), and/or the wrong number of fields necessary to instantiate ANY of the 3
classes used.
§ Hint:
If
a Monument object is to be instantiated and placed into the array, how many
fields should be onthe input line? What about the MonumentBase class?
You are still only to use the largest constructors of each class.
• Create
an array of type Rocks FROM THE VALID INPUT LINES ONLY (based upon the above
two qualifiers) in the same manner as the supplied Project 03 executable
class; after you validate the line and determine it is OK, just instantiate the
appropriate object and add the object to the array.
o
You must determine if a line is valid by
using exception processing (when appropriate) AND field (token) counting
(when appropriate) and any bad data lines are to be written to suspense.csv
EXACTLY AS THEY ARE/EXIST

IN THE INPUT FILE…just write the
entire input String row itself without any changes.

§ For a full
description of bad data, see below

§ The input file
layout that must be used follows at the end of this document


Write
to the “bad data” (suspense.csv) file, each line written EXACTLY
as it exists in the input file, when a line contains:
o
The incorrect number of fields to
instantiate EITHER of the 2 object types…Monument or MonumentBase
o
ORCharacter
or String data in a numeric field (improper format)
o
ORfloating
point data in an integer field (improper format)
§ Do
not worry about any other data checks; the above three are sufficient for this
project to cut down on programming time.

Create
a second file (validRecords.csv), WRITING IT FROM YOUR Rocks array AFTER
THE ARRAY HAS BEEN CREATED IN ITS ENTIRETY(entire input file
processed), which contains all validrecords/lines (and ONLY validrecords)
from the input file.
o
This must be the LAST function of
your program and written only after the Rocks Array has been satisfactorily

completed; write it
from a single loop that does nothing else but write the file.oA
record is valid when it passes the aforementioned data checks.

§ This,
obviously, must be written using the appropriate get methods that already exist
in the 2 classes being instantiated and placed into the Rocks array, to build
the entire line of text/record to be written.
§ Using
any way other than the existing get methods to obtain/write this data
will invalidate your project
§ Hint:Build one long
String using your get methods and write the single String. Look at the previous

projects; this has been
done before.

o
All
formatting (including decimal places) must be followed (as seen in the
sample output file) to receive full credit


Use exception processing/handling for
possible I/O exceptions.
o
All checked exceptions MUST
be handled…not just registered.

oAll
possible data formatting exceptions (a float where an int should be etc.) must
be handled. oSimply registering an exception is
insufficient.

o
Handle possible I/O (file opening,
closing, reading, writing, etc.) exceptions by displaying the stack trace
information to the screen (seen in class), followed by an appropriate exiting
message, and terminating the program.
• Do
not use the Exception superclass as the initial catch data type for ANY
exception processing. It may be used as a final “cleanup” type if desired (not
required). Specific exceptions must be used.


Do NOT place any more code than is
necessary within your try blocks; think!
o
Too much code in a try block will result
in a one point penalty for each statement that should not (in the instructor’s
opinion) be in the block.

• All
files must be written as text by writing a SINGLE ENTIRE TEXT LINE (one
record) with each write…not character by character or value by value.


You
must use the classes and interfaces from lab #03 AS SUPPLIED BY THE
INSTRUCTOR for this project.
o
Obviously the exception is the
driver/executable class…it is not used at all, but a great deal of the code
from it will probably be useful in this project. For example you can use a lot
of the display code to build the String to write to the file that will contain
valid output.

All
previous lab (“shop”) rules must be adhered to; be sure to check the list!

• Since
this lab has several goals (using exception processing/handling, tokenization,
and file handling) all of the following MUSTbe demonstrated:

o
Handling exceptions.
§ Note:
All exceptions must be handled by “catching” the exact exception that might be
thrown.
o
File handling.
§ Proper opening
and closing of files.


You must verify that the input file
exists and IS a file.
§ Reading a
complete line from a text file.

§ Writing
to a text file an entire line/record per write.oTokenization
creation & token handling.


Also…methods, classes, or techniques not
covered in class or in the text chapters covered may NOT be used. I want to see
you have mastered techniques we have covered.

• Modifying
ANY of the instructor-supplied code (except the executable class) is not
allowed and a grade of zero (0) will result.
o
It won’t run if you modify the supplied
code since you are only sending me the executable class.


Asking
for any input from the user, other than the single input file path & name
is not allowed.


Place ONLY your executable class
source file (RockFiles.java) in the assignment area. One file only should be
submitted! Since it must work with my supplied classes I will use my
copies. Submit the project no later than 5:00 PM on Monday

April
30th; no project
will be accepted late or incomplete.

Tips:

Start this one early; it has
a few twists and turns

When you
are writing text files for this project, each line being written must be a
String. You will need to build each line of output as a String prior to
writing it. You have seen this done in class on more than one occasion.
There is a STRONG possibility that
you will be seeing one or NULLPOINTEREXCEPTIONs as you progress.
Remember…these typically occur when you are trying to access an element of
an array of objects that is NULL; contains no object/value. Remember to
process your array until it finds a null element then stop.

Input File
Layout (all fields are delimited by a single comma; no spaces between fields)

REMEMBER THAT NOT ALL FIELDS WILL
EXIST IN EVERY LINE/RECORD

Quantity

Monument Width

Monument Thickness

Monument Height

Base Thickness

Base Diameter

(# of monuments &

(data
type: double)

(data type double)

(data type
double)

(data type double)

(data type double)

bases if bases apply)

(data type: int)

Look at the following examples and let’s
discuss the data:

40,44.75,13.5,38,12,65
25,40,13.5,36.75,12
30,42.7,15,34.25

22,44.6,25A,43.78,13,66.5

33.5,57.6,14.8,37.5
77,50.o,15,55

6,46,12,44,14,64

12,44,14,45,16,62

Output File Layout (all fields
are delimited by a single comma; no spaces between fields)

Display ONLY the following fields
(yes…in the real world it would be more!)

Order Number

Quantity Ordered

Total Cubic
Feet of WunderRock

Total Price

(data type int)

(data type int)

(data type double)

Just
start at 1000 and add 5 for each

additional
order

No Special formatting

No special formatting

Format to 3 decimal places

Format
to two decimal places

Look
at the following example and let’s discuss. Each field must be delimited by a
comma. Obviously the “x’s” must be replaced by valid data.

1000,xx,xxx.xxx,xxxxx.xx
1005,xx,xxxx.xxx,xxxxxxx.xx

Order your essay today and save 30% with the discount code: ESSAYHELP
Order your essay today and save 30% with the discount code: ESSAYHELPOrder Now