Starting from:
$30

$24

Assignment #1: Introduction to Programming Solution

Part 1 – Ascii Art




Write a set of methods that will output an ascii totem pole. Your implementation must include the three following static methods: printTotemPole, printFrog and printPig. You are free to introduce other methods if you would like but these three must be present and must be named EXACTLY as stated here.




Breaking down the steps




(see step 5 for what final output should look like)




Create a public class Welcome



Write the code for your class in your chosen editor
Save this file as Welcome.java



Compile this file in your terminal

javac Welcome.java
Repeat steps a through c until no errors are outputted to the console



Add a main method to your Welcome class in your editor



Add the main method



Add to your main method:
a println statement that prints Welcome followed by an empty line to the console

Compile in your terminal

javac Welcome.java



Run the program from your terminal

java Welcome
Repeat these steps until your output looks like the following…
Write and test the printPig method




Write the code for this static method
Call this static method from your main



Compile your program
Run your program
Repeat these steps until your output looks like the following…



Remove or comment out the call to this static method in your main method












Write and test the printFrog method



Write the code for this static method
Call this static method from your main
Compile your program



Run your program
Repeat these steps until your output looks like the following…
Remove or comment out the call to this static method in your main method



Write and test the printTotemPole method



Write the code for this static method

You will be calling the previous two methods you wrote



Don’t forget the spacer lines that are printed between each character!
Call this static method from your main
Compile your program



Run your program
Repeat these steps until your output looks like the following…









NOTE: these ascii art figures looks best when your terminal uses a Courier font (ie. monospaced). Each character is composed of characters that include the: period, equal sign, double quote, forwardslash, backslash, ^, ( , ), an underscore and more!




Part II – Math Calculations




Write a method to calculate the surface area of a cylinder given the height of the cylinder is 5m and the diameter is 4m (diagram shown below).














































Ensure you adhere to the method specifications described below:




Breaking down the steps




Write a method called calcSurfaceArea that will calculate and print out the surface area of the cylinder to the console. Your method should use the following algorithm.



Create 2 variables, one for height and set it to 5 and another for diameter and set it to 4.



Using the diameter and the value of Π, write a statement to calculate the circumference of the cylinder and store the result to a variable that you create.
Using the diameter and the value of Π, write a statement to calculate the area of the top of the cylinder and store the result to a variable.



Using the height and the circumference you calculated earlier, write a statement to calculate the area of the walls of the cylinder.
Using the 2 variables created above that are storing the area of the top and the area of the walls, write the lines of code to calculate the total surface area of the cylinder. Print the result to the console. Don’t forget – the cylinder has a top and a bottom J
Call this method from your main after you print your totem pole. Additional Notes:



There are other algorithms to calculate the surface area of a cylinder but we are asking you to follow this algorithm to give you practice with the creation and use of variables.
chose a primitive type for your variables carefully in order to get a precise answer…
for the value of Π, you are free to: hard code this value, create a constant for PI, use the PI constant in java’s Math library
chose the names of your variables carefully so they have meaning and make it easier for someone reading your code to understand what the code is doing



Challenge! Format your output so that only 2 decimal places are printed.



Write, compile and run your program until your output looks like that on the following page…
 
Grading:




Marks will be allocated for the following…




Your code must compile and run.



Your code should produce the output exactly as requested.
Your code must be indented and documented appropriately. Please follow the guidelines in Style_Guidelines.pdf, available in the Resources folder on conneX.

More products