PA3
IS 2063 - JAVA: PA3 ASSIGNMENT
TOTAL POINTS: 100 DUE: CHECK BLACKBOARD BY 11:59 PM READ CAREFULLY "ALL" THE INSTRUCTIONS!!! Do not submit code that doesn’t compile, run, or generate correct output. No assistance given via email. If needed, seek help during open tutoring or instructor office hours.
Contents (TOC) Alt Left Arrow to return to link.
UTSA HONOR CODE ........................................................................................................................... 1
OBJECTIVE .......................................................................................................................................... 1
PREP WORK: ....................................................................................................................................... 1
GRADING: ............................................................................................................................................ 1
PROGRAM INSTRUCTIONS: ............................................................................................................... 2
UML Diagrams ................................................................................................................................... 2
FINAL Output Specifications: ................................................................................................................ 9
SUBMISSIONS REQUIREMENT: ....................................................................................................... 10
SAMPLE OUTPUT .............................................................................................................................. 11 ***OUTPUT WITH NO ADDRESSES*** Not part of output. ................ 11
***OUTPUT INCORRECT/CORRECT INPUT*** Not part of output. .......... 11
UTSA HONOR CODE: As a UTSA student, you are bound by the honor code, so DO NOT cheat on any of your coursework. By submitting this assignment, you affirm that there has been no cheating or collusion in its completion; that the material you’ve used is from your textbook, professor, or Java tutors. Cheating can result in anyone, or combination, or all of the following: reduced or failing grade for the assignment, a signed statement of the infraction, reduced or failing grade for the course, reporting of student to the Department Chair, Dean’s Office, and/or elevation to Student Conduct and Community Standards. It is not only cheating, but an infringement of copyright, if this assignment or any student’s completed code is posted to any website for broad consumption or distribution; and, you are obligated by the Student Code of Conduct to report these infractions. The idea behind this assignment is not yours. The logic given to you for the assignment by the faculty is not yours. The code that is written embodies the idea. OBJECTIVE (this is not the program purpose): Code a program that uses the concepts covered in chapters 1-11 and lecture. PREP WORK: Material from chapters 1-11 (including instructor PowerPoint slides, demo programs, and completed exercises). GRADING: You’ll be graded on how well you follow the program instructions and the accuracy of your output as reflected in the prompts, the output specifications, and the sample output. This includes spacing and line advancing. Each line of output can be associated with multiple points in the code! The UML diagrams with prompts and coding instructions, and output are what
TOC
© 2023 Linda Shepherd 2
the user wants. You are not at liberty to change anything, but code to these requirements. You’ll also be graded on the code given to you by your professor for this PA. TEAM MEMBER RATING: Team members are to rate one another only if a member’s performance is 3 or below out of 5, which can affect a team member’s grade. Refer to Blackboard for details.
☐Yes ☐No Did we code the fields reflected in the UML using the private modifier? ☐Yes ☐No Did we code the methods according to the UML instructions? ☐Yes ☐No Did we declare any method-level (local) variables at the beginning of the method and
initialize them to their default values or given value?
1. 0 for int 2. 0.0 for double 3. ' ' for char (has space between the single quotes) 4. "" for String (no space between the double quotes; represents an empty String
literal) 5. null for class reference variables declared without an object
☐Yes ☐No Are the open braces on their own line? ☐Yes ☐No Did we use printf() and format specifiers by default unless instructed to use print() or
println()? ☐Yes ☐No Did we use the Java code given to us in the instructions? ☐Yes ☐No Did we use good form?
1. The code is properly spaced, not bunched up. 2. Readable within the line of sight from top to bottom rather than extensively left to
right. Don’t go beyond the grey line in the right margin of DrJava. 3. Use Ctrl A to highlight all your code, then press the tab key to align it. If it doesn’t
align, you have a bracing error. ☐Yes ☐No Did we follow commenting guidelines? ☐Yes ☐No Does my program compile and run with the correct results, i.e., did we follow
formatting guidelines? ☐Yes ☐No Is there equal division of labor among team members? A team member tasked with
an additional method is ok, since there can be an odd number of methods. PROGRAM INSTRUCTIONS: There will be 3 classes in a project folder that generates the address book belonging to a person (address book owner): Application Class, AddressBook, Addressee. Don’t forget to exit at the end of main(). You were shown during class or perhaps in a video how to create a project folder, if not, the PDF posted with this PA in Blackboard shows you how. The application class gets everything started. The AddressBook class creates an array of type Addressee that stores address book contacts. The Addressee class captures the data for a contact. The prompts and the final output in the sample output show you the logical progression of your code, and along with the instructions in the UML give you an idea as to what code to write and where to place your code.
1. Work and submit this PA in a group.
2. UML Diagrams for the classes: Data members are variables. The variables are derived from the prompts and/or the final output. DO NOT code the methods in any way other than what is
PA CHECKLIST
TOC
© 2023 Linda Shepherd 3
instructed. The – sign means private, the + means public, and underlines mean static in the UML.
Class Name Addressee This class is being given to you as it will be used to type the array in the AddressBook class. You are not allowed to post this program anywhere per the UTSA Honor Code. 1. You will insert comments for
a. the program purpose, b. import statement purpose, c. each field’s purpose, d. each method’s purpose (comment boxes above the method
headers). Expect to be tested on the final exam regarding code behavior in the methods of this class for chapters 9 and 11.
2. You will insert code for missing Java statements. 3. Read the instructions in the first comment box on how to
locate the lines requiring your attention. Class Name TeamMembersLastNamesAlphaOrderYourSectionNoPA3
imports N/A
Class Data
Members
N/A
Method Data
Members
+main() myContacts: AddressBook
Methods +main(args: String[]): static void
1. Code local variable.
2. Call start() from AddressBook.
3. Exit statement.
Class Name AddressBook
imports Scanner, File, PrintWriter, IOException
Class Data
Members
//Variables used in more than one method should be a //field or class variable. -input: Scanner -addressBook: Addressee[] (partial array creation) -ownerAddrBk: String -fileName: String -correct: char
TOC
© 2023 Linda Shepherd 4
Method Data
Members
+start() another: char count: int +createAddressBook() noAddressees: int ordinalSuffix: String +setOwner() ownerAddrBkCopy: String +displayAddressBook() family: String (properly format to “FAMILY”) friends: String (properly format to “FRIENDS”) work: String (properlyformat to “WORK”) hasFamily, hasFriends, hasWork: boolean +writeAddressBkContacts() contact: String outputFile: PrintWriter (partial object creation) fileError: boolean +checkInputFileContacts() file: File inputFile: Scanner fileRecord: String fileNotFound: boolean
Methods Remember: Every prompt requires a read statement from the input buffer into the right variable.
+AddressBook()
+start(): void
1. Code local variables.
2. In a do-while controlled by another that is tested using isLetter() conditional OR toLowerCase() for both ‘y’ conditional AND ‘n’ a. if preincrement count is equal to 1
Prompt: Begin entering addresses? ‘Y’ or ‘N’: otherwise
if another is not a letter Print: Not a letter! Enter a ‘Y’ or ‘N’ to begin:
otherwise if another lowercased is not equal to ‘y’ conditional OR another lowercased is not equal to ‘n’
Print: x is invalid! Enter a ‘Y’ or ‘N’: where x is another 3. if another is equal ‘Y’
Call createAddressBook()
TOC
© 2023 Linda Shepherd 5
displayAddressBook() writeAddressBkContacts() checkInputFileContacts()
otherwise Print: Exiting program.
+createAddressBook(): void
1. Chapter 7, lesson 4 will help with Arrays of Objects.
2. Except for setOwner(), the other set methods are from the Addressee class.
3. Code local variables.
4. Call setOwner().
5. Prompt: How many contacts will be recorded in your address book?
6. Use while not input.hasNextInt() a. Clear buffer. b. Prompt: Invalid integer! Re-enter the number of contacts:
7. Clear buffer.
8. Assign to addressBook array a new Addressee using noAddressees.
9. In for loop using i as the loop-control variable and testing to the length of addressBook
a. switch on the remainder of i + 1 over 10 wherein cases 1-3 assigns the proper “st”, “nd”, “rd” to ordinalSuffix with the default assigning “th” to ordinalSuffix.
b. Assign ordinalSuffix to the String.valueOf(i + 1) plus ordinalSuffix. c. Create an Addressee object at i of the addressBook array. d. At i of the addressBook array call these methods from the Addressee class,
i. setAddressee() by sending it ordinalSuffix. ii. setStreet(). iii. setCityStateZip(). iv. setPhone(). v. setRelationship().
+setOwner()
1. Code local variables.
2. In do-while controlled by correct not equal to ‘Y’
a. Prompt: Enter your name: b. Assign to ownerAddrBkCopy a new String by sending to it the ownerAddrBk.
The new String then calls replace to replace every blank space (“ “) with nothing (“”).
TOC
© 2023 Linda Shepherd 6
c. while(!Addressee.isAlpha(ownerAddrBkCopy)) i. Print: Invalid! Name not alphabetic. Please re-enter: ii. Assign to ownerAddrBkCopy a new String by sending to it the
ownerAddrBk. The new String then calls replace to replace every blank space (“ “) with nothing (“”).
d. Prompt: You enter Xxxxxxxx Xxxxxxxxxx. Is this correct? ‘Y’ or ‘N’: where the Xs is the ownerAddrBk. The static capitalize() in Addressee is called as the argument for the format specifier. The capitalize() method is given ownerAddrBk.
3. Assign to ownerAddrBk the proper capitalization of its value. Use the static capitalize() from Addressee.
+diplayAddressBook()
3. Code local variables.
4. In for controlled by j and tested to the length of the addressBook array,
a. switch on addressBook at j calling getRelationship() b. use the cases from the PA1 plan video where you assign a formatted String
of the addressee, street, city, state, zip and phone to the family, friends, and work variables in that order. i. Except, the arguments will be calls to the get methods for each output line
from the addressBook array at j. ii. These get methods are in the Addressee class. Example:
addressBook[j].getAddressee(), addressBook[j].getStreet(), etc. iii. Assign true to the local boolean variables belonging to its case.
4. Print: ADDRESS BOOK FOR XXXXXXXX XXXXXXXXXX where the Xs are the ownerAddrBk.
5. There will be 3 separate if statements testing each boolean. Example:
if(hasFamily) { System.out.printf("%s", family);
}//END if there are family contacts print them
+writeAddressBkContacts(): void
1. Code local variables.
2. In a try block
a. This prompt is coded with no line advances other than the one at the beginning. Enter Contacts.txt as the name of the file. Enter the file name for the address book (WARNING: This will erase a pre-existing file!):
b. Open the file in PrintWriter. c. Use a for-loop to assign the data from the array into the contact variable
using these format specifiers: "%s, %s, %s, %s, %s%n" in the order of
TOC
© 2023 Linda Shepherd 7
the get methods for the addressee, street, cityStateZip, phone, and relationship. i. The String.format() will be used to format the addressee before assigning
to the contact variable in this method. ii. The last argument in the String.format() is:
addressBook[i].getRelationship() == 1 ? "Family" : addressBook[i].getRelationship() == 2 ? "Friend" : "Work"
3. In a catch block that catches an IOException into e
a. Use the err object from System to call printf() by sending it this message: File cannot be created.
b. Re-initialize fileError to true.
4. Using a single-selection if, test for there is no fileError.
a. Close the outputFile. b. Print the message:
Data written to the Xxxxxxxxxxx file.
where the x’s is the name of the file.
+checkInputFileContacts(): void
1. Code local variables.
2. In a try block
a. Enter Contacts.txt as the name of the file for this prompt. Enter the name for the address book file:
b. Finish creating the File object with fileName. c. Finish creating the Scanner object with file. d. Use a while-loop by testing inputFile.hasNext() to
i. read the next line from the inputFile into fileRecord. ii. print what was just read. Use a format specifier with a line advance at the
beginning.
e. Print a blank line using println().
3. In a catch block that catches IOException into e
a. Use the err object from System to call printf() by sending it this message: File not found!
4. In a catch block that catches NullPointerException into e
a. Use the err object from System to call printf() by sending it this message:
TOC
© 2023 Linda Shepherd 8
Record couldn’t be accessed or read.
5. Using a single-selection if, test there is no fileNotFound.
a. Close the inputFile.
6. Use printf() with format specifiers where needed. 7. The prompts, the final output specs, and the sample output show you in what order to place your
code. To return from these links press Alt then left arrow. 8. You are to generate output from your program according the instructions in the sample output
section. 9. Make sure your code is properly indented.
10. Commenting Your Program: Refer to the Java Style Guide posted in Blackboard for more commenting and formatting details. Java doc comment box examples may have been given to you in demo programs coded during class or through a video posted by your professor. a. In your program, YOU MUST insert a program purpose in the first comment box. The
content of that first comment box was shown to you in the Anatomy of a Java Program lecture for chapter 1.
b. Use Javadoc comment boxes beginning with /** and ending with */ for your comment boxes. c. Insert a Javadoc comment box above all your methods explaining what is going on with the
code in the method. d. Line comment the import statements and the variables declared at the class level and/or in any
method [including main()]. e. Line comment close braces. The close brace for an else in an if-else is where you line
comment for the structure. Line comment after the while in a do-while. f. Through line and method comments, group members will claim authorship and the work must
be evenly distributed. Example:
int age = 0; //By Bugs Bunny: STORES AN AGE
/** * By Daffy Duck * main() captures a first and last name, an age, and a zip code. * It multiplies the age and zip code to get a product. * Output will be made to the console screen and to a * GUI window. */
11. Formatting Rules: Always test to validate your program is functioning properly with the correct output and spacing (line advances and spacing after punctuation). The %n can function differently when using separate printf statements versus one printf.
TOC
© 2023 Linda Shepherd 9
FINAL OUTPUT SPECIFICATIONS: The output will print the header, address category, addressee's name, street, city, state, zip code, and phone number. The specifications are repeated because there can be multiple addresses. The Xs represent the name of the owner of the address book, the addressee, the street, city and capitalized abbreviation for the state. The 9s represent the zip code and phone number. These output specs are different than the previous PAs.
ADDRESS BOOK FOR XXXXXXXXXXXX
FAMILY Addressee: Xxxxxxxxxxxx Street: Xxxxxxxxxxxx City, State Zip: Xxxxxxxxxx, XX xxxxx Phone: xxx-xxx-xxxx Addressee: Xxxxxxxxxxxx Street: Xxxxxxxxxxxx City, State Zip: Xxxxxxxxxx, XX xxxxx Phone: xxx-xxx-xxxx FRIENDS Addressee: Xxxxxxxxxxxx Street: Xxxxxxxxxxxx City, State Zip: Xxxxxxxxxx, XX xxxxx Phone: xxx-xxx-xxxx Addressee: Xxxxxxxxxxxx Street: Xxxxxxxxxxxx City, State Zip: Xxxxxxxxxx, XX xxxxx Phone: xxx-xxx-xxxx WORK Addressee: Xxxxxxxxxxxx Street: Xxxxxxxxxxxx City, State Zip: Xxxxxxxxxx, XX xxxxx Phone: xxx-xxx-xxxx Addressee: Xxxxxxxxxxxx Street: Xxxxxxxxxxxx City, State Zip: Xxxxxxxxxx, XX xxxxx Phone: xxx-xxx-xxxx ***END OUTPUT SPECIFICATIONS***
Header (Title): Triple-line advance header title using 2 “%n” with 1 %n at the end of the literal. Use 1 “%n” at the beginning of the 2nd header line and 1 at the end. All capital Xs means the owner’s name is in all CAPS.
TOC
© 2023 Linda Shepherd 10
SUBMISSIONS REQUIREMENT:
1. The group will submit only one project folder with all the files. Create a project folder according to the instructions posted with the PA or as directed by your professor. This means only one of the group members should submit the PA. ALL submissions will be ignored if both group members post submissions. The folder and the main() file will reflect the last names of both group members in alphabetical order. E.g., BunnyDuck001PA3. Through line and method comments, group members will claim authorship and the work must be evenly distributed. Example:
int age = 0; //By Bugs Bunny: STORES AN AGE
/** * By Daffy Duck * main() captures a first and last name, an age, and a zip code. * It multiplies the age and zip code to get a product. * Output will be made to the console screen and to a * GUI window. */
2. WARNING: One group member CANNOT and MUST NOT carry the load for these assignments. All group members must be actively and equally engaged in developing and writing code. Deadlines set by the group for ultimate submission must be met. All group members are to agree to the submission, unless the group agrees to convey that authority to the submitter. No correspondence by a group member to another group member is to be ignored; otherwise, you will be rated accordingly by your teammate. Therefore, not having the time, ignoring Discussion Board messages from your group, not knowing what to do, not checking your team Discussion Board, waiting for the last minute to contact your group, etc., will ensure a poor rating or you not getting credit for the project. Your group member could be a possible contact for future employment or even your employer. What you wouldn’t do in a workgroup on the job is what you don’t do in a workgroup at school. You must be professional in your dealings with your group members.
3. Upload Your Submission in This Order a. Word Document: Copy your .java code into a Word document and save it with the same
name as your program. Upload the document to Blackboard under this PA. b. Zipping Folders: Your Java files “must be” in a folder. This time it’ll be a project folder.
i. Create a project folder named for the program (excluding the file extension). ii. Put your .java, .class, .java~ files in the proper subfolders. iii. To zip the project folder, point to it then right click and iv. Filzip if you have it OR v. Click Send To then click Compressed (zipped) Folder vi. Upload your zipped folder to Blackboard under this PA.
5. Uploading to Blackboard: Make sure your browser is properly configured for Blackboard (see syllabus).
a. Your submissions are to be uploaded to Blackboard through Assignments only.
TOC
© 2023 Linda Shepherd 11
b. Upload your files no later than the due date by 11:55 pm; otherwise, you don’t have time to recover from any problems and your assignment may not be accepted by Blackboard.
c. Check to make sure your submission is uploaded. Please do not ask your instructor to check whether your assignment has been uploaded. You can do this yourself. Or upload during a tutoring session when someone can help you.
d. If you submit your assignment before the due date, want to make changes or upload additional files, you can re-upload your files.
6. NO ASSIGNMENTS WILL BE ACCEPTED LATE OR VIA E-MAIL. DO NOT UPLOAD PROGRAMS THAT DON’T COMPILE OR DON’T PRODUCE CORRECT OUTPUT.
SAMPLE OUTPUT: Do not expect the output to look exactly like the output for the previous PAs. It is always good to test your code using sample data to see if your program meets the output specifications. Run your program using the data in the following sample output. Copy and paste the output into a traditional comment box /* */ at the end of your PA3.java file. The comment box needs to be outside of the close brace for the application class. Change your font in DrJava to Monospaced or Courier New so your output is not out of alignment. Worth 5 points! Your output will not print in bold.
Begin entering addresses? 'Y' or 'N': 1 Not a letter! Enter a 'Y' or 'N' to begin: h h is invalid! Enter a 'Y' or 'N': n Exiting program.
Begin entering addresses? 'Y' or 'N': y Enter your name: James K0rk Number 0 as the letter ‘o’. Invalid! Name not alphabetic. Please re-enter: james kirk You entered James Kirk. Is this correct? 'Y' or 'N': y How many contacts will be recorded in your address book? # Invalid integer! Re-enter the number of contacts: 3 Enter the name of the 1st addressee: g#orge kirk Invalid! Name not alphabetic. Please re-enter: gorge kirk You entered Gorge Kirk. Is this correct? 'Y' or 'N': n Enter the name of the 1st addressee: george kirk You entered George Kirk. Is this correct? 'Y' or 'N': y Enter the street for George Kirk: 7!8 Enterprise Invalid! Re-enter the street: 728 Enerprise
***OUTPUT WITH NO ADDRESSES*** Not part of output.
***OUTPUT INCORRECT/CORRECT INPUT*** Not part of output.
TOC
© 2023 Linda Shepherd 12
You entered 728 Enerprise. Is this correct? 'Y' or 'N': n Invalid! Re-enter the street: 718 Enterprise Cir You entered 718 Enterprise Cir. Is this correct? 'Y' or 'N': y Enter the city, state and zip code for George Kirk in the correct format: r*verside, ia All on one line in DrJava. Invalid! Re-enter the city, state and zip code: riverside, ca You entered Riverside, Ca. Is this correct? 'Y' or 'N': n Invalid! Re-enter the city, state and zip code: riverside, ia 52327 You entered Riverside, IA 52327. Is this correct? 'Y' or 'N': y Enter the 10 digit phone number for George Kirk without dashes or parentheses: 3!97890123 All on one line in DrJava (text wrapped in Word). Invalid! Re-enter the 10 digit phone number without dashes or parentheses: 7197890123 All on one line in DrJava. You entered 719-789-0123. Is this correct? 'Y' or 'N': n Invalid! Re-enter the 10 digit phone number without dashes or parentheses: 3197890123 All on one line in DrJava. You entered 319-789-0123. Is this correct? 'Y' or 'N': y Relationship of the addressee: 1. Family 2. Friends 3. Work Choose from the above: 1 You entered 1 for Family. Is this correct? 'Y' or 'N': y Enter the name of the 2nd addressee: spock You entered Spock. Is this correct? 'Y' or 'N': y Enter the street for Spock: 15 triple moon You entered 15 Triple Moon. Is this correct? 'Y' or 'N': y Enter the city, state and zip code for Spock in the correct format: surak, vulcan All on one line in DrJava. You entered Surak, Vulcan. Is this correct? 'Y' or 'N': y Enter the 10 digit phone number for Spock without dashes or parentheses: 4151234567 All on one line in DrJava. You entered 415-123-4567. Is this correct? 'Y' or 'N': y
TOC
© 2023 Linda Shepherd 13
Relationship of the addressee: 1. Family 2. Friends 3. Work Choose from the above: 4 You entered 4 which is incorrect. Try again. Relationship of the addressee: 1. Family 2. Friends 3. Work Choose from the above: 2 You entered 2 for Friend. Is this correct? 'Y' or 'N': y Enter the name of the 3rd addressee: Lt. Commander Montgomery Scott You entered Lt. Commander Montgomery Scott. Is this correct? 'Y' or 'N': y All on one line in DrJava. Enter the street for Lt. Commander Montgomery Scott: 5 Star Fleet #62 You entered 5 Star Fleet #62. Is this correct? 'Y' or 'N': y Enter the city, state and zip code for Lt. Commander Montgomery Scott in the correct format: fort baker, ca 98210 All on one line in DrJava. You entered Fort Baker, CA 98210. Is this correct? 'Y' or 'N': y Enter the 10 digit phone number for Lt. Commander Montgomery Scott without dashes or parentheses: 4152345678 All on one line in DrJava. You entered 415-234-5678. Is this correct? 'Y' or 'N': y Relationship of the addressee: 1. Family 2. Friends 3. Work Choose from the above: 3 You entered 3 for Work. Is this correct? 'Y' or 'N': y ADDRESS BOOK FOR JAMES KIRK FAMILY Addressee: George Kirk Street: 718 Enterprise Cir City, State Zip: Riverside, IA 52327
TOC
© 2023 Linda Shepherd 14
Phone: 319-789-0123 FRIENDS Addressee: Spock Street: 15 Triple Moon City, State Zip: Surak, Vulcan Phone: 415-123-4567 WORK Addressee: Lt. Commander Montgomery Scott Street: 5 Star Fleet #62 City, State Zip: Fort Baker, CA 98210 Phone: 415-234-5678 Enter the file name for the address book (WARNING: This will erase a pre- existing file!): Contacts All on one line in DrJava. Data written to the Contacts file. Enter the name for the address book file: contacts George Kirk, 718 Enterprise Cir, Riverside, IA 52327, 319-789-0123, Family Spock, 15 Triple Moon, Surak, Vulcan, 415-123-4567, Friend Lt. Commander Montgomery Scott, 5 Star Fleet #62, Fort Baker, CA 98210, 415-234-5678, Work All on one line in Contacts.txt.
- TOTAL POINTS: 100
- DUE: CHECK BLACKBOARD BY 11:59 PM
- PA CHECKLIST
- SUBMISSIONS REQUIREMENT:
- ***OUTPUT WITH NO ADDRESSES*** ( Not part of output.
- ***OUTPUT INCORRECT/CORRECT INPUT*** ( Not part of output.