我必须创建一个 EchoDouble 类来扩展 Echo 类,它将文本文件回显到控制台。
这个文本文件的内容是
Nature's first green is gold,
Her hardest hue to hold.
Her early leaf's a flower;
But only so an hour.
但我正在尝试编辑 EchoDouble 类中的 processLine 方法,以便它将像这样以双倍行距回显文本文件
Nature's first green is gold,
Her hardest hue to hold.
Her early leaf's a flower;
But only so an hour.
回声类
import java.util.Scanner;
import java.io.*;
public class Echo{
String fileName; // external file name
Scanner scan; // Scanner object for reading from external file
public Echo(String f) throws IOException
{
fileName = f;
scan = new Scanner(new FileReader(fileName));
}
// reads lines, hands each to processLine
public void readLines(){
while(scan.hasNext()){
processLine(scan.nextLine());
}
scan.close();
}
// does the real processing work
public void processLine(String line){
System.out.println(line);
}
}
EchoDouble 类
import java.io.*;
public class EchoDouble extends Echo
{
public EchoDouble (String datafile) throws IOException
{
super(datafile);
}
// Prints the given line and inserts a blank line
// Overrides the processLine method in Echo class
public void processLine(String line)
{
/* **code here** */
}
}
我是java中这个回声和扫描仪的新手,并且被困在这个问题上。如果有人可以就如何解决这个问题给我任何建议,将不胜感激!