Back to Basics (Weeks 1–7)
You should be able to answer these questions correctly every time, without hesitation.
- Write statements to declare the following variables:
light: integerprimary: java.awt.Colorscores: array of integersnames: array of strings
- Write statements that assign a value to each variable from #1.
- Rewrite the code from #1 and #2 using one line for each variable.
- Rewrite the code to initialize
scoresandnameswith specific values of your choice. - Write statements to do the following:
- Declare and initialize a random
doublebetween 0 (inclusive) and 100 (exclusive). - Convert the random
doubleto an integer and assign the resulting value tolight.
- Declare and initialize a random
- Write the following loops:
- Print the word “Hello” 5 times.
- Print each character in a string variable named
message. - Double each value in an integer array named
ratings. - Print each object in a
List<String>namedgroceries.
- Write the following statements:
- Throw an
IllegalStateExceptionwith an error message of your choice. - Call a method named
surprise()and catch anIllegalStateException.
- Throw an
- Write all the code for a class named
Marker:- Attributes are
label(char) andposition(java.awt.Point). - Note:
java.awt.Pointcontains public attributesxandy. - default constructor, explicit value constructor, and (deep) copy constructor
- getters and setters, override
equals(), overridetoString()(with both attributes) - static method that creates and returns a
Listof 3Markerobjects of your choice.
- Attributes are