Lab 14: Final Lab

Table of Contents


Objectives

  • Review file IO syntax.
  • Start getting ready for the final exam.

Academic Honesty

Read the Scholastic Honesty Policy and Quest and Lab Integrity policies of the syllabus. Here are some clarifications for this particular lab:

  • This is a solo lab that you must complete individually.
  • You may discuss the code with other students for this lab.
  • You must type all the code yourself and not copy from another student.

Lab Specifications

  1. Make sure you have completed the exercises from lesson 14.
  2. Complete the Extra: File I/O exercises in CodeLab. These are review exercises and you have all the information needed to complete them. If you have questions, please contact the instructor.
  3. Complete the following problems and make sure your final project has in-game instructions, which could be like the instructions part of this lab.

    You may make modifications to the above lab as long as the lab grading criteria below is met.

A. Starting a scenario

Complete the following steps to create a new scenario:

  1. Review lessons:
  2. Open Greenfoot and start a new Java scenario named: lab14.
  3. Add your name to the README.TXT accessed by following the Scenario menu to the Scenario Information window.
  4. Change the name of the world to LabWorld with a background image of your choosing. Make the world size 600 pixels wide by 400 pixels high and a cell size of one. Compile your code to verify it works.
  5. When complete, your scenario screen should show a world background image.

B. Create Instructions

  1. Review 13.2.6: Reading a Text File.
  2. Save the following text file to the main scenario folder: gameuser.txt.
  3. Create an Actor subclass named Instructions with no image.
  4. In the constructor of the Instructions class, create a Scanner object named "in" that reads the file "gameuser.txt" from a JAR file.
  5. After opening the stream, use a while loop like the following to read each line of text from the file into a String variable named "text":
    String text = "";
    while (in.hasNext()){
        text += in.nextLine() + "\n";
    }
    

    The "\n" adds an end-of-line (newline) character for each line of text read from the file.

  6. After the loop is completed, close the file.
  7. Use the text to construct a new GreenfootImage object.

    Hint: the easy way to create the image is to use the GreenfootImage constructor made for text that we discussed in lesson 10.3.2 under the subheading Creating a Label. Feel free to choose appropriate foreground and background colors, set borders and add other features to your instructions.

  8. Set the image for the Instructions objects to the image created in the prior step.
  9. In the act() method of the Instructions class, add a statement to remove this object from the world.

    You may add fading effects if desired, but simply disappearing is acceptable.

  10. In the World subclass for your scenario, add an Instructions object to the scenario.
  11. Test your scenario to verify the instructions appear when the scenario loads and then disappears when pressing the Run button.

Grading Criteria

The instructor will evaluate your lab using the following criteria. Thus you should check your lab against these criteria to maximize your XP.

Lesson Exercises (from Class)

  • 2: All lesson exercises attempted and turned in
  • 1: Some lesson exercises not completed and turned in or other problems found
  • 0: No lesson exercises turned in or wrong folder name

CodeLab Exercises

Number completed correctly / number exercises * 8 and rounded up to the nearest integer.

Lab 14 Exercises

Everyone starts with 4 points and points are subtracted for the following problems.

  • -3: No Instructions object.
  • -2: No stream opened to read from a JAR file.
  • -2: Instructions not visible in the scenario.
  • -1: Instructions/title not visible before scenario starts.
  • -1: Missing the "gameuser.txt" file in the scenario.
  • -1: Not reading from the "gameuser.txt" file in the scenario.
  • -1: Not closing the file stream.

Maximum XP: 14

Deliverables

CodeLab is submitted automatically, but other lab work must be submitted as described below.

  1. On your computer, create a folder for the lesson exercises named "lesson" (no extra characters) and place all the exercise files from Lesson 14 into this folder. The exercises include the platformer scenario with these files included:
    1. GameManager.java
    2. Map1.java
    3. Map2.java
    4. Label.java
    5. Button.java
  2. Create a second folder named "tutorial" (no extra characters) and place the entire scenario from this lab into the folder. There should be only one scenario. Do not include any files from previous labs.
  3. Submit one or more zip files containing both scenarios to the Lab 14 slot of Canvas.

Please do not add any extra characters to the above folder names. Also, do not put any spaces or special characters like #, : or $ in zip file or folder names. Your crafted code must work as submitted. Remember to test and double check your files before and after submitting them. If you make a mistake, you can resubmit up to the deadline but must resubmit all your lab files.

Last Updated: December 05 2018 @13:09:37