CSCI1260 Introduction to Computer Science II – Homework 1
Setting the Commenting and Formatting Standards in Eclipse
  1. Download the three xml files provided with this lab and place them on your desktop.
  2. CSCI1260_Code_Formatting.xml
  3. This file contains standard formatting data for curly braces and other things.
  4. CSCI1260_Commenting_Template.xml
  5. This file contains standard formatting dataforyour code’s comments.
  6. Templates.xml
  7. This file contains a template to generate a toString method in a new class.
  8. Launch Eclipse and select your CSCI1260 workspace.
  9. SelectWindows > Preferences…

  1. Navigate to General/Editors/Text Editors. Check Show Line Numbers if not already checked.

  1. In the Preferences dialog, navigate the Preferencestree to ‘CodeTemplates’ as shown on the next page.
  1. Next, selectComments, and then click the Import… button.
  1. Navigate to the ‘CSCI1260_Commenting_Templates.xml’ file, select it, and select Open.
  1. In the Preferences dialog, expand Comments, select Files, and click the Edit button. This will allow you to change the name of the user, the user’s email address and the section number to your information:

  1. Repeat the process with Types and change my name to your name.

  1. Back in the Preferences dialog, navigate the tree to ‘Formatter,’ and then select Import…

  1. Navigate to the ‘CSCI1260_Code_Formatting.xml’ file, select it, and select Open.

  1. Take note of the name change of the Active Profile and then select ‘Ok.’
  1. You can now generate comments automatically and the curly braces will be automatically aligned for you.
  2. Now, navigate to Editor under Java. Expand Editor and go to Templates under Editor. That should present a dialog that looks something like this.
  1. Now click Import on the right-hand side and browse to where you saved Templates.xml. Select it. This will add an editor template that will allow you to generate the skeleton of a fully commented toString method in a class you are creating by typingtostr followed by pressing ctrl and space together. This will show

Double-click on the selectedline in the dialog and the toString method skeleton such as below will appear.

  1. In the preferences dialog, navigate to Run/Debug/Console as shown below. Modify the colors to suit your preferences, making sure to choose colors that are easy to see when your program is running. “Standard Out” is for text displayed by your program by System.out.print or System.out.println commands. “Standard In” is for text you type at the keyboard that is being input to your program via the program’s use of a Scanner object.
  1. Click the OK button to exit the Preferences dialog.
  1. To see the results of our changes in action, create a Java project called HelloWorld2.
  2. Add a class called HelloWorldto the project. Here is the New Java Class dialog, take note of the checked boxes. Then click Finish.
  1. Eclipse should generate the following commented code (some of the comment blocks may be collapsed and you will have to click on the + in the circle next to the line number to expand them to look as below):
  1. Examine the comments, and make changes to the filler text (such as “Enter type purpose here” or “Enter method description here”) in all appropriate locations. Add additional information to comments as needed throughout all projects.
  1. Retrieve and work your way through Some Tips for Using Eclipse.pptx on the website.
  2. Add a second class named Person with 3 attributes: firstName, lastName, and age of appropriate types. Use the Source menu in Eclipse to generate constructor methods, getters and setters, and the toString method. Using the Source menu in this way creates the skeleton of the methods and the headercomments for the methods. This saves you a lot of work instead of typing everything from scratch. Of course, there may be methods not on the Source menu that you must type from scratch, but if you put the cursor on the method and click Source/Generate Element Comment, Eclipse will write the skeleton of the comments for you.

0

  1. Complete the program by modifying the driver to create at least 2 Person objects, one using the defaultconstructor for Person and the other using the parameterizedconstructor. Display the two Person objects on the screen.
  2. All files, classes, methods, and attributes MUST be properly commented before submission.
  3. Submit the results of this exercise. Be sure to follow the instructions and name the zipped folder as instructed in the document named SomeCourseFacts.docx. Make sure all of the .java files submitted are documented consistently with the Documentation Standards document on the course website.

Part II

  1. Create a new Java project named HW1bYourName
  2. Add a driver class to the project. Name the driver class HW1bDriver
  3. Add a second class to the project. Name this class Person.
  4. Add 3 (private) attributes to the class: firstName, lastName, and age of appropriate types.
  5. Add a defaultconstructor method that initializes each of the attributes to some defaultvalue (such as blanks or zero)
  6. Add a parameterizedconstructor method that initializes each of the attributes to values passed in as parameters
  7. Add getters and setters for each attribute
  8. Add a method called formattedPerson that returns a string with a value consisting of the first name, the last name, and the age formatted as shown by the example:
    “I am Willy Makit and I am 24 years old.”
  9. Comment each of the methods as well as the class and the file appropriately.
  10. In the main method in the driver class,
  11. Promptthe user to input his/her first and last name and age
  12. Create a Person object using the information the user input
  13. Output the formattedPerson information for this Person object
  14. Document the entirefile and its components accordingly
  15. Show your work to the TA and get him/her to check off your name before you leave