CS152, Fall 2020

Computer Programming Fundamentals
Home
Schedule
Syllabus
Style Guidelines

Assignment 5: Programming Assignment
Due: Monday September 28 by 9:30am

Description

You can choose to work in a 2 person team or on your own for this assignment. If you want to work in a team, please let me know (via email) by the end of the day Friday 9/25. The email should contain the full names and email addresses of the team members.

Create a program with a class that describes a vehicle. The vehicle class should have (at least) the following instance variables: xPosition, yPosition. The vehicle class should have (at least) the following methods: constructor, displayVehicle(), moveVehicle (int xAmount, int yAmount). The class should draw some sort of vehicle (a car, boat, plane, etc.) on the screen. Your program should allow you to move the vehicle around the screen with the arrow keys (up, down, left, and right). Here is a sample class you can start from. Note, the arrow keys are "coded" keys. See https://processing.org/reference/keyCode.html To use them, you will need to write something like this in your main program file:

void keyPressed () {
  //check to see if the input key is a "coded" key
  if (key == CODED) {
    //if the inputKey is the right pointing arrow
    if (inputKey == RIGHT) {
      //do something to move your vehicle to the right
    }
    //check to see if the key is one of the other arrow keys
    //move the vehicle appropriately
  }
}

Requirements

Your project should include all of the elements below.

  • The screen should be at least 500 pixels by 500 pixels. The dimensions can vary depending upon your program, but make sure that it is not "small".
  • Create a nice background for your vehicle to move around in.
  • Create a vehicle class as described above. Start from this sample class code
  • The vehicle should consist of at least 5 primitive shapes (ie: ellipses, rectangles, etc.) and lines.
  • Your vehicle should be controlled using the up, down, left, and right arrow keys.
  • Include the appropriate source code header.
  • Carefully read and follow the course Style Guidelines.
  • Extra credit #1: 5 points will be awarded to especially creative vehicles and backgrounds.
  • Extra credit #2 (5 points): Your program should prevent your vehicle from moving off of the screen. If you hit the edge of the screen, the vehicle should appear on the other side of the screen. That is, if it moves off of the right side of the screen it should reappear on the left side. If it moves off of the bottom of the screen it should reappear on the top.
  • Extra credit #3 (5 points): Add an instance variable called vehicleSize. Add a new constructor that allows you to create vehicles of different sizes. Add a method that allows you to change the size of a vehicle that has already been created.

What to Hand in:

  1. Your program. Browse to the folder containing your code files. Compress the folder into a .zip file and upload this to Learn. If you do not know how to create .zip files, check out these instructions for PC and mac OS.
  2. A paragraph about your project. In Learn, also submit a paragraph about your program and how you designed and implemented it. Include a brief discussion about your experience working on this assignment: what challenges did you encounter? how did you address them? what was hard? what did you learn?