| CSC 207 | Algorithms and Object Oriented Design | Spring 2009 |
Summary: In this lab, you will practice more with basic Java types, control structures, and static method calls.
cd somewhere/CSC207/labs/intro
Scanner type, described in Weiss
2.6.2. Its nextLine() method is very convenient.
lastname:firstname:assignment:grade
Doe:John:HW1:78 Doe:Jane:HW1:92 Doe:J:HW1:80
Grader, that prompts the user for the
name of a file, reads one line of the form above from the file,
segments the line into the four parts (last name, first name, name
of homework, and grade) and then prints the data in human-readable
form, such as
John Doe received a 78 on HW1.
indexOf to find the index of the
colon(s) and then substring to extract the
appropriate portion. More directly, you can use
the split method of the String class
with the colon as the (regular expression) string to split upon
matching.
alternatecharacters or sequences of characters are used in place of familiar alphabetics. For example, a plus sign (
+) is used in place of the letter t, a 3 in place of the
letter e, the numeral 1 in place of the letter l, and the numeral 0 in
place of the letter o. In some cases, multiple symbols are used in place
of a single letter, such as a vertical bar and a 3 in place of b or B.
or a vertical bar, a backslash, and a vertical bar in place of n.
Write a main class, DeLeet, which prompts the user for a
phrase in this odd language and attempts to return that phrase to its
English form. Here is a sample run of the program
Whassup? 3@+ |3@|\|@|\|@
I think you said 'eat banana'.
String class. (You can find the
Java API reference from the course home page.)
main method) that
contain methods other than main. These are
called static methods (we'll discuss what that means soon). For
now, it suffices to know that they have the same interpretation as the
functions you are used to in C (cf. Weiss 1.6).
MyUtils.java
int variables.
main method that tests your routine by printing
some examples.
main method to test your routine by
printing some eamples.
MyUtils class a static method that
takes a year as an integer parameter,
returning true if it is a leap
year, false
otherwise. (See Leap
year: Algorithm at Wikipedia.)
main method to test your routine by
printing some eamples.
double, computes the square of the square root of 2
and subtracts 2 from the result, printing the result to the screen.
(Henceforth you should use System.out to generate
output for the screen.)
Note that java.lang.Math.sqrt is useful for computing square roots.
double approximates real
numbers. One problem with approximation is that a sequence of
operations can lead to less and less good approximations.
In response to this problem, many programmers write code that
determines whether two values are approximately equal.
Write a program that prompts for and reads in two real numbers and
determines whether they are approximately equal. You may choose the
metric for approximate equality, but it should be a sensible metric.
You may wish to know about the method java.lang.Double.parseDouble.
Counter with a main method that takes
three integers as command-line arguments -- a starting value, an
ending value, and an increment -- and then prints all integers
starting with the starting value and ending just before or at
the ending value. For example,
java Counter 5 10 1would produce
Counting...
5 6 7 8 9 10
java Counter 5 12 3
Counting...
5 8 11
java.lang.Integer.parseInt.