Difference between revisions of "Numerology with Methods"

From CompSciWiki
Jump to: navigation, search
m
m
Line 53: Line 53:
 
         curr = upperName.charAt(r);
 
         curr = upperName.charAt(r);
  
    if (curr == 'A' || curr == 'J' || curr == 'S')
+
    if (curr == 'A' {{!}}{{!}} curr == 'J' {{!}}{{!}} curr == 'S')
 
sum += 1;
 
sum += 1;
    else if (curr == 'B' || curr == 'K' || curr == 'T')
+
    else if (curr == 'B' {{!}}{{!}} curr == 'K' {{!}}{{!}} curr == 'T')
 
sum += 2;
 
sum += 2;
    else if (curr == 'C' || curr == 'L' || curr == 'U')
+
    else if (curr == 'C' {{!}}{{!}} curr == 'L' {{!}}{{!}} curr == 'U')
 
sum += 3;
 
sum += 3;
    else if (curr == 'D' || curr == 'M' || curr == 'V')
+
    else if (curr == 'D' {{!}}{{!}} curr == 'M' {{!}}{{!}} curr == 'V')
 
sum += 4;
 
sum += 4;
    else if (curr == 'E' || curr == 'N' || curr == 'W')
+
    else if (curr == 'E' {{!}}{{!}} curr == 'N' {{!}}{{!}} curr == 'W')
 
sum += 5;
 
sum += 5;
    else if (curr == 'F' || curr == 'O' || curr == 'X')
+
    else if (curr == 'F' {{!}}{{!}} curr == 'O' {{!}}{{!}} curr == 'X')
 
sum += 6;
 
sum += 6;
    else if (curr == 'G' || curr == 'P' || curr == 'Y')
+
    else if (curr == 'G' {{!}}{{!}} curr == 'P' {{!}}{{!}} curr == 'Y')
 
sum += 7;
 
sum += 7;
    else if (curr == 'H' || curr == 'Q' || curr == 'Z')
+
    else if (curr == 'H' {{!}}{{!}} curr == 'Q' {{!}}{{!}} curr == 'Z')
 
sum += 8;
 
sum += 8;
    else if (curr == 'I' || curr == 'R')
+
    else if (curr == 'I' {{!}}{{!}} curr == 'R')
 
sum += 9;
 
sum += 9;
 
         }
 
         }

Revision as of 13:12, 3 April 2011

Back to the Case Studies homepage

Problem

Write 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)
corresponds to the name. So if name = “Alan Turing”, the method should return 45.


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,
then the method should return 7 (and not 16).


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

Wiki start01.jpg

Solution

Code

Solution Code

Back to the Case Studies homepage