![]() |
|
|
ObjectivesIn this lab, you will...
Pre-labVirtually all interesting programs must store collections of items. In this lab we will work on problems that store lists of items using the generic ArrayList class. Before coming to the lab review your notes on the ArrayList and Iterator classes and your notes on generic methods. In-lab ExercisesPart 1. Writing a generic methodLets assume that we're writing a program for the City of Vancouver Taxation Department. One of their requirements is that they can figure out the total taxes paid by a given list of properties. Property taxes are computed in different ways depending on the type of property: condominium, attached or detached. You have designed a Property class that has the following method: public abstract double getTaxes() You have also designed three subclasses of Property each of which provides an implementation of the abstract method getTaxes(): Condominium, Attached and Detached. Write a method that takes a list of properties as its only parameter and that returns the total annual taxes to be paid by the properties in the list. You must use an iterator to visit the items in the list - do not use the get() method of the ArrayList class. Note that your method must accept any of the following lists: ArrayList<Property> list1 = new ArrayList<Property>(); To get started:
Part 2. Determining if a Sequence is GC-richA DNA sequence represents 4 kinds of nucleotides that are denoted by the characters A, C, G and T. A sequence may be very long. For example, even the genome (i.e., the DNA) of a simple bacterium has more than a million nucleotides. Biologists sometimes want to know if an organism is GC-rich. To determine this information, the total number of Cs and Gs appearing in a sequence must be counted, and the percentage of the sequence that is a C or a G computed. Note that we are not looking for the nucleotide sequence "GC" but are simply interested in the number of Gs and Cs irrespective of their order. In this part of the lab, you will write code to report the percentage of a DNA sequence that is a G or a C nucleotide. To get started:
You should now have three files in the dna package:
The DNASequence and DNAApplication classes should compile and you should be able to run DNAApplication as a Java application. By default, the application simply reports the number of nucleotides in the SARS genome. (Note: The code works as provided, just don't touch this part of the code!) You must add a method to the DNASequence class to compute the
percentage of the sequence that is a G or a C and you must write out a line to standard
output of the form: Did you know? The Computer Science department offers Combined Majors programs with other Science departments. You can do a combined majors degree in Computer Science with Microbiology and Immunology for example. Unlike double majors degrees, these combined majors degrees can be completed in the usual four year period. If you are interested in knowing more about these options, see our website or make an appointment to see one of our advisors by e-mailing undergrad-info@cs.ubc.ca When you are finished, call over your TA and see if your solution is correct. (Note: We are not concerned with efficiency in this lab so we are willing to represent every nucleotide as a separate object in the DNA sequence even though this is not the most efficient way of proceeding.)
|
||
©University of British Columbia | Last updated:
October 25, 2007 10:07 |