求大大编写一段java程序...万分感谢! 100
本人java0基础..最近在看视频自学,但是被要求要编以下这样一个程序,完全超出了我自学的进度...很快就要交了..实在没办法只能来这里求助了,希望有大神能帮忙,谢谢_(...
本人java 0基础..最近在看视频自学,但是被要求要编以下这样一个程序,完全超出了我自学的进度...很快就要交了..实在没办法只能来这里求助了,希望有大神能帮忙,谢谢_(:з」∠)_...
要求大致如下:
编写一个程序,形成一个”anagram puzzle“(字谜拼图)程序。”anagram“指由颠倒字母顺序而构成的字,一个能被其他词或短语中的字母转换或重组而形成的词或短语。例如,”CHARM“是”MARCH“的anagram,”CLINT EASTWOOD“是”OLD WEST ACTION“的anagram。 这个程序中只考虑单词的anagram。同时在制作这个拼图的内容中,anaram的定义是”一个单词能被一个字符串的字母转换形成(它可以是也可以不是一个单词)这个程序需要编的举例来说:
CHARM和MARCH都是字符串RMCHA的anagram。在这例子中RMCHA是一个anagram puzzle,然后MARCH和CHARM都是它的解决方案。所以更具体化来说这个程序的目标是:随机选择一些英语单词,并输出一个它的随机重排字母。
你需要一个单词列表文件,wordlist.txt或stateslist.txt,(这个我上传不了。。大致程序能编出意思就行了,谢谢)运行大型字典单词表,输入:
Java anagrampuzzlegenerator wordlist.txt
另外原题给了个可能是提示或者是例子的,如下:
class Echo {
public static void main(String[] args) throws FileNotFoundException {
Scanner in = new Scanner(new FileInputStream(args[0]));
int size = in.nextInt();//first item is the number of words
//while loop print out of words in file
int i = 0;
while ( i < size ) {
System.out.println(in.next());
i++;
}
}
}
能简单讲解一下最好,不苛求...关键只要能编出大致意思就行了,万分感谢_(:з」∠)_ 展开
要求大致如下:
编写一个程序,形成一个”anagram puzzle“(字谜拼图)程序。”anagram“指由颠倒字母顺序而构成的字,一个能被其他词或短语中的字母转换或重组而形成的词或短语。例如,”CHARM“是”MARCH“的anagram,”CLINT EASTWOOD“是”OLD WEST ACTION“的anagram。 这个程序中只考虑单词的anagram。同时在制作这个拼图的内容中,anaram的定义是”一个单词能被一个字符串的字母转换形成(它可以是也可以不是一个单词)这个程序需要编的举例来说:
CHARM和MARCH都是字符串RMCHA的anagram。在这例子中RMCHA是一个anagram puzzle,然后MARCH和CHARM都是它的解决方案。所以更具体化来说这个程序的目标是:随机选择一些英语单词,并输出一个它的随机重排字母。
你需要一个单词列表文件,wordlist.txt或stateslist.txt,(这个我上传不了。。大致程序能编出意思就行了,谢谢)运行大型字典单词表,输入:
Java anagrampuzzlegenerator wordlist.txt
另外原题给了个可能是提示或者是例子的,如下:
class Echo {
public static void main(String[] args) throws FileNotFoundException {
Scanner in = new Scanner(new FileInputStream(args[0]));
int size = in.nextInt();//first item is the number of words
//while loop print out of words in file
int i = 0;
while ( i < size ) {
System.out.println(in.next());
i++;
}
}
}
能简单讲解一下最好,不苛求...关键只要能编出大致意思就行了,万分感谢_(:з」∠)_ 展开
1个回答
展开全部
/* Anagram Game Application */
package com.toy.anagrams.ui;
import com.toy.anagrams.lib.WordLibrary;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.TextField;
import java.awt.Toolkit;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JRootPane;
/**
* Main window of the Anagram Game application.
*/
public class Anagrams{
public static void main(String[] args) {
new Anagrams(new JFrame("Test"));
}
private int wordIdx = 0;
private JRootPane rootPane;
public Anagrams(JFrame frame){
frame.setLayout(new BorderLayout());
initComponents();
frame.add(mainPanel);
scrambledWord.setText(WordLibrary.getScrambledWord(wordIdx));
guessedWord.requestFocusInWindow();
frame.setVisible(true);
}
/** Creates new form Anagrams */
public Anagrams() {
JFrame mainFrame = new JFrame("Anagrams");
rootPane = mainFrame.getRootPane();
initComponents();
getRootPane().setDefaultButton(guessButton);
scrambledWord.setText(WordLibrary.getScrambledWord(wordIdx));
mainFrame.pack();
guessedWord.requestFocusInWindow();
// Center in the screen
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = mainFrame.getSize();
mainFrame.setLocation(new Point((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.width) / 2));
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setVisible(true);
}
public Anagrams(JComponent topComponent){
initComponents();
topComponent.setLayout(new BorderLayout());
topComponent.add(mainPanel);
scrambledWord.setText(WordLibrary.getScrambledWord(wordIdx));
guessedWord.requestFocusInWindow();
}
private void setJMenuBar(JMenuBar menuBar){
rootPane.setJMenuBar(menuBar);
}
private JRootPane getRootPane(){
return rootPane;
}
private Container getContentPane(){
return getRootPane().getContentPane();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
mainPanel = new javax.swing.JPanel();
scrambledLabel = new javax.swing.JLabel();
scrambledWord = new javax.swing.JTextField();
guessLabel = new javax.swing.JLabel();
guessedWord = new javax.swing.JTextField();
feedbackLabel = new javax.swing.JLabel();
buttonsPanel = new javax.swing.JPanel();
guessButton = new javax.swing.JButton();
nextTrial = new javax.swing.JButton();
mainPanel.setLayout(new java.awt.GridBagLayout());
mainPanel.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(12, 12, 12, 12)));
mainPanel.setMinimumSize(new java.awt.Dimension(297, 200));
scrambledLabel.setText("Scrambled Word:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 6);
mainPanel.add(scrambledLabel, gridBagConstraints);
scrambledWord.setColumns(20);
scrambledWord.setEditable(false);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
mainPanel.add(scrambledWord, gridBagConstraints);
guessLabel.setDisplayedMnemonic('Y');
guessLabel.setLabelFor(guessedWord);
guessLabel.setText("Your Guess:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 20, 6);
mainPanel.add(guessLabel, gridBagConstraints);
guessedWord.setColumns(20);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 20, 0);
mainPanel.add(guessedWord, gridBagConstraints);
feedbackLabel.setText(" ");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 20, 0);
mainPanel.add(feedbackLabel, gridBagConstraints);
buttonsPanel.setLayout(new java.awt.GridBagLayout());
guessButton.setMnemonic('G');
guessButton.setText("Guess");
guessButton.setToolTipText("Guess the scrambled word.");
guessButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
guessedWordActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
buttonsPanel.add(guessButton, gridBagConstraints);
nextTrial.setMnemonic('N');
nextTrial.setText("New Word");
nextTrial.setToolTipText("Fetch a new word.");
nextTrial.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nextTrialActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
gridBagConstraints.weighty = 1.0;
buttonsPanel.add(nextTrial, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weighty = 1.0;
mainPanel.add(buttonsPanel, gridBagConstraints);
}
// </editor-fold>//GEN-END:initComponents
private void nextTrialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextTrialActionPerformed
wordIdx = (wordIdx + 1) % WordLibrary.getSize();
feedbackLabel.setText(" ");
scrambledWord.setText(WordLibrary.getScrambledWord(wordIdx));
guessedWord.setText("");
//getRootPane().setDefaultButton(guessButton);
guessedWord.requestFocusInWindow();
}//GEN-LAST:event_nextTrialActionPerformed
private void guessedWordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guessedWordActionPerformed
if (WordLibrary.isCorrect(wordIdx, guessedWord.getText())){
feedbackLabel.setText("Correct! Try a new word!");
//getRootPane().setDefaultButton(nextTrial);
} else {
feedbackLabel.setText("Incorrect! Try again!");
guessedWord.setText("");
}
guessedWord.requestFocusInWindow();
}//GEN-LAST:event_guessedWordActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel buttonsPanel;
private javax.swing.JLabel feedbackLabel;
private javax.swing.JButton guessButton;
private javax.swing.JLabel guessLabel;
private javax.swing.JTextField guessedWord;
private javax.swing.JPanel mainPanel;
private javax.swing.JButton nextTrial;
private javax.swing.JLabel scrambledLabel;
private javax.swing.JTextField scrambledWord;
// End of variables declaration//GEN-END:variables
}
请参考,记得采纳我
package com.toy.anagrams.ui;
import com.toy.anagrams.lib.WordLibrary;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.TextField;
import java.awt.Toolkit;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JRootPane;
/**
* Main window of the Anagram Game application.
*/
public class Anagrams{
public static void main(String[] args) {
new Anagrams(new JFrame("Test"));
}
private int wordIdx = 0;
private JRootPane rootPane;
public Anagrams(JFrame frame){
frame.setLayout(new BorderLayout());
initComponents();
frame.add(mainPanel);
scrambledWord.setText(WordLibrary.getScrambledWord(wordIdx));
guessedWord.requestFocusInWindow();
frame.setVisible(true);
}
/** Creates new form Anagrams */
public Anagrams() {
JFrame mainFrame = new JFrame("Anagrams");
rootPane = mainFrame.getRootPane();
initComponents();
getRootPane().setDefaultButton(guessButton);
scrambledWord.setText(WordLibrary.getScrambledWord(wordIdx));
mainFrame.pack();
guessedWord.requestFocusInWindow();
// Center in the screen
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = mainFrame.getSize();
mainFrame.setLocation(new Point((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.width) / 2));
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setVisible(true);
}
public Anagrams(JComponent topComponent){
initComponents();
topComponent.setLayout(new BorderLayout());
topComponent.add(mainPanel);
scrambledWord.setText(WordLibrary.getScrambledWord(wordIdx));
guessedWord.requestFocusInWindow();
}
private void setJMenuBar(JMenuBar menuBar){
rootPane.setJMenuBar(menuBar);
}
private JRootPane getRootPane(){
return rootPane;
}
private Container getContentPane(){
return getRootPane().getContentPane();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
mainPanel = new javax.swing.JPanel();
scrambledLabel = new javax.swing.JLabel();
scrambledWord = new javax.swing.JTextField();
guessLabel = new javax.swing.JLabel();
guessedWord = new javax.swing.JTextField();
feedbackLabel = new javax.swing.JLabel();
buttonsPanel = new javax.swing.JPanel();
guessButton = new javax.swing.JButton();
nextTrial = new javax.swing.JButton();
mainPanel.setLayout(new java.awt.GridBagLayout());
mainPanel.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(12, 12, 12, 12)));
mainPanel.setMinimumSize(new java.awt.Dimension(297, 200));
scrambledLabel.setText("Scrambled Word:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 6);
mainPanel.add(scrambledLabel, gridBagConstraints);
scrambledWord.setColumns(20);
scrambledWord.setEditable(false);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
mainPanel.add(scrambledWord, gridBagConstraints);
guessLabel.setDisplayedMnemonic('Y');
guessLabel.setLabelFor(guessedWord);
guessLabel.setText("Your Guess:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 20, 6);
mainPanel.add(guessLabel, gridBagConstraints);
guessedWord.setColumns(20);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 20, 0);
mainPanel.add(guessedWord, gridBagConstraints);
feedbackLabel.setText(" ");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 20, 0);
mainPanel.add(feedbackLabel, gridBagConstraints);
buttonsPanel.setLayout(new java.awt.GridBagLayout());
guessButton.setMnemonic('G');
guessButton.setText("Guess");
guessButton.setToolTipText("Guess the scrambled word.");
guessButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
guessedWordActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
buttonsPanel.add(guessButton, gridBagConstraints);
nextTrial.setMnemonic('N');
nextTrial.setText("New Word");
nextTrial.setToolTipText("Fetch a new word.");
nextTrial.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nextTrialActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
gridBagConstraints.weighty = 1.0;
buttonsPanel.add(nextTrial, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weighty = 1.0;
mainPanel.add(buttonsPanel, gridBagConstraints);
}
// </editor-fold>//GEN-END:initComponents
private void nextTrialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextTrialActionPerformed
wordIdx = (wordIdx + 1) % WordLibrary.getSize();
feedbackLabel.setText(" ");
scrambledWord.setText(WordLibrary.getScrambledWord(wordIdx));
guessedWord.setText("");
//getRootPane().setDefaultButton(guessButton);
guessedWord.requestFocusInWindow();
}//GEN-LAST:event_nextTrialActionPerformed
private void guessedWordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guessedWordActionPerformed
if (WordLibrary.isCorrect(wordIdx, guessedWord.getText())){
feedbackLabel.setText("Correct! Try a new word!");
//getRootPane().setDefaultButton(nextTrial);
} else {
feedbackLabel.setText("Incorrect! Try again!");
guessedWord.setText("");
}
guessedWord.requestFocusInWindow();
}//GEN-LAST:event_guessedWordActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel buttonsPanel;
private javax.swing.JLabel feedbackLabel;
private javax.swing.JButton guessButton;
private javax.swing.JLabel guessLabel;
private javax.swing.JTextField guessedWord;
private javax.swing.JPanel mainPanel;
private javax.swing.JButton nextTrial;
private javax.swing.JLabel scrambledLabel;
private javax.swing.JTextField scrambledWord;
// End of variables declaration//GEN-END:variables
}
请参考,记得采纳我
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |