Happy New Year! Let's write some code.
We're going to keep it a little easier today and just practice the basics again. Here's today's TODO list:
- Fork this project on Github
- Clone your fork using IntelliJ
- Create a
main
function - Print Hello World to the screen
- Create a
static
function calledadd
- The function should take in two
int
parameters - It should return the sum of the two parameters
- In your main function, create a variable called
sum
that stores anint
- In your main function, call
add
with the parameters 3 and 5, and store the output intosum
- The function should take in two
- In
MainTest
, create a new test method calledtestAdd
- In
testAdd
, runadd
with 2 and 4 as inputs, and assert that the output is 6 - In
testAdd
, runadd
with -3 and 7 as inputs, and assert that the output is 4
- In
- Create a function called
explode
- Create a new class called
FancyPrinter
- It should have an instance variable called
stringArr
that is aString
array - Create a constructor for
FancyPrinter
that takes in aString
- The constructor should split the string on spaces and store the split string into
stringArr
- The constructor should split the string on spaces and store the split string into
- Create a method called
print
that takes in no parameters- The method should print out each member of
stringArr
on its own line
- The method should print out each member of
- In your
main
function, create and store an instance ofFancyPrinter
, passing "I can code" into the constructor - In your
main
function, call theFancyPrinter
instance'sprint
method
- It should have an instance variable called
- Create a new class called
ClassyPrinter
ClassyPrinter
should inherit fromFancyPrinter
- Override the
print
function- The
print
function should print the contents ofstringArr
in reverse order
- The
- In your
main
function, create and store an instance ofClassyPrinter
, passing "I'm a pro" into the constructor - In your
main
function, call theClassyPrinter
instance'sprint
method - Create another
print
method that takes in aboolean
- If the parameter is
true
, call thesuper
class'sprint
method - If the parameter is
false
, call this class'sprint
method that takes in no parameters
- If the parameter is
- In your
main
function, callprint
from yourClassyPrinter
instance withtrue
as an input
- Pat yourself on the back. Good job.