我在一个项目中有三个文件,我似乎无法在我的主类打印中打印 println 语句!帮助?
第一个文件:
package chapter2;
public class UseStringLog
{
public static void main(String[] args)
{
StringLogInterface log;
log = new ArrayStringLog("Example Use");
log.insert("Elvis");
log.insert("King Louis XII");
log.insert("Captain Kirk");
System.out.println(log);
System.out.println("The size of the log is " + log.size());
System.out.println("Elvis is in the log: " + log.contains("Elvis"));
System.out.println("Santa is in the log: " + log.contains("Santa"));
}
}
第二个文件:
package chapter2;
public interface StringLogInterface
{
void insert(String element);
boolean isFull();
int size();
boolean contains(String element);
void clear();
String getName();
String toString();
}
第三个文件:
package chapter2;
public class ArrayStringLog implements StringLogInterface
{
protected String name;
protected String[] log;
protected int lastIndex = -1;
public ArrayStringLog(String name, int maxSize)
{
log = new String[maxSize];
this.name = name;
}
public ArrayStringLog(String name)
{
log = new String[100];
this.name = name;
}
public void insert(String element)
{
lastIndex++;
log[lastIndex] = element;
}
public boolean isFull()
{
if (lastIndex == (log.length - 1))
return true;
else
return false;
}
public int size()
{
return (lastIndex + 1);
}
public boolean contains(String element)
{
int location = 0;
while (location <= lastIndex)
{
if (element.equalsIgnoreCase(log[location])) // if they match
return true;
else
location++;
}
return false;
}
public void clear()
{
for (int i = 0; i <= lastIndex; i++)
log[i] = null;
lastIndex = -1;
}
public String getName()
{
return name;
}
public String toString()
{
String logString = "Log: " + name + "\n\n";
for (int i = 0; i <= lastIndex; i++)
logString = logString + (i+1) + ". " + log[i] + "\n";
return logString;
}
}
我运行每一个都成功构建,但没有输出!