Difference between revisions of "Numerology with Methods"
Line 29: | Line 29: | ||
This method should print the final message of the program. The magicNumber is between 1 and 9. | This method should print the final message of the program. The magicNumber is between 1 and 9. | ||
</p> | </p> | ||
− | |||
<br> | <br> | ||
<p>Remember to follow [http://courses.cs.umanitoba.ca/index.asp?sec=3394&too=30&eve=1&ppa=5178 COMP 1010 coding standards].</p> | <p>Remember to follow [http://courses.cs.umanitoba.ca/index.asp?sec=3394&too=30&eve=1&ppa=5178 COMP 1010 coding standards].</p> | ||
Line 40: | Line 39: | ||
<p>Here are steps you can follow:</p> | <p>Here are steps you can follow:</p> | ||
<ul> | <ul> | ||
− | <li>Make sure you understand the problem | + | <li>Make sure you understand the problem</li> |
− | <li>List exactly what the problem is asking you to do | + | <li>List exactly what the problem is asking you to do</li> |
− | <li>Determine the logic for each item | + | <li>Determine the logic for each item</li> |
− | <li>Organize the code | + | <li>Organize the code</li> |
− | <li>Type the rest of the code | + | <li>Type the rest of the code</li> |
</ul> | </ul> | ||
<br> | <br> | ||
+ | |||
+ | |||
+ | ==Step 1: Make Sure You Understand The Problem== | ||
<p> | <p> | ||
+ | This step is important. You definitely want to avoid a situation where you have been working on an assignment for 3 days and suddenly find out you misinterpreted the question. | ||
+ | </p> | ||
+ | <br> | ||
+ | ===The Problem=== | ||
+ | <p> | ||
+ | In this case, the problem is to re-write the Numerology solution to use methods. What is the actual problem? According to the Numerology problem your task is to convert a name into an integer using the pseudo-mathematics of numerology. | ||
+ | </p> | ||
+ | <br> | ||
===What is a Method?=== | ===What is a Method?=== | ||
+ | <p> | ||
A <b>Method</b> is a section of code, similar to a sub procedure, which can be referred by name from anywhere in your program. The structure of an method includes a name, signature, and sometimes a return value. Methods benefit the programmer because time is saved from repeating sections of code by simply calling the method's name. Methods can be saved and used in other programs as well. | A <b>Method</b> is a section of code, similar to a sub procedure, which can be referred by name from anywhere in your program. The structure of an method includes a name, signature, and sometimes a return value. Methods benefit the programmer because time is saved from repeating sections of code by simply calling the method's name. Methods can be saved and used in other programs as well. | ||
</p> | </p> | ||
+ | |||
+ | |||
+ | ==Step 2: List Exactly What The Problem Is Asking To Do.== | ||
+ | ==Step 3: Determine The Logic For Each Item== | ||
+ | ==Step 4: Organize The Code.== | ||
+ | ==Step 5: Type The Rest Of The Code== | ||
|SolutionCode= | |SolutionCode= |
Revision as of 14:38, 3 April 2011
Back to the Case Studies homepage
ProblemWrite a complete Java program, similar to the problem Numerology in Case Studies Level Two. If you have not completed the previous problem click here to view problem details. Your goal is to rewrite the solution to use methods.
In particular, you should at least have methods with the following headers: 1. Calculate String Method public static int calculateString (String name) This method will accept the name as a String and return the int which directly (i.e., without further collapsing)
2. Collapse Integer Method public static int collapseInt (int currentValue) This method totally collapses the integer parameter currentValue to a single-digit number. So if currentValue = 88,
3. Print Message Method public static void printMessage (String name, int magicNumber) This method should print the final message of the program. The magicNumber is between 1 and 9.
Remember to follow COMP 1010 coding standards. |
Numerology with Methods | |
---|---|---|
SolutionI suggest you plan and create an outline on how to accomplish the solution before you code. An outline can benefit you in many ways. For example an outline can help you determine and layout the logic of your solution, variables, and methods. Additionally, you can find possible problems in the logic before writing the code. If an error exists or the code does not execute as expected, locating the problem in a few hundred lines of code is not always easy. If you know in advance what exactly you want to do, writing the code will be easier. Here are steps you can follow:
Step 1: Make Sure You Understand The ProblemThis step is important. You definitely want to avoid a situation where you have been working on an assignment for 3 days and suddenly find out you misinterpreted the question.
The ProblemIn this case, the problem is to re-write the Numerology solution to use methods. What is the actual problem? According to the Numerology problem your task is to convert a name into an integer using the pseudo-mathematics of numerology.
What is a Method?A Method is a section of code, similar to a sub procedure, which can be referred by name from anywhere in your program. The structure of an method includes a name, signature, and sometimes a return value. Methods benefit the programmer because time is saved from repeating sections of code by simply calling the method's name. Methods can be saved and used in other programs as well.
Step 2: List Exactly What The Problem Is Asking To Do.Step 3: Determine The Logic For Each ItemStep 4: Organize The Code.Step 5: Type The Rest Of The Code | ||
Code |