Question

I need help doing all these questions (1-6) ASAP. Keep in mind we are only on chapter 5 of "Building Java Programs" so too advanced code cannot be used. Please use the appropriate code coved in the chapter and the chapters before. Thank you.Preview File Edit View Go Tools Window Help O 2.15?

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Answer 1:  PigLatin Words



import java.io.IOException;
import java.util.Scanner;

public class PigLatin {

    public static void main(String args[]) throws IOException
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter your sentence.");

        String word = sc.nextLine();// To read the input from the user.
        while (!word.trim().equalsIgnoreCase(""))
        {
            System.out.println("The Piglatin sentence = ");
            for(String s: word.split(" "))
            {
                convertStringToPigLatin(s);
                System.out.print(" ");
            }
            System.out.println();
            System.out.println("Enter your sentence.");
            word = sc.nextLine();
        }
        System.out.println("Exiting.....");
    }

    //This method converts the word into Pig latin word.
    private static void convertStringToPigLatin(String s)
    {
        int l=s.length(); // get the length of the word.
        int position=-1; //initialize the position and character

        for(int i=0; i<l; i++)
        {
            char ch =s.charAt(i);
            if(ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U' || ch=='a' || ch=='e' ||  ch=='i' || ch=='o' || ch=='u')
            {
                position=i; //storing the index of the first vowel
                break; // Since we got the first index we break from the iteration.
            }
        }

        if(position!=-1) //Condition to check if any vowel is present in the word. if  value is -1 then no vowels are present.
        {
            String a=s.substring(position); //extracting all alphabets in the word beginning from the 1st vowel
            String b=s.substring(0,position); //extracting the alphabets present before the first vowel
            String pig=a+"-"+b+"ay"; //adding "ay" at the end of the extracted words after joining them.
            System.out.print(pig);
        }
    }
}
Add a comment
Know the answer?
Add Answer to:
I need help doing all these questions (1-6) ASAP. Keep in mind we are only on...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I have to use java programs using netbeans. this course is introduction to java programming so...

    I have to use java programs using netbeans. this course is introduction to java programming so i have to write it in a simple way using till chapter 6 (arrays) you can use (loops , methods , arrays) You will implement a menu-based system for Hangman Game. Hangman is a popular game that allows one player to choose a word and another player to guess it one letter at a time. Implement your system to perform the following tasks: Design...

  • Hangman is a game for two or more players. One player thinks of a word, phrase...

    Hangman is a game for two or more players. One player thinks of a word, phrase or sentence and the other tries to guess it by suggesting letters or numbers, within a certain number of guesses. You have to implement this game for Single Player, Where Computer (Your Program) will display a word with all characters hidden, which the player needed to be guessed. You have to maintain a dictionary of Words. One word will be selected by your program....

  • How can I do this program complete with input validation so that the computer prompts the...

    How can I do this program complete with input validation so that the computer prompts the user to enter a number 0 through 100 if he/she guesses anything lower than 0, a floating point number, or other characters? And later, prompts the user to enter yes or no if he/she enters anything else when the program prompts the user to play again? Write a program that plays the Hi-Lo guessing game with numbers. The program should pick a random number...

  • Java 1) In a game of guessing numbers, one person says, “I’m thinking of a number...

    Java 1) In a game of guessing numbers, one person says, “I’m thinking of a number between 1 and 100.” The other person guesses “50.” The first person replies, “No, the number is less.” The second person then guesses “25,” and so on, until she guesses correctly. Write a program that plays this game. The computer knows the number (a random number between 1 and 100) and the user is the guesser. At the end of the game, the computer...

  • Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program...

    Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program 3 - Hangman Game Assignment purpose: User defined functions, character arrays, c style string member functions Write an interactive program that will allow a user to play the game of Hangman. You will need to: e You will use four character arrays: o one for the word to be guessed (solution) o one for the word in progress (starword) o one for all of...

  • Write the Java code for the class WordCruncher. Include the following members:

    **IN JAVAAssignment 10.1 [95 points]The WordCruncher classWrite the Java code for the class WordCruncher. Include the following members:A default constructor that sets the instance variable 'word' to the string "default".A parameterized constructor that accepts one String object as a parameter and stores it in the instance variable. The String must consist only of letters: no whitespace, digits, or punctuation. If the String parameter does not consist only of letters, set the instance variable to "default" instead. (This restriction will make...

  • Do in Python please provide screenshots aswell. Here are the requirements for your game: 1. The...

    Do in Python please provide screenshots aswell. Here are the requirements for your game: 1. The computer must select a word at random from the list of avail- able words that was provided in words.txt. The functions for loading the word list and selecting a random word have already been provided for you in ps3 hangman.py. 2. The game must be interactive; the flow of the game should go as follows: • At the start of the game, let the...

  • I need help with this assignment. Please include comments throughout the program. Thanks Develop an algorithm...

    I need help with this assignment. Please include comments throughout the program. Thanks Develop an algorithm and write the program in java for a simple game of guessing at a secret five-digit code. When the user enters a guess at the code, the program returns two values: the number of digits in the guess that are in the correct position and the sum of those digits. For example, if the secret code is 13720, and the user guesses 83521, the...

  • I need help with this. I need to create the hangman game using char arrays. I've...

    I need help with this. I need to create the hangman game using char arrays. I've been provided with the three following classes to complete it. I have no idea where to start. HELP!! 1. /** * This class contains all of the logic of the hangman game. * Carefully review the comments to see where you must insert * code. * */ public class HangmanGame { private final Integer MAX_GUESSES = 8; private static HangmanLexicon lexicon = new HangmanLexicon();...

  • Need help with this C program? I cannot get it to compile. I have to use...

    Need help with this C program? I cannot get it to compile. I have to use Microsoft Studio compiler for my course. It's a word game style program and I can't figure out where the issue is. \* Program *\ // Michael Paul Laessig, 07 / 17 / 2019. /*COP2220 Second Large Program (LargeProg2.c).*/ #define _CRT_SECURE_NO_DEPRECATE //Include the following libraries in the preprocessor directives: stdio.h, string.h, ctype.h #include <stdio.h> /*printf, scanf definitions*/ #include <string.h> /*stings definitions*/ #include <ctype.h> /*toupper, tolower...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT