【发布时间】:2015-07-14 03:10:03
【问题描述】:
我是一个完整的java新手。如果你能帮助我,那就太好了。所以我需要编写一个程序来进行货币交易。 我的写法如下:
class program
{
public static void main (String[] param)throws IOException
{
intro();
System.exit(0);
}
public static void intro()throws IOException
{
PrintWriter x =new PrintWriter(new FileWriter("data.txt"));
while (true)
{
Object[] possibleValues = { "Transfer", "Receive", "Cancel"};
Object selectedValue = JOptionPane.showInputDialog(null,"Choose one", "Input",JOptionPane.INFORMATION_MESSAGE, null, possibleValues, possibleValues[0]);
String name;
String surname;
String amount;
String info;
if(selectedValue.equals(possibleValues[0]))
{
name = JOptionPane.showInputDialog(null, "recipients name");
surname = JOptionPane.showInputDialog(null, "recipients surname");
amount = JOptionPane.showInputDialog(null, "amount");
info = name+surname+amount;
x.println(info);
}
else if(selectedValue.equals(possibleValues[1]))
{
String inputname;
String inputsurname;
String inputamount;
inputname = JOptionPane.showInputDialog(null, "your name");
inputsurname = JOptionPane.showInputDialog(null, "your surname");
inputamount = JOptionPane.showInputDialog(null, "amount");
String inputinfo = inputname + inputsurname + inputamount;
if(x.contains.String(inputinfo))
{
JOptionPane.showMessageDialog(null,"you will recieve "+inputamount+"$");
}
else
{
JOptionPane.showMessageDialog(null,"request not found");
}
}
else if(selectedValue.equals(possibleValues[2]))
{
x.close();
System.exit(0);
}
}
}
}
一切似乎都在工作,除了:
If (x.contains.String(inputinfo))线
这个程序基本上应该做的是,当你进行交易时,它会记下你想给他们的人的名字和金额,并将其存储在 data.txt 中,当这个人想要收钱时,写下他的他应该收到的姓名和金额,如果该信息与存储在 data.txt 中的信息匹配,程序会告诉他们他们将收到金额,但如果不匹配,则程序会告诉他们请求没有没有找到。
程序在data.txt中存储名称和金额的部分有效;只有找到它的部分没有。 请帮忙。
【问题讨论】:
-
抛出任何错误?
-
如果你在解析.txt文件时遇到问题,最好不要编写转账程序!
-
约瑟夫·e。是的,错误:找不到符号 if(x.contains.String(inputinfo)) ^
-
isnot2bad,它不会处理实际货币,它只是一个假设
-
您无法使用 PrintWriter 读取文件,要将字符串与 txt 文件的内容进行比较,您应该使用 Scanner 或 FileReader 等将内容变红并进行比较