Java 在这种情况下,我如何拨打超级班级电话?
我正试图弄清楚在以下情况下如何进行超类调用 正如您将在下面看到的,我扩展的类的子类在其构造函数中只有一个参数,而超类有两个参数 下面是我的代码:Java 在这种情况下,我如何拨打超级班级电话?,java,superclass,super,Java,Superclass,Super,我正试图弄清楚在以下情况下如何进行超类调用 正如您将在下面看到的,我扩展的类的子类在其构造函数中只有一个参数,而超类有两个参数 下面是我的代码: import java.io.*; import java.util.*; public class DirectorySize extends DirectoryProcessor { /* Dan Czarnecki October 29, 2013
import java.io.*;
import java.util.*;
public class DirectorySize extends DirectoryProcessor
{
/*
Dan Czarnecki
October 29, 2013
Class variables:
private HashMap<File, DirectoryStatistics> directory
A HashMap object that will contain the files and folders
within a directory
Constructors:
public DirectorySize(File startingDirectory) throws FileNotFoundException
Creates a DirectorySize object, takes in a pathname (inherited from DirectoryProcessor class,
and has a single hashmap of a DirectoryStatistics object to hold the files and folders
within a directory
Methods:
public void processFile(File file)
A method that searches for all the files and folders
within a directory and calculated the total size
for each of them
public void run()
Calls the processFile() method and prints out
the files and folders (along with their sizes)
in the directory
public String toString()
Returns each element in the directory Vector
Modification History
October 29, 2013
Original version of class
Implemented run() and processFile() methods
October 30, 2013
Added implementation of FileFilter to processFile() method
*/
private HashMap<File, DirectoryStatistics> directory;
public DirectorySize(File startingDirectory) throws FileNotFoundException
{
super(startingDirectory);
directory = new HashMap <File, DirectoryStatistics>();
}
public void processFile(File file, FileFilter fileFilter) throws FileNotFoundException
{
DirectoryStatistics parent;
int index;
File parentFile;
boolean find;
parentFile = file.getParentFile();
parent = new DirectoryStatistics(parentFile);
find = directory.containsValue(parent);
if(find)
{
directory.put(parentFile, parent);
directory.get(parentFile).setSizeInBytes(file.length());
directory.get(parentFile).incrementFileCount();
}
if(find)
{
directory.get(find).addToSizeInBytes(file.length()); //increments the total size of the directory
directory.get(find).incrementFileCount(); //increments the number of files in the directory
}
}
public void run() throws FileNotFoundException
{
File file;
file = directoryLister.next();
while(file != null) //the following will be called when the File object is not null
{
processFile(file, fileFilter);
file = directoryLister.next();
}
}
public String toString()
{
Set<File> parentFile = directory.keySet();
File[] parentFileArray = parentFile.toArray(new File[0]);
String str; //creates a new string that will hold the file or directory name
str = "";
for(int i = 0; i < parentFileArray.length; i++)
{
str = str + directory.get(parentFileArray[i]).toString();
}
return str;
}
}
import java.io.*;
abstract public class DirectoryProcessor extends DirectoryLister
{
/*
Dan Czarnecki
October 14, 2013
Class variables:
private DirectoryLister directoryLister
A variable of type DirectoryLister that will list all the directories from a given pathname
Constructors:
public DirectoryProcessor(File startingDirectory) throws FileNotFoundException
Makes a super call to the startingDirectory variable, creates a new DirectoryLister object
Methods:
abstract public void processFile(File file, FileFilter fileFilter)
This abstract method's function is implemented in the TotalFileSize class to process each file within a directory and return the total size of them
public void run()
Basically takes the functionality what was originally done with our FileLister and DirectoryLister class (within the driver class)
but has now moved to its own method
Modification History:
October 14, 2013
Original version of class
October 16, 2013
Class and processFile() method have been made abstract
October 30, 2013
*/
public DirectoryLister directoryLister;
public FileFilter fileFilter;
public DirectoryProcessor(File startingDirectory, FileFilter fileFilter) throws FileNotFoundException
{
super(startingDirectory);
directoryLister = new DirectoryLister(startingDirectory);
fileFilter = this.fileFilter;
}
abstract public void processFile(File file, FileFilter fileFilter) throws FileNotFoundException;
public void run() throws FileNotFoundException
{
File file;
file = directoryLister.next();
while(file != null) //the following will be called when the File object is not null
{
processFile(file, fileFilter);
file = directoryLister.next();
}
}
}
import java.io.*;
导入java.util.*;
公共类DirectorySize扩展了DirectoryProcessor
{
/*
丹扎内基
2013年10月29日
类变量:
私有哈希映射目录
包含文件和文件夹的HashMap对象
在目录中
建造商:
public DirectorySize(File startingDirectory)引发FileNotFoundException
创建DirectorySize对象,接受路径名(从DirectoryProcessor类继承),
并且有一个DirectoryStatistics对象的hashmap来保存文件和文件夹
在目录中
方法:
公共void进程文件(文件文件)
搜索所有文件和文件夹的方法
并计算了总大小
对他们每个人来说
公开募捐
调用processFile()方法并打印输出
文件和文件夹(及其大小)
在目录中
公共字符串toString()
返回目录向量中的每个元素
修改历史
2013年10月29日
类的原始版本
实现了run()和processFile()方法
2013年10月30日
在processFile()方法中添加了FileFilter的实现
*/
私有HashMap目录;
public DirectorySize(File startingDirectory)引发FileNotFoundException
{
超级(启动目录);
directory=newhashmap();
}
public void processFile(File File,FileFilter FileFilter)引发FileNotFoundException
{
目录统计;
整数指数;
文件父文件;
布尔查找;
parentFile=file.getParentFile();
父项=新目录统计信息(父项文件);
find=directory.containsValue(父级);
如果(查找)
{
directory.put(parentFile,parent);
get(parentFile).setSizeInBytes(file.length());
directory.get(parentFile.incrementFileCount();
}
如果(查找)
{
directory.get(find).addToSizeInBytes(file.length());//增加目录的总大小
directory.get(find).incrementFileCount();//增加目录中的文件数
}
}
public void run()引发FileNotFoundException
{
文件;
file=directoryLister.next();
while(file!=null)//当file对象不为null时,将调用以下内容
{
processFile(文件,文件过滤器);
file=directoryLister.next();
}
}
公共字符串toString()
{
设置parentFile=directory.keySet();
文件[]parentFileArray=parentFile.toArray(新文件[0]);
String str;//创建一个新字符串,该字符串将保存文件或目录名
str=“”;
对于(int i=0;i
在这种情况下,如何进行超类调用?您的问题不清楚,但是如果您指的是在派生类构造函数中调用
super()
,那么您必须提供所需的两个参数。如果我理解正确,您是ref