Help creating pronunciation program

i need help finishing an assignment, it includes getting input from the user and scanning each letter/character to see where it corresponds to with my if statements and printing out the pronunciation of the word in the console.

import javax.swing.JOptionPane;

String enterWord;

int i = 1+

void setup(){
  size(1000,550);
  background(200);
  noLoop();
}



  void draw(){

enterWord = JOptionPane.showInputDialog("Please enter a Hawaiian word, or quit to stop");

for (enterWord.charAt(i);){

if ( p ){

} else if (k){
  
} else if (h){

} else if (l){

} else if (m){

} else if (n){

} else if (w){
  
} else if (a){
    if(ai){
      println();
    } else if(ae){
      println();
    } else if(ao){
      println();
    }
} else if (e){
    if(ei){
      println();
    } else if(eu){
      println();
    }
} else if (i){
    if(iu){
      println();
    }
} else if (o){
    if(oi){
      println();
    } else if(ou){
      println();
    }
} else if (u){
    if(ui){
      println();
    }
}

}
1 Like

You are doing it a little wrong

use a normal for(int i=0; i<enterWord; i++) {

then if(enterWord.charAt(i)==‘p’) {…

Repeat for every if clause

(Just copy the expression)

great thanks, though i get this error on the console,

“The operator < is undefined for the argument type(s) int, String”

1 Like

for(int i=0; i<enterWord.length(); i++) {

My bad

2 Likes

sweet thanks got that but now this is what I have and im getting a constant error?

the error says

“Invalid character constant”

and its red underlined at

    } else if(enterWord.charAt(i)=='aw'){
      println("w");

 void draw(){

enterWord = JOptionPane.showInputDialog("Please enter a Hawaiian word, or quit to stop");

for(int i=0; i < enterWord.length(); i++)
  
  if(enterWord.charAt(i)=='p') {
  println("p");
} else if (enterWord.charAt(i)=='k'){
  println("k");
} else if (enterWord.charAt(i)=='h'){
  println("h");
} else if (enterWord.charAt(i)=='l'){
  println("l");
} else if (enterWord.charAt(i)=='m'){
  println("m");
} else if (enterWord.charAt(i)=='n'){
  println("n");
} else if (enterWord.charAt(i)=='p'){
  println("p");
  if(enterWord.charAt(i)=='w'){
      println("w");
    } else if(enterWord.charAt(i)=='aw'){
      println("w");
    } else if(enterWord.charAt(i)=='iw'){
      println("v");
    } else if(enterWord.charAt(i)=='ew'){
      println("v");
    } else if(enterWord.charAt(i)=='uw'){
      println("w");
    } else if(enterWord.charAt(i)=='ow'){
      println("w");
    }
} else if (enterWord.charAt(i)=='a'){
  println("ah");
    if(enterWord.charAt(i)=='ai'){
      println("eye");
    } else if(enterWord.charAt(i)=='ae'){
      println("eye");
    } else if(enterWord.charAt(i)=='ao'){
      println("ow");
    } else if(enterWord.charAt(i)=='au'){
      println("ow");
    }
} else if (enterWord.charAt(i)=='e'){
  println("eh");
    if(enterWord.charAt(i)=='ei'){
      println("ay");
    } else if(enterWord.charAt(i)=='eu'){
      println("eh-oo");
    }
} else if (enterWord.charAt(i)=='i'){
  println("ee");
    if(enterWord.charAt(i)=='iu'){
      println("ew");
    }
} else if (enterWord.charAt(i)=='o'){
  println("oh");
    if(enterWord.charAt(i)=='oi'){
      println("oy");
    } else if(enterWord.charAt(i)=='ou'){
      println("ow");
    }
} else if (enterWord.charAt(i)=='u'){
  println("oo");
    if(enterWord.charAt(i)=='ui'){
      println("ooey");
    }
}

}
1 Like

In this Method you check only one char not two

For checking two letters look at subString in the reference

ah i see but i want it to print the output based on what the user types in not a preset output

Nothing to do with this. Substring is just a way to look at two Strings

Or what do you mean?

I understand now.

It’s a little difficult though because sometimes you read 1 letter and sometimes 2. Totally logical but a bit harder for computers.

The approach we have now wouldn’t work now fully because of this. It would work when we would only use 1 letter.

Also hard because you check for ai and a alone (for example).

To solve this:

Don’t use for loop but while. Check first only two letter occurrences.

  • When you have a match set a boolean marker to true.

Increase i by 2 (!)

  • When you don’t have a match start checking for 1 letter occurrences. Increase i by 1.

Chrisir

1 Like

@Burgs – welcome to the forum! When you post, please help us help you by formatting your code with the </> button or by putting ``` above and below your code.

here is an example of the idea above



//https://discourse.processing.org/t/help-creating-pronunciation-program/18453

import javax.swing.JOptionPane;

String enterWord;

//int i = 1; 

void setup() {
  size(1000, 550);
  background(200);
  println("");
  noLoop();
}

void draw() {

  enterWord = JOptionPane.showInputDialog("Please enter a Hawaiian word, or quit to stop");

  int i=0;

  while ( i<enterWord.length()) {

    boolean marker=false; 

    if (i<enterWord.length()-3) {
      if (enterWord.substring(i, i+2).equals("ai")) {
        print("AI");
        marker=true;
        i += 2;
      }
    }

    // ----------------

    if (! marker) {
      // println ("here");  
      if (enterWord.charAt(i)=='u') {
        //
        println("U");
      }//if
      i++;
    }
  }//while
  //
  println("");
  //
}//func 
//
1 Like