Advanced Placement Computer Science Course Overview Course Policies Computer Science AP Syllabus Class Schedule Homework Labs Projects Extra Credit Study Material Grades Computer Science 2 AP Get Software Useful Resources Teacher Information |
Labs for Computer Science AP
Do problems 13.2 &
13.3. To do this you NEED to read section 13.1. Note: it
defines the selection sort in the OPPOSITE order of how it was defined
in class. (both are valid definitions of the algorithm)
This is an individual lab and is worth 2 points.
Write a text editing
program.
Put more clearly, you need to write a GUI program that has
Hint: when you are outputting the text from the JTextArea to the file, use the print method, not the println method to avoid adding a extra line feed. If the user tries to open a file that does not exist or save to a file that does not exist, you should use JOptionPane to display an error message. Feel free to use existing code on THIS site as a template for a GUI program. To be done individually and is worth 8 points
Define an interface called Hero
that requires all classes that implement it to define a method called
destroyenemy that takes no parameter and has a return type of
void. It should also have a constant value called MaxScore that
is set to 30
In a seperate class, implement the interface you defined above, declare an instance integer to track the score and implement a destroyenemy method that increases the score by one (but make sure that you do not exceed MaxScore) To be done individually on paper, and is worth 3 points.
Write a program that asks the
user what sort of data they want to enter into an array. (Prompt
them with something that says "Hit 1 for integers, 2 for Strings" and
then create an array of type Object of size 10. Read in 10
integers or 10 Strings into the Array. (depending on what the
user selected). Once you have it in the array, call the method
defined below with the name of the array as its parameter:
public static void sort(Comparable[] array) { Comparable temp; for (int b = array.length-1; b > 1; b--) { for (int a = 0; a < b; a++) { if (array[a].compareTo(array[a+1])> 0) { temp = array[a+1]; array[a+1] = array[a]; array[a] = temp; } } } } And after that print out the array elements one by one. (remember some are integers, and not Strings) Big tip: Remember, you can NOT directly put integers into Objects, you need to put them in a wrapper class first... (section 11.4) This is a partnered lab and worth 4 points.
Do book problems 11.6 & 11.7,
worth 3 points and this is a partnered lab.
Implementing the Comparable
interface (read 6.3 for information) implement a class that handles
fractions. (you should store the fractions as two instance
variables (integers), a numerator and a denominator). You need
the following methods in the code:
Any methods that Comparable
requires
public void setValues(int numeratorValue, int denominatorValue) a method that simply sets the
internal instance variables
public int getNumerator() a
method that returns the numerator
public int getDenominator() a method that returns
the denominator
public
void reduceFraction()
a method that will try to
simplify the fraction as much as it can. (eg: make 6/3 into 2/1
or 12/8 into 3/2) Just try to find the biggest number that
divides into both numbers without leaving a remainder.
Hint: you might want to try to find the GCD by counting up from 1 until the number is bigger than the denominator or the numerator. While counting, see if the number divides into both the denominator and numerator without leaving a remainder. (hint: %) The last number that you find that evenly divides into both is what you want to divide the numerator and the denominator. For the sake of comparing one
fraction to another, you probably want to convert the values of it to a
double. (ie: actually divide the numerator by the denominator and
store it in a double in that method) You can also assume that the
Object parameter in the method Comparable requires MUST be of type
Fraction. (you still need to cast it though)
This is a partnered lab and worth 4 points.
Do the problems here
on paper. This is an
individual lab, and worth 4 points.
Write a program that opens a file
the user selects and prints out the number of lines that exist in the
file. This is a partnered lab and worth 3 points.
Revise the Tic Tac Toe project (a
functional copy of the full project's code is here)
so that it has appropriate try/catch clauses for all of the places the
program could reasonably generate exceptions. Make certain the program
recovers from every exception that it reasonably can. (if the
user types a blank into a JOptionPane, you should be able to recover
and prompt the user for another input)
This is a partnered lab and worth 4 points. last
updated on 4/5/04
Copyright (C) 2004 Jim Casaburi |