Created
December 4, 2023 00:40
-
-
Save ojulianos/9295e5e7b15feff6c879fcbe5668ec4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class TrabProg { | |
// Verifica se a palavra termina com um sufixo de uma oxítona | |
public static boolean endsWithOx(String word) { | |
String[] oxSuffixes = {"a", "e", "o", "em", "as", "es", "os", "ens"}; | |
for (String suffix : oxSuffixes) { | |
if (word.endsWith(suffix)) { | |
return true; | |
} | |
} | |
return false; | |
} | |
// Verifica se a última sílaba contém um ditongo | |
public static boolean hasDit(String[] syllables) { | |
char[] vowels = {'a', 'e', 'i', 'o', 'u'}; | |
String lastSyllable = syllables[syllables.length - 1]; | |
int secondLastCharIndex = lastSyllable.length() - 2; | |
for (char vowel : vowels) { | |
if (lastSyllable.charAt(secondLastCharIndex) == vowel) { | |
return true; | |
} | |
} | |
return false; | |
} | |
// Verifica se a palavra é oxítona ou paroxítona e aplica as regras de acentuação | |
public static void checkOxOrParox(String word, int tonic) { | |
String[] syllables = word.split("-"); | |
boolean isOx = endsWithOx(word); | |
switch (tonic - 1) { | |
case 0: | |
System.out.println("A palavra é oxítona."); | |
if (isOx) { | |
System.out.println("Tem acento."); | |
} else { | |
System.out.println("Não tem acento."); | |
} | |
System.out.println("Todas as oxítonas terminadas em A(s), E(s), O(s), EM(ns) são acentuadas."); | |
System.out.println("Oxítonas não terminadas com esses prefixos não são acentuadas."); | |
break; | |
case 1: | |
System.out.println("A palavra é paroxítona."); | |
if (isOx) { | |
if (hasDit(syllables)) { | |
System.out.println("Tem acento."); | |
System.out.println("Todas as paroxítonas que possuem ditongos são acentuadas."); | |
} else { | |
System.out.println("Não tem acento."); | |
System.out.println("Exceção: O acento não ocorre quando o I ou U tônico formarem sílaba com as letras L, M, N, R ou z (EX: ruim) ou forem seguidos de nh (EX: rainha)."); | |
} | |
} else { | |
System.out.println("Tem acento."); | |
System.out.println("Todas as paroxítonas não terminadas em A(s), E(s), O(s), EM(ns) são acentuadas."); | |
} | |
break; | |
default: | |
System.out.println("Palavra sem acento."); | |
} | |
} | |
public static void main(String[] args) { | |
Scanner kBoard = new Scanner(System.in); | |
String keepGoing = "sim"; | |
while (keepGoing.equals("sim")) { | |
System.out.println("Digite uma palavra separada em sílabas: "); | |
String word = kBoard.next().toLowerCase(); | |
System.out.println("Numere a sílaba tônica da direita para a esquerda. Exemplo: Ca-fe tônica: Fe=1"); | |
int tonic = kBoard.nextInt(); | |
checkOxOrParox(word, tonic); // Verifica a classificação e regras de acentuação | |
System.out.print("Digite 'sim' para utilizar novamente: "); | |
keepGoing = kBoard.next().toLowerCase(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment