在我继续我的问题之前,我只想说我对 Java 完全陌生,对它知之甚少,因为我在学校上 Java 课程,我想我喜欢这门语言,但老实说,我对 Java 感到沮丧上课的方式
所以我需要编写一个程序,将一首诗中的所有“你”替换为“我们”。这就是我提供的测试器类所拥有的。我知道这是错误的 我只是在猜测
替换.java
import java.io.FileInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class Replace {
String old_poem;
String new_poem;
//sets the name to OldPoem for the file with the original Poem
//sets the name to NewPoem for the file with the converted Poem
public Replace()
{
File inputFile = new File("OldPoem.txt");
String line = in.nextLine();
}
// replaces "you " with "we "
public void convert() throws FileNotFoundException
{
String newLine = line.replaceFirst("you", "we");
PrintWriter out = new PrintWriter("NewPoem.txt");
out.println(newLine);
}
//compares if the lines are the same in the new_poem file and in the correct file
//one line each time
public void same_as(String correct) throws FileNotFoundException
{
//stuck
enter code here
}
}
TextEditorTester.java
import java.io.FileNotFoundException;
public class TextEditorTester
{
private static boolean line_change;
public static void main(String[] args) throws FileNotFoundException
{
Replace poem=new Replace();
poem.convert();
poem.same_as("Kates.txt");
}
}