Question: JAVA ILLUMINATED An Active Learning Approach. QUESTIONS. CHAPTER 7.18.6 62. Write a class encapsulating the concept of a file, assuming a file has only a
JAVA ILLUMINATED An Active Learning Approach.
QUESTIONS.
CHAPTER 7.18.6
62. Write a class encapsulating the concept of a file, assuming a file has only a single attribute: the name of the file. Include a constructor, the accessors and mutators, and methods toString and equals. Also, code a method returning the extension file (for instance, if the file name is Test.java, then the method should return java); if there is no dot(.) in the file name, then the method should return unknown extension. Write a client class to test all the methods in your class.
public class FileClient { public static void main( String [] args ) { File f1 = new File( "Test.java" ); File f2 = new File( "Test.class" ); System.out.println( "The name of file #1 is " + f1.getName( ) ); System.out.println( "File #2 is " + f2.toString( ) ); System.out.println( "The extension of file # 2 is " + f2.fileExtension( ) );
if ( f1.equals( f2 ) ) System.out.println( "Original files #1 and #2 are identical" ); else System.out.println( "Original files #1 and #2 are different" );
f2.setName( "Test.java" );
if ( f1.equals( f2 ) ) System.out.println( "Original file #1 and modified file #2 are identical" ); else System.out.println( "Original file #1 and modified file #2 are different" ); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
