Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class encapsulating the concept of a file, assuming file has a single at

ID: 3565615 • Letter: W

Question

Write a class encapsulating the concept of a file, assuming file has a single attribute: the name of the file. Include a constructor, the accessors, and the methods toString, and equals. Also, code a method returning the extension of the file. For example if the filename is text.java, the method will return java. If the file name does not include a dot, the method should return "unknown extension." Write a client class to test all the methods in the class. Also, write comments on class definition and class members in Javadoc format. There needs to be 3 files: .java and .class files of the class, and .java of the client program. Thanks!

Explanation / Answer

import java.util.*;
class MyFile {
private String name;
public MyFile(String mf){
this.name =mf;
}
public static void main(String[] args) {
// TODO code application logic here
MyFile myfile = new MyFile("text.java");
System.out.println(myfile.getFileExtension)

}
public String getName()
{
return this.name;
}
public void setName(String n)
{
this.name = n;
}
public String toString()
{
return "file name :" + getName();
}
public String getFileExtension()
{
int d = getName().indexOf(".");
if (d>0)
{
return getName().substring(d,getName().length()...
}
else{
return "unknown extension";


}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote