Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello I am working on a Pig Latin Java Program. I finished it up with zero probl

ID: 3763021 • Letter: H

Question

Hello I am working on a Pig Latin Java Program. I finished it up with zero problems, but need to make the program open a JPanel instead of asking the user for the information in the console and make the program allow the user to enter a short sentence, and display the Pig Latin translation of the entire sentence.

Please help!!!!

Current Program:

package piglatin;

import java.util.Scanner;
public class PigLatin
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
final String vowels = "aeiouAEIOU";
System.out.println("Enter your word.");
String word = sc.nextLine();
while (!word.equalsIgnoreCase("done"))
{
String beforVowel = "";
int cut = 0;
while (cut < word.length() && !vowels.contains("" + word.charAt(cut)))
{
beforVowel += word.charAt(cut);
cut++;
}
if (cut == 0)
{
cut = 1;
word += word.charAt(0) + "w";
}
System.out.println(word.substring(cut) + beforVowel + "ay");
System.out.println("Enter your word.");
word = sc.nextLine();
}
}
}

Explanation / Answer

You can use the below also for

first = word.charAt(0);
      if (first == 'a' || first == 'e' || first == 'i' || first == 'o' || first == 'u')
         pig = word + "hay";    
      else
         pig = word.substring(1) + word.charAt(0) + "ay";

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;


public class SwingContainer{
   private JFrame mainFrame;
   private JLabel headerLabel;
   private JLabel statusLabel;
   private JPanel controlPanel;
   private JLabel msglabel;
   private JTextField jt;

   public SwingContainer(){
      prepareGUI();
   }

   public static void main(String[] args){
      SwingContainer swingContainerDemo = new SwingContainer();
      swingContainerDemo.showJPanel();
   }

   private void prepareGUI(){
      mainFrame = new JFrame("Java Swing Examples");
      mainFrame.setSize(400,400);
      mainFrame.setLayout(new GridLayout(3, 1));
      mainFrame.addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent windowEvent){
            System.exit(0);
         }      
      });  
      headerLabel = new JLabel("", JLabel.CENTER);      
      statusLabel = new JLabel("",JLabel.CENTER);  

      statusLabel.setSize(350,100);

      msglabel = new JLabel("PigLatin Program", JLabel.CENTER);

      controlPanel = new JPanel();
      controlPanel.setLayout(new FlowLayout());


      mainFrame.add(headerLabel);
      mainFrame.add(controlPanel);
      mainFrame.add(statusLabel);
      mainFrame.setVisible(true);
      mainFrame.add(jt);
      Scanner sc = new Scanner(System.in);
final String vowels = "aeiouAEIOU";
System.out.println("Enter your word.");
String word = sc.nextLine();
while (!word.equalsIgnoreCase("done"))
{
String beforVowel = "";
int cut = 0;
while (cut < word.length() && !vowels.contains("" + word.charAt(cut)))
{
beforVowel += word.charAt(cut);
cut++;
}
if (cut == 0)
{
cut = 1;
word += word.charAt(0) + "w";
}
System.out.println(word.substring(cut) + beforVowel + "ay");
System.out.println("Enter your word.");
word = sc.nextLine();
}

   }

   private void showJPanel(){
      headerLabel.setText("Container in action: JPanel");    

      JPanel panel = new JPanel();
      panel.setBackground(Color.magenta);
      panel.setLayout(new FlowLayout());      
      panel.add(msglabel);

      controlPanel.add(panel);      
      mainFrame.setVisible(true);    
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote