SE1011
Class Exercises
Exercise 1: Packages
- Individually write an explanation for the purpose of a Java package.
- When you and your partner have both completed your answers, compare them and determine which answer you like better (and why).
- Write a new an improved answer together.
Exercise 2: Coding Conventions
- Individually write an explanation for the purpose of a coding convention.
- When you and your partner have both completed your answers, compare them and determine which answer you like better (and why).
- Write a new an improved answer together.
- List the main areas that the coding standards document addresses.
- List important coding conventions that you need to be aware of as you continue writing code this year.
Exercise 3: Random Numbers
Using documentation for the java.util.Random class write code to generate random numbers with the following characteristics:
- An integer value between 0 and 15 (including 0, but no including 15)
- An integer value between 5 and 10
- A double value between 0.0 and 1.0
- A double value between 0.0 and 100.0
- A double value between -100.0 and 100.0
Exercise 4 (optional): System.out.format
Using documentation for the java.io.PrintStream.format method and the format string syntax make use of System.out.format
to:
- Display "There are 8 chocolate bars each of the 5 bags" where the numbers are stored in integers,
numBars
andnumBags
. - Display "The COW JUMPED over the MOON" where the all caps words are stored in strings:
noun1
,verb
, andnoun2
. - Display "The 8 COWs JUMPED over the MOON" where the 8 is stored in an integer,
number
, and the all caps words are stored in strings:noun1
,verb
, andnoun2
. - Display PI with 5 significant digits.
- Display five integers (each on a separate line) so that they are right justified, e.g.,
13 1872 8238820 3 -73
- Display a table with a heading and three additional rows with the following format (assume all values come from variables):
Name Address ==== ======= John 123 8th St. Wendy 231 3rd Ave. Edwardo 321 Lethanderson Way
- Display five doubles (each on a separate line) so that they are right justified and have 3 places to the right of the decimal, e.g.,
100.135 -3.700 70003.888 23.456 3.142
Last modified: Friday, 30-Sep-2016 08:52:55 EDT