CPSC-115 Fall 2008
Lab 5
September 30, October 1, 2008
Professor Heidi Ellis

Be sure that you hand in the printouts of your work before leaving!!!

Objective:

Pre-lab: The prelab for Lab 5 is to create a flowchart algorithm for the second program. Hand in the flowchart at the beginning of class.

This lab involves two programs. You must do both programs using the pairs assigned below.
Pair Programming:
  1. Locate your partner and introduce yourself:
  2. Tuesday Lab   Wednesday Lab
    Kristen AndersonNick Dragu  Chelsea Bainbridge-DonnerJohn Wilsterman
    Jake ElderJeff Young  Catherine DoyleGreg Vaughan
    Zain Khan   Jesse VazquezJin Feng Liu
        Corazon IrizarryRyan Ersland
  3. Select one person to start as "driver". This person will type at the keyboard for the first 20 mintues.
  4. Proceed through the process of completing the lab as described below. Be very careful to ensure that every item for both programs is completed.
  5. Swap pairs every 20 minutes.
  6. When you are done, be sure to email a copy of the code to the person whose account you are not working in. In other words, make sure that both partners have a copy of the code.

Program 1: Video Rental - Multiple Charges

The first program will again use the online video rental system where customers rent a number of movies per month including the rate plan option as in the second part of Lab 4. You must modify the program from Lab 4 in the following manner:
  1. Your program must use a while loop which allows information for multiple customers to be input and their corresponding charges to be calculated.
  2. Your program must keep track of the number of customers as well as the total amount of the charges.
  3. Your program should again display the information and charge for each customer.
  4. After the last customer has been entered, your program should display the total number of customers and the average charge per customer.
A sample test run is shown below:
Welcome to Rockin' Rental!
Enter customer name: Sam
Enter customer ID: P1234
Enter rate plan: A
Enter number of regular (non-recent releases) videos rented: 10
Enter number of recent release videos rented: 10

Customer name: Sam
Customer ID: P1234
Number of regular videos rented: 10
Number of recent releases rented: 10
Charge: $54.0

Enter customer name: Sally
Enter customer ID: U890
Enter rate plan: B
Enter number of regular (non-recent releases) videos rented: 2
Enter number of recent release videos rented: 3

You appear to enjoy recent releases. Please consider signing up for automatic notification of recent releases.

Customer name: Sally
Customer ID: U890
Number of regular videos rented: 2
Number of recent releases rented: 3
Charge: $30.0

Enter customer name: Fred
Enter customer ID: E98032
Enter rate plan: C
Enter number of regular (non-recent releases) videos rented: 12
Enter number of recent release videos rented: 23

You have rented over 20.0 videos this month and you are not a premium  member.
You should consider becoming a  premium member. You would save $7.0

You appear to enjoy recent releases. Please consider signing up for automatic notification of recent releases.

Customer name: Fred
Customer ID: E98032
Number of regular videos rented: 12
Number of recent releases rented: 23
Charge: $70.0

Enter customer name: exit

Total number of customers: 3
Average charge: $51.333333333333336
Test your code carefully to make sure that it operates correctly under a variety of test cases. Your code should have good programming style and follow all Java conventions. Don't forget to use constants where appropriate.

Program 2: Amino Acid Sequence Determination

Proteins are made up of long sequences of amino acids. There are only 20 known amino acids and scientists have developed a shorthand notation for identifying amino acids where each amino acid is represented by a single upper-case character. The table below shows the 20 amino acids and their identifiers:

Amino Acid NameSymbol Amino Acid NameSymbol
Alanine A LeucineL
ArginineR LysineK
AsparagineN MethionineM
Aspartic acidD PhenylalanineF
CysteineC ProlineP
Glutamic acidE SerineS
GlutamineQ ThreonineT
GlycineG TryptophanW
HistidineH TyrosineY
IsoleucineI ValineV


Therefore, a protein's structure can be represented as a string of these upper-case characters where each character represents the amino acid in the protein's sequence. For example:
ADQLTEEQIAEFKEAFSLFDKDGDGTITTKELGTVMRSLGQNPTEAELQDMI
NEVDADGNGTIDFPEFLTMMARKMKDTDSEEEIREAFRVFDKDGNGYISAAEL
RHVMTNLGEKLTDEEVDEMIREADIDGDGQVNYEEFVQMMTAK
A relatively common problem in protein structure determination is the identification of a certain sequence of amino acids within a protein. In fact, a sequence of amino acids may occur more than once within a protein. For example, in the following protein:
AKGAEDEKDFAETDVAEGDQV
The sequence AE appears three times:

AKGAEDEKDFAETDVAEGDQV

You must write a program that calculates the number of times that a sequence of amino acids occur within a protein. Your program should use strings of characters for both the protein and for the amino acid sequence. You will need to use a loop to step through each position in the protein and check to see if the sequence starts at that location within the protein. Note that the String class has a helpful method called regionMatches that returns a boolean if the provided string matches some part of the larger string. The format of the method is:

boolean regionMatches(startPositioninProtein, searchSequence, 0, lengthOfSearchSequence)
The snippet of code below shows how the method might be used. In the example below, the region being matched starts at the zeroeth position in the larger string and determines if there is a match for the character string AE starting at the zeroeth location of the substring AE and with a length of 2. The result of calling the regionMatches method is false since the first two characters of the string (starting a position zero) are AK.
currentPosition = 0;
"AKGAEDEKDFAETDVAEGDQV".regionMatches(currentPosition, "AE", 0, 2)
Note that you will have to modify the code above to use variables when you include it in your program. A sample run of the program might look like:
Enter the protein as a sequence of upper case characters:
ADQLTEEQIAEFKEAFSLFDKDGDGTITTKELGDKDTVMRSLGQDKDNPTEAELDKQDMI

Enter the search sequence, again as a sequence of 
upper case characters: DKD

The protein ADQLTEEQIAEFKEAFSLFDKDGDGTITTKELGDKDTVMRSLGQDKDNPTEAELDKQDMI 
has 3 matches with the amino acid chain: DKD
You're done!! Don't forget to log out and hand in your printouts to the professor before you leave!!