Click here to Skip to main content
15,896,493 members
Home / Discussions / Java
   

Java

 
QuestionPROCES TRASNFERRING FROM ONE CLIENT TO ANOTHER CLIENT Pin
madhump11-Oct-08 22:27
madhump11-Oct-08 22:27 
QuestionProcess tranferring from one client to another client Pin
madhump9-Oct-08 21:13
madhump9-Oct-08 21:13 
Questionadding new library to netbeans Pin
Areff8-Oct-08 12:42
Areff8-Oct-08 12:42 
QuestionConvert Fortran program to Java Pin
Trupti Mehta7-Oct-08 20:59
Trupti Mehta7-Oct-08 20:59 
AnswerRe: Convert Fortran program to Java Pin
toxcct8-Oct-08 1:03
toxcct8-Oct-08 1:03 
QuestionHelp to set apache tomcat 6.0 to netbeans Pin
hamid zamani7-Oct-08 2:12
hamid zamani7-Oct-08 2:12 
AnswerRe: Help to set apache tomcat 6.0 to netbeans Pin
Pedram Behroozi8-Oct-08 7:08
Pedram Behroozi8-Oct-08 7:08 
QuestionCode Optimization Pin
TannerB6-Oct-08 12:02
TannerB6-Oct-08 12:02 
I just finished writing this program, what it does is takes your name and assigns each letter a number and adds them up,
ie. Tanner would give you 27
The program then checks to see if the number is one or two digits, which in this case it is two (2 and 7)
It then adds those two digits together. Comments explain everything

What I would like input on is if anyone could give me a couple pointers on how to optimize my code, make it faster or take away some of the writing to reduce it's length

import javax.swing.*;

public class bruce_tanner_A2Q2
{
	public static void main (String [] args)
	{
		int firstNameTotal = 0;
		int secondNameTotal, thirdNameTotal;
		int currentLetter;

		String input = JOptionPane.showInputDialog("Numerology Calculator -\nEnter a Name");

		int inputLength = input.length(); //Checks how long the string is to be used as a maximum in the for loop

		//For loop which
		for(int i = 0;i < inputLength;i++)
		{
			currentLetter = (int)input.charAt(i) % 60; // Converts charAt's return into an integer, modulus 60 for less writing


			//Each if statement checks for uppercase and lowercase of each letter
			//A, J, S
			if (currentLetter == 5 || currentLetter == 14 || currentLetter == 23
			|| currentLetter == 37 || currentLetter == 46 || currentLetter == 55)
			{
				firstNameTotal++;
			}

			//B, K, T
			else if (currentLetter == 6 || currentLetter == 15 || currentLetter == 24
				 || currentLetter == 38 || currentLetter == 47 || currentLetter == 56)
			{
				firstNameTotal = firstNameTotal + 2;
			}

			//C, L, U
			else if (currentLetter == 7 || currentLetter == 16 || currentLetter == 25
				 ||	currentLetter == 39 || currentLetter == 48 || currentLetter == 57)
			{
				firstNameTotal = firstNameTotal + 3;
			}

			//D, M, V
			else if (currentLetter == 8 || currentLetter == 17 || currentLetter == 26
				 || currentLetter == 40 || currentLetter == 49 || currentLetter == 58)
			{
				firstNameTotal = firstNameTotal + 4;
			}

			//E, N, W
			else if (currentLetter == 9 || currentLetter == 18 || currentLetter == 27
				 || currentLetter == 41 || currentLetter == 50 || currentLetter == 59)
			{
				firstNameTotal = firstNameTotal + 5;
			}

			//F, O, X
			else if (currentLetter == 10 || currentLetter == 19 || currentLetter == 28
			 	  || currentLetter == 42 || currentLetter == 51 || currentLetter == 0)
			{
				firstNameTotal = firstNameTotal + 6;
			}

			//G, P, Y
			else if (currentLetter == 11 || currentLetter == 20 || currentLetter == 29
				  || currentLetter == 43 || currentLetter == 52 || currentLetter == 1)
			{
				firstNameTotal = firstNameTotal + 7;
			}

			//H, Q, Z
			else if (currentLetter == 12 || currentLetter == 21 || currentLetter == 30
				  || currentLetter == 44 || currentLetter == 53 || currentLetter == 2)
			{
				firstNameTotal = firstNameTotal + 8;
			}

			//I, R
			else if (currentLetter == 13 || currentLetter == 22 || currentLetter == 45
				  || currentLetter == 54)
			{
				firstNameTotal = firstNameTotal + 9;
			}
		}
		//secondNameTotal and thirdName total calculations will separate the digits and add them together
		//and do nothing if the digit is already less then 10
		//thirdNameTotal is a check just incase secondNameTotal is still over 10
		secondNameTotal = ((firstNameTotal % 10) + (firstNameTotal - (firstNameTotal % 10)) / 10);
		thirdNameTotal  = ((secondNameTotal % 10) + (secondNameTotal - (secondNameTotal % 10)) / 10);

		//Printing of results
		if(thirdNameTotal == 1)
			System.out.println(input + " (1) is ambitious, independent, and self-sufficient");
		if(thirdNameTotal == 2)
			System.out.println(input + " (2) is supportive, diplomatic, and analytical");
		if(thirdNameTotal == 3)
			System.out.println(input + " (3) is enthusiastic, optimistic, and fun-loving");
		if(thirdNameTotal == 4)
			System.out.println(input + " (4) is practical, traditional, and serious");
		if(thirdNameTotal == 5)
			System.out.println(input + " (5) is adventurous, mercurial, and sensual");
		if(thirdNameTotal == 6)
			System.out.println(input + " (6) is responsible, careful, and domestic");
		if(thirdNameTotal == 7)
			System.out.println(input + " (7) is spiritual, eccentric, and a bit of a loner");
		if(thirdNameTotal == 8)
			System.out.println(input + " (8) is money-oriented, decisive, and stern");
		if(thirdNameTotal == 9)
			System.out.println(input + " (9) is multi-talented, compassionate, and global");
	}
}

AnswerRe: Code Optimization Pin
toxcct6-Oct-08 21:26
toxcct6-Oct-08 21:26 
GeneralRe: Code Optimization Pin
TannerB7-Oct-08 7:04
TannerB7-Oct-08 7:04 
GeneralRe: Code Optimization Pin
toxcct7-Oct-08 7:11
toxcct7-Oct-08 7:11 
AnswerRe: Code Optimization Pin
douss7-Oct-08 23:19
douss7-Oct-08 23:19 
GeneralRe: Code Optimization Pin
toxcct8-Oct-08 0:34
toxcct8-Oct-08 0:34 
QuestionHelp with digest message using md5 algrothim Pin
omar el halwagy6-Oct-08 4:44
omar el halwagy6-Oct-08 4:44 
QuestionHow to debug MSJVM in Eclipse Pin
utnqbao6-Oct-08 0:50
professionalutnqbao6-Oct-08 0:50 
AnswerRe: How to debug MSJVM in Eclipse Pin
toxcct6-Oct-08 1:37
toxcct6-Oct-08 1:37 
GeneralRe: How to debug MSJVM in Eclipse Pin
utnqbao6-Oct-08 16:34
professionalutnqbao6-Oct-08 16:34 
GeneralRe: How to debug MSJVM in Eclipse Pin
utnqbao6-Oct-08 17:32
professionalutnqbao6-Oct-08 17:32 
QuestionDraw graph (networks) Pin
ventomito4-Oct-08 11:23
ventomito4-Oct-08 11:23 
AnswerRe: Draw graph (networks) Pin
douss7-Oct-08 23:38
douss7-Oct-08 23:38 
GeneralRe: Draw graph (networks) Pin
ventomito10-Oct-08 23:32
ventomito10-Oct-08 23:32 
Generaljava.util.List memory usage Pin
thrasher08154-Oct-08 10:55
thrasher08154-Oct-08 10:55 
Questionhow to close acceptandopen for streamconncetionnotifier Pin
manju23reddy2-Oct-08 18:16
manju23reddy2-Oct-08 18:16 
Questiontext twist game project help...... Pin
reanne_8830-Sep-08 21:20
reanne_8830-Sep-08 21:20 
AnswerRe: text twist game project help...... Pin
toxcct30-Sep-08 22:54
toxcct30-Sep-08 22:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.