Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.IOException;
- import java.util.Scanner;
- public class Chap5prob14_fileDISPLAY {
- //data members
- // are the basic characteristics of the object
- private String filename;
- //method members
- //are the functionalities of the object
- //constructors These methods create (instantiate) an instance of the object
- /**
- * Default constructor sets the filename to ""
- */
- public Chap5prob14_fileDISPLAY(){
- filename = "";
- }
- /**
- * full constructor sets the filename according to the parameters
- * @param filename is the filename
- */
- public Chap5prob14_fileDISPLAY(String filename){
- this.filename = filename;
- }
- //getters
- /**
- * this method returns the filename
- * @return the filename
- */
- public String getfilename(){
- return filename;
- }
- //setters
- /**
- * This method resets the filename according to the parameter
- * @param value will be set as the new value
- */
- public void setfilename( String value ) {
- this.filename = value;
- }
- //toString method
- public String toString(){
- String str;
- str = ("\tThe file name you entered is: " + filename);
- return str;
- }
- //all other object specific methods
- double lineCount = 0;
- public StringBuffer displayHead() throws IOException {
- File dataFile = new File(filename);
- Scanner input = new Scanner(dataFile);
- StringBuffer file = new StringBuffer("");
- while(input.hasNextLine() && lineCount <= 4){
- file.append(input.next() + "\n");
- lineCount++;
- }
- return file;
- }
- }//end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement