cs101_mw113

Assignment 3

Contents

Due Dates

Part 1 Due Thursday, February 13, 2014 by 11 am in the Assignment3 Part1 link on Moodle
Parts 2--4 Due Thursday, February 20, 2014 by 11:59pm in your Sites/cs101/Assignment3 folder

Keep track of the amount of time that you spend on each part, then fill out the survey Assignment 3 feedback on Moodle once you have completed the entire assignment.

Submission checklist

  1. From the Students link on the left, find your username and click on the Assignment3 link
  2. Verify that you have two .html files:
    1. PrintBill.html
    2. PrintBillWithFreeShipping.html
  3. Both of the files above should show your bill generation Flash movies when clicked
  4. If you would like, you can rename one of the .html files to be index.html -- this will make the browser automatically show that file when the directory link (i.e., Assignment3) is clicked
  5. Be sure to have completed the ella survey entitled Assignment 3 feedback

REMEMBER: Do not edit your files after the submission, as I will judge submission time by the last modified time stamp! If you want to work further on any part, create a NEW folder named postsubmission within your cs101/Assignment3 folder and put your additional modifications within.

Resources

Goals

In this assignment, you will create a Flash application to create a bill for a purchase. Information about (1) the cost of the item, (2) the shipping zip code, and (3) the cost of shipping and handling are encoded in a purchase code, which is a String. You will learn about splitting a problem into smaller, reusable parts and how to use String functions to extract and decode this information and format it as a bill. Here is an example. Try adding the the following parameters to the Flash app below:

  • Item name: Great Expectations
  • Purchase code: 01002-ZALKJ83DJ2E3

Creating a Bill

Part 1: Planning the backend (25 points)

Part 1 Due Thursday, February 13, 2014 by 11:00 am in the Assignments link on Moodle. Bring a copy with you to class.

In this part, you will write pseudo code and design the functions that will carry out calculating and formatting the bill. We will not be programming until Part 2.

  • Write pseudo code for the following:
    To create a bill, first take an item name and its purchase code. From the purchase code, extract the cost of the item. To do this, find the index of the '-', then convert the next two characters to unicode. The item cost is the first character's unicode minus the second character's unicode. Next, extract the zip code -- the first five characters. Then extract the the shipping cost from the zip code -- the sum of the last two digits of the zip code. Compute the total bill as the item cost plus the shipping cost. Finally, format the bill to include the name of the purchased item, its cost, shipping and handling, to what zip code it is being shipped, and the total cost. Print the bill.
  • Rather than having one function to do all of this, break it up into smaller, more manageable pieces. You should be able to create at least five functions. Use what you learned from Lab 2: Designing Functions and Lab 3: Declaring and Using Functions and the String reference in the AS3 API.
    • For each function in your pseudo code, make a function signature, including:
      • parameter names and types
      • the return type
      • a comment above the function stating what it does, an constraints that exist for the parameters, and what is returned.

Type your refined pseudo code (just the final refinement is fine) and function signatures in a Word document or text/rtf file -- call it Assignment3PseudoCode.doc/txt/rtf -- and upload it in the Assignments link on Moodle CS101 by Thursday morning at 11 am.


SUGGESTED SOLUTIONS

Here are the function signatures we came up with. You can choose to use these or the ones you submitted, either is perfectly fine.

/**
 * Takes the name of a purchased item and its order code and
 * returns a bill as a string.
 **/
function getBill( itemName:String, orderCode:String ):String
 
 
/**
 * Creates a formatted bill given an item name, cost, the shipping cost, and the zip code
 * the item is being shipped to.
 **/
function createFormattedBill( itemName:String, itemCost:int, shippingCost:int, zipCode:String ):String
 
 
/**
 * Takes a zip code and extracts the shipping cost from it.
 **/
function getShippingCost( zipCode:String ):int
 
 
/**
 * Takes an order code and extracts the cost of the item without
 * shipping.
 **/
function getItemCost( orderCode:String ):int
 
 
/**
 * Takes an order code and extracts the zip code.
 **/
function getZipCode( orderCode:String ):String

Part 2: Programming the backend (30 points)

Parts 2--4 Due Thursday, February 20, 2014 by 11:59pm in your Sites/cs101/Assignment3 folder

You have refined pseudo code and a list of signatures from Part 1. Now you are going to take that pseudo code and declare and define the functions necessary to calculate and format a bill.

  • Create a new directory <your_username>/Sites/cs101/Assignment3.
    • Create a new ActionScript3 file named BillFunctions.as in the directory you just created.
    • Create a new Flash file named PrintBill.fla in the directory you just created..
  • Take the comments from your pseudo code and write the corresponding lines of AS3 code (function declarations and definitions go inside the BillFunctions.as file). Remember: I am expecting to see a comment for each line of code!
  • In PrintBill.fla, be sure to include your BillFunctions.as code.
    • Add code to test your function using the parameters:
      • Item name: Great Expectations
      • Purchase code: 01002-ZALKJ83DJ2E3
    • Print the bill using the trace function.

You will need to copy the intToString and stringToInt functions we used in Assignment 2 to your BillFunctions.as file:

/** 
 * This function takes a String parameter that consists 
 * only of digits (e.g., "3", "465", ...)
 * and converts it to the int value (e.g., 3, 465, ...). 
 * The int value is returned to the caller.
 **/
function stringToInt( s : String ) : int 
{
    // You should not understand this right now!
    return int( s );
}
 
/** 
 * This function takes an int parameter (e.g., 3, 465, ...)
 * and returns the String version of it (e.g., "3", "465", ...).
 * The String value is returned to the caller.
 **/
function intToString( i : int ) : String 
{
    // You should not understand this right now!
    return i.toString();
}

Part 3: The Graphical User Interface (GUI) (25 points)

Using the skills you learned in Assignment 2, create text fields for the inputs and output and a button to your PrintBill.fla file. There should be an input box for the item name and the purchase code. The output box should be large enough to see the entire bill.

  • Add code to the PrintBill.fla actions frame that will place a listener on the button.
  • Add a new function in BillFunctions.as that will be called by the listener above and create a bill using the contents of the input text boxes and sets the contents of the output text box to the bill text.
  • Publish your work (go to File->Publish)

Part 4: Free shipping (20 points)

In this part, we will see why making many small functions is so helpful. We will create a new Flash application that will be just like PrintBill.fla, except that the shipping cost will always be free.

  • Save your PrintBill.fla as a new Flash file in your cs101/Assignment3 directory named PrintBillWithFreeShipping.fla.
    • You should now have three files in your cs101/Assignment3 directory: PrintBill.fla, PrintBillWithFreeShipping.fla, and BillFunctions.as.
  • Add two new functions to your BillFunctions.as file:
    • One will be a new function that takes two parameters, the item name and purchase code, and creates a new bill where the cost of shipping is $0 Hint: this should look a lot like a function you wrote in Part 1.
    • The other will be similar to the function you called in PrintBill.fla, but it will instead call the function you just made in the step above.
  • Modify your action listener call in PrintBillWithFreeShipping.fla to reference the second function you made above.
  • Publish your work (go to File->Publish)

Here's an example of what it might look like:

Skin by RIL Partner