Results 1 to 2 of 2
  1. #1
    SeanNYC is offline Member
    Join Date
    Oct 2011
    Posts
    1
    Rep Power
    0

    Post How to add characters that have integers stored in them

    Write a Java program that may be part of a game, scoring points for words. It should:
    1. Ask the user to type in a word, using a JOptionPane.showInputDialog().
    2. Look at each letter in the word and add up the points for each letter. The points for letters are:
    a. Vowels (a‟, e‟, i‟, o‟ and u‟) are valued at zero.
    b. The letters x‟ and q‟ are valued at 5.
    c. All other letters are valued at 1.
    d. Anything not a letter should be ignored.
    e. Upper case and lower case letters count the same.
    3. Using a JOptionPane.showMessageDialog(), display the word and the score.
    4. Repeat this process until the user types the word "Stop



    Java Code:
    import javax.swing.*;
    
    public class Project0 {
    	public static void main(String[] args) {
    
    	String insertWord;
    	int sum=0;
    	
    	// This line asks the user for input 
    	insertWord = JOptionPane.showInputDialog(null,"Type in a Word: " );
    	char a,A,e,E,I,i,O,o,U,u=0;
    	char x,X,q,Q=5;
    	char b,B,C,c,D,d,F,f,G,g,H,h,J,j,K,k,L,l,m,M,N,n,P,p,R,r,S,s,T,t,V,v,W,w,y,Y,Z,z=1;
    	//Count letters in word
    	for(int ia = 0; ia<insertWord.length(); ia++){
    			
    		if(Character.isLetter(insertWord.charAt(ia))) sum++;{
    			
    			}
    			
    		}
    			System.out.println("There are: " + sum + " sum");
     	}
    }
    This is what i have so far, it counts the letters inputed by the user instead of the stored number of the character, i need help fixing this problem thank you

  2. #2
    jammas615 is offline Senior Member
    Join Date
    Jul 2011
    Location
    Melbourne, Victoria, Australia
    Posts
    155
    Rep Power
    4

    Default Re: How to add characters that have integers stored in them

    Your code only counts the number of letters the user inputs, as you said. You want to test EACH letter and then depending on the letter, add 0,5 or 1 to 'sum'.

    Java Code:
    for(int ia = 0; ia<insertWord.length(); ia++){
    
    if (input == a ||e ||i ||o ||u)
            sum += 0;
    if (input == "x" ||"q")
            sum += 5;
    if input == a || b || c ||etc.)
            sum += 1;
    
    }

Similar Threads

  1. Replies: 16
    Last Post: 06-22-2011, 07:14 AM
  2. Convert integers into ACSII characters.
    By Valkyrie in forum New To Java
    Replies: 4
    Last Post: 11-24-2009, 02:39 AM
  3. stored procedure
    By sankarigopi in forum JDBC
    Replies: 1
    Last Post: 11-13-2008, 04:53 PM
  4. Stored Procedures
    By geeta_ravikanti in forum JDBC
    Replies: 1
    Last Post: 04-22-2008, 02:34 AM
  5. Replies: 1
    Last Post: 08-07-2007, 05:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •