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
mainfunction - Print Hello World to the screen
- Create a
staticfunction calledadd- The function should take in two
intparameters - It should return the sum of the two parameters
- In your main function, create a variable called
sumthat stores anint - In your main function, call
addwith 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, runaddwith 2 and 4 as inputs, and assert that the output is 6 - In
testAdd, runaddwith -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
stringArrthat is aStringarray - Create a constructor for
FancyPrinterthat 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
printthat takes in no parameters- The method should print out each member of
stringArron its own line
- The method should print out each member of
- In your
mainfunction, create and store an instance ofFancyPrinter, passing "I can code" into the constructor - In your
mainfunction, call theFancyPrinterinstance'sprintmethod
- It should have an instance variable called
- Create a new class called
ClassyPrinterClassyPrintershould inherit fromFancyPrinter- Override the
printfunction- The
printfunction should print the contents ofstringArrin reverse order
- The
- In your
mainfunction, create and store an instance ofClassyPrinter, passing "I'm a pro" into the constructor - In your
mainfunction, call theClassyPrinterinstance'sprintmethod - Create another
printmethod that takes in aboolean- If the parameter is
true, call thesuperclass'sprintmethod - If the parameter is
false, call this class'sprintmethod that takes in no parameters
- If the parameter is
- In your
mainfunction, callprintfrom yourClassyPrinterinstance withtrueas an input
- Pat yourself on the back. Good job.