Professional Documents
Culture Documents
Assignment 8: Set Up
Assignment 8: Set Up
Assignment 8
Chapter 9, Exercise 9-1, Pages 321 & 322, Create and Work with Interfaces
Set Up
1. You will provide your personal Heading and Date classes, calling on them as appropriate in
the modification instructions below.
2. Our author offers start code and classes for you; however, the output is limited, as shown in
Exhibit A. Following the author’s instruction; which is what you will be performing initially,
you would end up with the following in Exhibit B.
Wheeeee!!
Exhibit B. Author’s Solution Class Output. Where you are headed by following the
Author’s instructions; this is not your final coding solution.
[ Continued ]
Exhibit C. Modified output. When in doubt as to an instruction, code to this Exhibit in these
situations. An Exhibit is the equivalent of written instruction(s) and, therefore, gradable in every
aspect.
Wm Bowers Page 1 of 7
Info 1521: Java Programming 1 Assignment 8
General Formatting
1. Top margin a minimum and maximum of two blank lines. The call to your personal Heading
class’s getHeading(…) method should perform that for you. If it does not, then correct your
personal getHeading(…) method, not this weekly application. You would be in copyright
violation, otherwise.
2. As shown above, Exhibit C, maintain a minimum and maximum left margin of two (2) blank
spaces. The use of blank lines must match mine, as well; too many are careless in their
production and coding and believe that just throwing something in the output does not matter.
Wm Bowers Page 2 of 7
Info 1521: Java Programming 1 Assignment 8
It does matter. You have a client to consider; just because it’s me makes no difference in
expectations.
3. Your overall alignment (columns, margins, spacing, etc.) of displayed data should resemble
mine. Just more practice for you; I know how much you enjoy the detail work. First Name,
Last Name and Department columns are left justified; the Salary $$$ column is right justified
and aligned on the decimal point, with the thousands separator displayed for any value over
999.99. The dollar sign is not used with any of the individual values.
4. Title Lines. Anything other than instructed\shown is considered a misspelling and a loss of 8-
points. You may call it a display difference, you may not consider it a misspelling; but, these
roses by any other name are still a loss of points for not following specific instructions.
b. A nice professional printer’s touch, note the spacing involved with the categories:
E M P L O Y E E S and P R O D U C T S and S E R V I C E S. All caps with a space
in between each letter.
c. Note the Spelling, capitalization of words, column alignment, decimal alignment and
the use of hyphens instead of underscores for the column headings.
d. At the closing, state “End of Report” ahead of the calls to your Date class’s printfDate()
and printfTime() methods. It is a title line, also: watch capitalization, as shown, and it
does not have a period at the end because it is not meant to be a sentence this time.
Why the changes? Because this is programming, and anything goes when it comes to
customer specifications.
5. Class DepartmentConstants.
a. Add two (2) more constant data members. Being constants and having the examples
set for you in the author’s solutions, as well as on page 283 of your text, add these:
SERVICES whose position will be assigned the value of 4.
PROGRAMMING whose position will be assigned the value of 5.
Note 1. Interface items may exist, but do not have to be necessarily used.
Note 2. I do require you capitalize these words as shown in the text. It is traditional
programming, and we will follow that path.
b. Do not forget to use the correct opening programmer’s comment citations which, as
you know, must be complete, current and correct.
Wm Bowers Page 3 of 7
Info 1521: Java Programming 1 Assignment 8
d. Do not forget to use the correct opening programmer’s comment citations which, as
you know, must be complete, current and correct.
7. Class Product.
a. Part of the Author’s Step 4 is to add a getDisplayText( ) method. One may use the
print( ) method found on Page 285 as a guide; however, that is coded to display the
output vertically. As you review Exhibit C, notice we are taking the horizontal route of
displaying information here, too. Two reasons for horizontal: first, it saves screen
space; second, it gives you much-needed conversion practice and source code which is
not in your text.
@Override
public String getDisplayText()
{ // added Step 4
String text = "";
text += " " + String.format("%-12s", getCode())
+ String.format("%-23s", getDescription())
+ String.format("%,14.2f", price)+ "\n";
return text;
}
b. Do not forget to use the correct opening programmer’s comment citations which, as
you know, must be complete, current and correct.
Wm Bowers Page 4 of 7
Info 1521: Java Programming 1 Assignment 8
8 Our own modification addition: create a class named Service. You have three choices: you
can create one from scratch, or you can model it on the Employee class, or you can model it
on the Product class. Look over the prospects of required output in Exhibit C. The
Employee class has four fields to display: first name, last name salary and department. The
Product class has three fields to display: code, title and price each. The Services class has
four fields to display: services, description, per hour and flat rate. I chose to model it on the
Product class to show you how to make more complicated (time consuming) changes. Do
what you wish, but here are my steps.
e. You already have a getFormattedPrice( ) method, don’t change it. But do add a
complete public String getFormattedFlatRate( ) method to handle the flatRate
variable.
@Override
public String getDisplayText()
{ // added Step 4
String text = "";
text += " " + String.format("%-12s", getCode())
+ String.format("%-21s", getDescription())
+ String.format("%,8.2f", price)
+ String.format("%,12.2f", flatRate) + "\n";
return text;
}
9. Class Displayable.
Wm Bowers Page 5 of 7
Info 1521: Java Programming 1 Assignment 8
However …
b. Do not forget to use the correct opening programmer’s comment citations which, as
you know, must be complete, current and correct.
a. At the class level; that is, ahead of main(…), declare and instantiate your personal
Heading class and personal Date class. We’ve done this before, and we will practice
some more. Mine, for example:
As a reminder, from this point forward, I can only use the bh and bd as needed; I
cannot (or should not, traditionally) use the words BowersHeading and BowersDate.
This is applicable to all object oriented programming, regardless of the language.
b. Inside of main(…), open with a call to your personal heading class, passing the String
“Assignment Eight – Working With Interfaces”; no more, and no less than shown in the
quotes. There is a space on each side of the hyphen, and watch capitalization and the
lack of any other punctuation. Yep, the word Eight instead of number 8.
Handling Employees
e. You need to display\call for display, a minimum of five (5) employees; one from each
of the categories. Instantiate them as follows, and in this order. Order in this part is
important because I want to show you that order can be changeable.
Wm Bowers Page 6 of 7
Info 1521: Java Programming 1 Assignment 8
f. When you actually display them, do so in this order because someone came along with
more stripes on their arm than you and wanted to change the final output without
changing the original input. Order of display: e5, e1, e2, e3 and e4; with you being
the last line showing. Refer to Exhibit C, which is what I did to put President Lincoln
on top; albeit, he was last on the instantiation\declaration list.
Handling Products
g. The author instantiated a single product, Murach’s Beginning Java. We will instantiate
a second product, of your choosing, as long as it follows the existing format of a 4-
letter or 4-digit product code, a title and a price each.
Handling Services
h. Reviewing Exhibit C, Make your columnar headings as shown in the Exhibit. Add four
services with four descriptions a column for Per Hour charges and a column for Flat
Rate charges.
1) Per Hour charges must decimal-align.
2) Flat rate charges must decimal align and, as shown, accommodate a thousand’s
separator for any value above 999.99. To make sure you are doing so, send such
a value to your Service class via the four argument Service class constructor.
1) On its own line, exactly as shown in Exhibit C, state the following: “End of
Report”. Capitalize the first letters as shown, and do not use a period or any
other punctuation.
2) On their own (one, single, solo) line, use your personal Date class instance to call
your printfDate( ) and printfTime( ) methods.
ji. Do not forget to use the correct opening programmer’s comment citations which, as
you know, must be complete, current and correct.
k. If I forgot anything, you fill in the necessaries. If any instruction is confusing, default
to the finished output examples provided in Exhibit C.
Wm Bowers Page 7 of 7