Lab 3

Eclipse Lab: What to do

  1. Install and start Eclipse.
  2. Create a project:
    1. File/New/Java Project
    2. Give it the name "Craps".
    3. Click Finish.
    4. You should now be in the "Java Perspective". There should be several window panes, and in the upper right corner should be a small box with a J and some other symbols in it. If you aren't in the "Java Perspective", you can get there by selecting Window/Perspective/Open Perspective/Java Browsing.
  3. Import an existing source file:
    1. Double click Craps in the Package Explorer pane (or click the triangle to expand it's content)
    2. Select "src"
    3. Download Craps.java from the Canvas Files folder.
    4. Select File/Import/General/File System. Click Next. Browse to your Downloads folder where you saved Craps.java then click OK.
    5. select Craps.java in the right hand pane.
    6. If the "Into folder" doesn't already show "Craps\src" then click on the browse button for that field and select "Craps\src" then click OK. (It should already be filled in if you followed steps 1 and 2 above.
    7. Click Finish.
  4. Open Craps.java in an editor. Double click src/default package (if necessary to open them up in the Package Explorer (left pane), then double click Craps.java. An editor pane should open with Craps.java.
  5. Fix two problems in Craps.java indicated by the red circle with an "x" indicating an error and a yellow circle (if you look close I believe it is a yellow light bulb) indicating that Eclipse has a suggestion as to how to solve the problem.
    1. Scoll down to the first light bulb (yellow blob) in the left margin of the editor pane. Notice the little red squares on the right margin of the editor pane. They show where the errors are in the complete file. Try clicking on one.
    2. Click ONCE on the first light bulb. Give it a few seconds. It will show several suggestions.
    3. Select the one suggesting you need to import java.util.Random, then double click it. This will make the insertion for you.
    4. Scroll down to the next light bulb. (Look for the one remaining red square in the right margin.) Click on the light bulb. Notice it shows you the methods that could be called. Select the correct one and then double click it.
    5. Save the file and you should no longer see any red circles with white "x"s in them.
  6. Run the program.
    1. Click the green triangle or Select Run/Run or Run/Run As/Java Application.
    2. A console will appear. It may take a few seconds to get started. The console should eventually show a prompt for the seed. You may need to click in the console pane before you can enter any input.
    3. Play a few rounds of the game then end by betting 0.
  7. Add a new method using refactoring.
    1. In the method rollDiceUntilWinOrLose, select the lines after the comment "// roll until point or 7" up through the end of the if-else statement. You can get there quickly by clicking on the method name in the rightmost pane labelled "Outline".
    2. Click menu Refactor and select Extract Method.
    3. Give the method a name. I suggest, rollUntilPointOr7.
    4. Click the "package" Access Modifier button then click OK.
    5. Notice how it figured out what needed to be passed in and that the result needed to be assigned to variable winLose.
    6. Click File/Save. (If Save is not available then the file was already saved automatically.)
  8. See some name completion in action.
    1. Create another file just to play around with typing. File/New/Class. Call it "Fiddle" or whatever you want. Check the box saying you want it to create a main method. Click Finish.
    2. In the body of main type "String str;"
    3. On the next line type "str." then just wait. A window will pop-up showing all of the possible operations you can perform on a string. Type a little more so you have "str.subs". Notice how it just shows those methods or operations that could fit with what you have typed.

What to turn in

After completing the above exercise, go back to editing Craps.java in Eclipse. Scroll to the top and open up the opening block comment by clicking on the + on line 2 if it isn't already opened up. At the end of the comment add a line with your name like this

Errors corrected by Firstname Lastname

then take a screen shot of either your full desktop or the Eclipse window.

Submit that screen shot (.tiff, .png, or .jpg) under lab3 in Canvas.