私は、ユーザーからの入力を受け入れる英語の翻訳プログラム(命題と論理式)に対する単純な論理式を持っています。左から右に文字列を読み込んでタスクを実行し、各文字に割り当てられたタスクを実行する方法は?
私の問題は、文字列がpで始まっていれば、命題 "p"が出力に表示され、次に次の内容をチェックするように論理式をチェックする方法がわからないことです。文字列であり、記号 "Λ"を使用したとすると、単語 "and"は次に表示されるはずです。
画像:
それが終了すると、私はどちらか解決するのか分からない1つのマイナーな問題は、任意のことを考えると、結果の翻訳の最初の文字を大文字にする方法であります3つの命題p、q、およびrは、ユーザが何を入力するかによって最初に来ることができる。
編集:私は
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Dmep extends JFrame implements ActionListener
{
JLabel Lp, Lq, Lr, Le, La;
JTextField Tp, Tq, Tr, Te, Ta;
JButton Bp, Bq, Br, Bnot, Band, Bor, Bxor, Bimp, Bico, Btl;
Font font = new Font ("Calibri", Font.BOLD, 24);
public Dmep()
{
Container C = getContentPane();
C.setLayout(new FlowLayout());
C.setBackground(Color.green);
Lp = new JLabel("Proposition p: ");
Lq = new JLabel("Proposition q: ");
Lr = new JLabel("Proposition r: ");
Le = new JLabel("Logical Expression: ");
La = new JLabel("English Trasnlation: ");
Tp = new JTextField("The window is open", 100);
Tq = new JTextField("the program is running", 100);
Tr = new JTextField("the translator will work", 100);
Te = new JTextField("pΛqΛr", 100);
Ta = new JTextField("The window is open and the program is running and the translator will work.", 100);
Bp = new JButton("p");
Bq = new JButton("q");
Br = new JButton("r");
Bnot = new JButton("¬");
Band = new JButton("Λ");
Bor = new JButton("V");
Bxor = new JButton("⊕");
Bimp = new JButton("→");
Bico = new JButton("↔");
Btl = new JButton("T R A N S L A T E");
C.add(Lp);
C.add(Tp);
C.add(Lq);
C.add(Tq);
C.add(Lr);
C.add(Tr);
C.add(Le);
C.add(Te);
C.add(La);
C.add(Ta);
C.add(Bp);
C.add(Bq);
C.add(Br);
C.add(Bnot);
C.add(Band);
C.add(Bor);
C.add(Bxor);
C.add(Bimp);
C.add(Bico);
C.add(Btl);
Bp.addActionListener(this);
Bq.addActionListener(this);
Br.addActionListener(this);
Bnot.addActionListener(this);
Band.addActionListener(this);
Bor.addActionListener(this);
Bxor.addActionListener(this);
Bimp.addActionListener(this);
Bico.addActionListener(this);
Btl.addActionListener(this);
Ta.setEditable(false);
setSize(1250,200);
setTitle("Logical Expression to English Translator");
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String pp, pq, pr, pa, pe;
pp = Tp.getText();
pq = Tq.getText();
pr = Tr.getText();
pe = Te.getText();
pa = pp + pq + pr;
if (e.getSource() == Bp)
{
Te.setText(String.valueOf(pe) + "p");
}
if (e.getSource() == Bq)
{
Te.setText(String.valueOf(pe) + "q");
}
if (e.getSource() == Br)
{
Te.setText(String.valueOf(pe) + "r");
}
if (e.getSource() == Bnot)
{
Te.setText(String.valueOf(pe) + "¬");
}
if (e.getSource() == Band)
{
Te.setText(String.valueOf(pe) + "Λ");
}
if (e.getSource() == Bor)
{
Te.setText(String.valueOf(pe) + "V");
}
if (e.getSource() == Bxor)
{
Te.setText(String.valueOf(pe) + "⊕");
}
if (e.getSource() == Bimp)
{
Te.setText(String.valueOf(pe) + "→");
}
if (e.getSource() == Bico)
{
Te.setText(String.valueOf(pe) + "↔");
}
if (e.getSource() == Btl)
{
Ta.setText(String.valueOf(pa) + "");
}
}
public static void main(String[] args)
{
Dmep M = new Dmep();
M.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
は、コードをポスト...私たちはあなたのロジックに従って何かを提案することができます/アルゴリズム –
編集にコードを掲載しました。 – sebagmi