SlideShare a Scribd company logo
Write a Java Class to Implement a Generic Linked List
Your list must be implemented as a singly-linked list of generic nodes, where each Node object
has two instance variables: an object of the “type variable” class, and a pointer to the next node
on the list.
Your class will contain separate methods to handle each of the operations read from a data file
(see II., below)
Your class will also override toString() to return the objects on the list in the order in which they
occur.
Write a Test Class for Your LinkedList Class
Your main method will read list operation instructions from a data file, until end-of-file and call
the appropriate LinkedList method to execute each one.
After each operation is executed, print out the operation and the updated list.
The data file to be used is on the class web site and the operations are:
APPEND X - Append object X to the end of the list
ADD N X - Insert object X as the new Nth element in the list, increasing the size of the list by 1
E.g. Suppose the list is:
head -> 1 -> 2 -> 3 -> 4->null
After ADD 3 7 it would be:
head -> 1 -> 2 -> 7 -> 3 -> 4->null
DELETE N – Remove the Nth object from the list
SWAP M N - Interchange the positions of the Mth and Nth
objects on the list
For credit, the two nodes must actually "trade places" in the list, and not merely swap their data
values
REVERSE - Reverse the order of the objects on the list
This must be done by reversing the order of the nodes themselves, rather than by swapping the
data stored
To get credit for your reverse() method, it must use either one of these 2 algorithms:
For each node on the list except the current “head”
node, delete the node and insert it as the new head
Use your swap() method
6. CLEAR – Clear the list (make it empty)
No credit will be given for programs that use any additional data structures – either from the Java
API or programmer defined -, other than your own LinkedList class
txt file:
Solution
//Java Program to Implement Singly Linked List
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/* Class Node */
class Nodes
{
protected Object data;
protected Nodes next;
/* Constructor */
public Nodes()
{
next = null;
data = null;
}
/* Constructor */
public Nodes(Object d,Nodes n)
{
data = d;
next = n;
}
/* Function to set link to next Node */
public void setLink(Nodes n)
{
next = n;
}
/* Function to set data to current Node */
public void setData(Object d)
{
data = d;
}
/* Function to get link to next node */
public Nodes getLink()
{
return next;
}
/* Function to get data from current Node */
public Object getData()
{
return data;
}
}
/* Class linkedList */
class linkList
{
protected Nodes start;
protected Nodes end ;
public int size ;
/* Constructor */
public linkList()
{
start = null;
end = null;
size = 0;
}
/* Function to check if list is empty */
public boolean isEmpty()
{
return start == null;
}
/* Function to get size of list */
public int getSize()
{
return size;
}
/* Function to insert an element at begining */
public void insertAtStart(int val)
{
Nodes nptr = new Nodes(val, null);
size++ ;
if(start == null)
{
start = nptr;
end = start;
}
else
{
nptr.setLink(start);
start = nptr;
}
}
/* Function to insert an element at end */
public void insertAtEnd(int val)
{
Nodes nptr = new Nodes(val,null);
size++ ;
if(start == null)
{
start = nptr;
end = start;
}
else
{
end.setLink(nptr);
end = nptr;
}
}
/* Function to insert an element at position */
public void insertAtPos(int val , int pos)
{
Nodes nptr = new Nodes(val, null);
Nodes ptr = start;
pos = pos - 1 ;
for (int i = 1; i < size; i++)
{
if (i == pos)
{
Nodes tmp = ptr.getLink() ;
ptr.setLink(nptr);
nptr.setLink(tmp);
break;
}
ptr = ptr.getLink();
}
size++ ;
}
/* Function to delete an element at position */
public void deleteAtPos(int pos)
{
if (pos == 1)
{
start = start.getLink();
size--;
return ;
}
if (pos == size)
{
Nodes s = start;
Nodes t = start;
while (s != end)
{
t = s;
s = s.getLink();
}
end = t;
end.setLink(null);
size --;
return;
}
Nodes ptr = start;
pos = pos - 1 ;
for (int i = 1; i < size - 1; i++)
{
if (i == pos)
{
Nodes tmp = ptr.getLink();
tmp = tmp.getLink();
ptr.setLink(tmp);
break;
}
ptr = ptr.getLink();
}
size-- ;
}
/* Function to display elements */
public void display()
{
System.out.print(" Singly Linked List = ");
if (size == 0)
{
System.out.print("empty ");
return;
}
if (start.getLink() == null)
{
System.out.println(start.getData() );
return;
}
Nodes ptr = start;
System.out.print(start.getData()+ "->");
ptr = start.getLink();
while (ptr.getLink() != null)
{
System.out.print(ptr.getData()+ "->");
ptr = ptr.getLink();
}
System.out.print(ptr.getData()+ " ");
}
public void reverse()
{
// For first node, previousNode will be null
Nodes previousNode=null;
Nodes nextNode;
while(start!=null)
{
nextNode=start.next;
// reversing the link
start.next=previousNode;
// moving currentNode and previousNode by 1 node
previousNode=start;
start=nextNode;
}
start=previousNode;
}
public void swapNodesP(int x,int y ){
if(start==null) return;
else{
Nodes n1=start,n2=start,n3=null;
for(int i=1;i");
}
}
/* Class SinglyLinkedList */
public class TestClass {
public static void main(String[] args)
{
String line=null;
/* Creating object of class linkedList */
linkList list = new linkList();
System.out.println("Singly Linked List Test ");
String s,fileName="c:/eclipse/operations.txt";
int i,j;
try{
BufferedReader br = new BufferedReader(new FileReader(fileName));
while((line = br.readLine()) != null) {
s=line.toString();
if(s.contains("APPEND"))
{
i=(int)Integer.parseInt(line.substring(7).toString().trim());
list.insertAtEnd(i );
list.display();
}
else if(s.contains("ADD")) {
i=(int)Integer.parseInt(line.substring(4,7).toString().trim());
j=(int)Integer.parseInt(line.substring(6,8).toString().trim());
list.insertAtPos(i,j);
list.display();
}
if(s.contains("DELETE")){
i=(int)Integer.parseInt(line.substring(7).toString().trim());
list.deleteAtPos(i);
list.display();
}
else if(s.contains("REVERSE")) {
list.reverse();
list.display();
}
else if(s.contains("SWAP")){
i=0;j=0;
i=(int)Integer.parseInt(line.substring(5,6).toString().trim());
j=(int)Integer.parseInt(line.substring(7,8).toString().trim());
list.swapNodesP(i,j);
list.display();
}
else if(s.contains("CLEAR")){
list.clear();
}
}
// Always close files.
br.close();
}
catch(FileNotFoundException ex) {
System.out.println(
"Unable to open file '" +
fileName + "'");
}
catch(IOException ex) {
System.out.println(
"Error reading file '"
+ fileName + "'");
}
}
}

More Related Content

Similar to Write a Java Class to Implement a Generic Linked ListYour list mus.pdf (20)

PDF
Objective The purpose of this exercise is to create a Linke.pdf
giriraj65
 
PDF
Given below is the completed implementation of MyLinkedList class. O.pdf
info430661
 
PDF
hi i have to write a java program involving link lists. i have a pro.pdf
archgeetsenterprises
 
PDF
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
QalandarBux2
 
DOCX
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
Komlin1
 
PDF
Note             Given Code modified as required and required met.pdf
Ankitchhabra28
 
PDF
Hi,I have added the methods and main class as per your requirement.pdf
annaelctronics
 
PDF
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
facevenky
 
PDF
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
arrowmobile
 
PDF
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
footstatus
 
PDF
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
mallik3000
 
PDF
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
fantasiatheoutofthef
 
PDF
The LinkedList1 class implements a Linked list. class.pdf
malavshah9013
 
PDF
In this assignment you will implement insert() method for a singly l.pdf
fantasiatheoutofthef
 
PDF
File LinkedList.java Defines a doubly-l.pdf
Conint29
 
PDF
please i need help Im writing a program to test the merge sort alg.pdf
ezonesolutions
 
PDF
import java-util--- public class MyLinkedList{ public static void.pdf
asarudheen07
 
PDF
Exception to indicate that Singly LinkedList is empty. .pdf
aravlitraders2012
 
PDF
Linked List Leetcode - Easy Collections - Interview Questions Java
Sunil Yadav
 
PDF
For each task, submit your source java code file.(1) Objective Im.pdf
dhavalbl38
 
Objective The purpose of this exercise is to create a Linke.pdf
giriraj65
 
Given below is the completed implementation of MyLinkedList class. O.pdf
info430661
 
hi i have to write a java program involving link lists. i have a pro.pdf
archgeetsenterprises
 
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
QalandarBux2
 
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
Komlin1
 
Note             Given Code modified as required and required met.pdf
Ankitchhabra28
 
Hi,I have added the methods and main class as per your requirement.pdf
annaelctronics
 
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
facevenky
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
arrowmobile
 
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
footstatus
 
PLEASE MAKE SURE THE PROGRAM IS ASKING FOR INPUT FROM USER TO ADD OR.pdf
mallik3000
 
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
fantasiatheoutofthef
 
The LinkedList1 class implements a Linked list. class.pdf
malavshah9013
 
In this assignment you will implement insert() method for a singly l.pdf
fantasiatheoutofthef
 
File LinkedList.java Defines a doubly-l.pdf
Conint29
 
please i need help Im writing a program to test the merge sort alg.pdf
ezonesolutions
 
import java-util--- public class MyLinkedList{ public static void.pdf
asarudheen07
 
Exception to indicate that Singly LinkedList is empty. .pdf
aravlitraders2012
 
Linked List Leetcode - Easy Collections - Interview Questions Java
Sunil Yadav
 
For each task, submit your source java code file.(1) Objective Im.pdf
dhavalbl38
 

More from rozakashif85 (20)

PDF
Give background information concerning EMT and include what is known.pdf
rozakashif85
 
PDF
Explain how the current economic recession differs from the depressio.pdf
rozakashif85
 
PDF
Does yeast uses CopI and CopII formation for vesicle budding to grow.pdf
rozakashif85
 
PDF
DNA molecules consist of chemically linked sequences of the bases ad.pdf
rozakashif85
 
PDF
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
rozakashif85
 
PDF
Count Red Nodes. Write a program that computes the percentage of red.pdf
rozakashif85
 
PDF
apple 2008 historically what were Apples major competitive advanta.pdf
rozakashif85
 
PDF
A partial results from a PERT analysis for a project with 50 activit.pdf
rozakashif85
 
PDF
briefly write about the variability of natural systems and the signi.pdf
rozakashif85
 
PDF
A graph is symmetric with respect to the vertical line corresponding.pdf
rozakashif85
 
PDF
X-Linked Recessive Write three rules to keep in mind when counseling .pdf
rozakashif85
 
PDF
Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
rozakashif85
 
PDF
Which of the following would you expect to happen in a plant that doe.pdf
rozakashif85
 
PDF
What is the value of including personal information about yourself a.pdf
rozakashif85
 
PDF
What is a voluntary response sampleSolutionVoluntary response.pdf
rozakashif85
 
PDF
What adaptive benefit do these abilities give wolbachia In oth.pdf
rozakashif85
 
PDF
Think about autumn (Fall season) in places like New England (Pennsyl.pdf
rozakashif85
 
PDF
The orange is which type of fruit Simple - Legume Simple - Drupe .pdf
rozakashif85
 
PDF
The _________ is the protective chamber that houses the ovule and Lat.pdf
rozakashif85
 
PDF
Suppose X follows a normal distribution with mean=1 and variance=4. .pdf
rozakashif85
 
Give background information concerning EMT and include what is known.pdf
rozakashif85
 
Explain how the current economic recession differs from the depressio.pdf
rozakashif85
 
Does yeast uses CopI and CopII formation for vesicle budding to grow.pdf
rozakashif85
 
DNA molecules consist of chemically linked sequences of the bases ad.pdf
rozakashif85
 
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
rozakashif85
 
Count Red Nodes. Write a program that computes the percentage of red.pdf
rozakashif85
 
apple 2008 historically what were Apples major competitive advanta.pdf
rozakashif85
 
A partial results from a PERT analysis for a project with 50 activit.pdf
rozakashif85
 
briefly write about the variability of natural systems and the signi.pdf
rozakashif85
 
A graph is symmetric with respect to the vertical line corresponding.pdf
rozakashif85
 
X-Linked Recessive Write three rules to keep in mind when counseling .pdf
rozakashif85
 
Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
rozakashif85
 
Which of the following would you expect to happen in a plant that doe.pdf
rozakashif85
 
What is the value of including personal information about yourself a.pdf
rozakashif85
 
What is a voluntary response sampleSolutionVoluntary response.pdf
rozakashif85
 
What adaptive benefit do these abilities give wolbachia In oth.pdf
rozakashif85
 
Think about autumn (Fall season) in places like New England (Pennsyl.pdf
rozakashif85
 
The orange is which type of fruit Simple - Legume Simple - Drupe .pdf
rozakashif85
 
The _________ is the protective chamber that houses the ovule and Lat.pdf
rozakashif85
 
Suppose X follows a normal distribution with mean=1 and variance=4. .pdf
rozakashif85
 
Ad

Recently uploaded (20)

PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
Dimensions of Societal Planning in Commonism
StefanMz
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Ad

Write a Java Class to Implement a Generic Linked ListYour list mus.pdf

  • 1. Write a Java Class to Implement a Generic Linked List Your list must be implemented as a singly-linked list of generic nodes, where each Node object has two instance variables: an object of the “type variable” class, and a pointer to the next node on the list. Your class will contain separate methods to handle each of the operations read from a data file (see II., below) Your class will also override toString() to return the objects on the list in the order in which they occur. Write a Test Class for Your LinkedList Class Your main method will read list operation instructions from a data file, until end-of-file and call the appropriate LinkedList method to execute each one. After each operation is executed, print out the operation and the updated list. The data file to be used is on the class web site and the operations are: APPEND X - Append object X to the end of the list ADD N X - Insert object X as the new Nth element in the list, increasing the size of the list by 1 E.g. Suppose the list is: head -> 1 -> 2 -> 3 -> 4->null After ADD 3 7 it would be: head -> 1 -> 2 -> 7 -> 3 -> 4->null DELETE N – Remove the Nth object from the list SWAP M N - Interchange the positions of the Mth and Nth objects on the list
  • 2. For credit, the two nodes must actually "trade places" in the list, and not merely swap their data values REVERSE - Reverse the order of the objects on the list This must be done by reversing the order of the nodes themselves, rather than by swapping the data stored To get credit for your reverse() method, it must use either one of these 2 algorithms: For each node on the list except the current “head” node, delete the node and insert it as the new head Use your swap() method 6. CLEAR – Clear the list (make it empty) No credit will be given for programs that use any additional data structures – either from the Java API or programmer defined -, other than your own LinkedList class txt file: Solution //Java Program to Implement Singly Linked List import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; /* Class Node */ class Nodes { protected Object data;
  • 3. protected Nodes next; /* Constructor */ public Nodes() { next = null; data = null; } /* Constructor */ public Nodes(Object d,Nodes n) { data = d; next = n; } /* Function to set link to next Node */ public void setLink(Nodes n) { next = n; } /* Function to set data to current Node */ public void setData(Object d) { data = d; } /* Function to get link to next node */ public Nodes getLink() { return next; } /* Function to get data from current Node */ public Object getData() { return data; } }
  • 4. /* Class linkedList */ class linkList { protected Nodes start; protected Nodes end ; public int size ; /* Constructor */ public linkList() { start = null; end = null; size = 0; } /* Function to check if list is empty */ public boolean isEmpty() { return start == null; } /* Function to get size of list */ public int getSize() { return size; } /* Function to insert an element at begining */ public void insertAtStart(int val) { Nodes nptr = new Nodes(val, null); size++ ; if(start == null) { start = nptr; end = start; } else
  • 5. { nptr.setLink(start); start = nptr; } } /* Function to insert an element at end */ public void insertAtEnd(int val) { Nodes nptr = new Nodes(val,null); size++ ; if(start == null) { start = nptr; end = start; } else { end.setLink(nptr); end = nptr; } } /* Function to insert an element at position */ public void insertAtPos(int val , int pos) { Nodes nptr = new Nodes(val, null); Nodes ptr = start; pos = pos - 1 ; for (int i = 1; i < size; i++) { if (i == pos) { Nodes tmp = ptr.getLink() ; ptr.setLink(nptr); nptr.setLink(tmp); break; }
  • 6. ptr = ptr.getLink(); } size++ ; } /* Function to delete an element at position */ public void deleteAtPos(int pos) { if (pos == 1) { start = start.getLink(); size--; return ; } if (pos == size) { Nodes s = start; Nodes t = start; while (s != end) { t = s; s = s.getLink(); } end = t; end.setLink(null); size --; return; } Nodes ptr = start; pos = pos - 1 ; for (int i = 1; i < size - 1; i++) { if (i == pos) { Nodes tmp = ptr.getLink(); tmp = tmp.getLink(); ptr.setLink(tmp);
  • 7. break; } ptr = ptr.getLink(); } size-- ; } /* Function to display elements */ public void display() { System.out.print(" Singly Linked List = "); if (size == 0) { System.out.print("empty "); return; } if (start.getLink() == null) { System.out.println(start.getData() ); return; } Nodes ptr = start; System.out.print(start.getData()+ "->"); ptr = start.getLink(); while (ptr.getLink() != null) { System.out.print(ptr.getData()+ "->"); ptr = ptr.getLink(); } System.out.print(ptr.getData()+ " "); } public void reverse() { // For first node, previousNode will be null Nodes previousNode=null; Nodes nextNode; while(start!=null)
  • 8. { nextNode=start.next; // reversing the link start.next=previousNode; // moving currentNode and previousNode by 1 node previousNode=start; start=nextNode; } start=previousNode; } public void swapNodesP(int x,int y ){ if(start==null) return; else{ Nodes n1=start,n2=start,n3=null; for(int i=1;i"); } } /* Class SinglyLinkedList */ public class TestClass { public static void main(String[] args) { String line=null; /* Creating object of class linkedList */ linkList list = new linkList(); System.out.println("Singly Linked List Test "); String s,fileName="c:/eclipse/operations.txt"; int i,j; try{ BufferedReader br = new BufferedReader(new FileReader(fileName)); while((line = br.readLine()) != null) { s=line.toString(); if(s.contains("APPEND"))
  • 9. { i=(int)Integer.parseInt(line.substring(7).toString().trim()); list.insertAtEnd(i ); list.display(); } else if(s.contains("ADD")) { i=(int)Integer.parseInt(line.substring(4,7).toString().trim()); j=(int)Integer.parseInt(line.substring(6,8).toString().trim()); list.insertAtPos(i,j); list.display(); } if(s.contains("DELETE")){ i=(int)Integer.parseInt(line.substring(7).toString().trim()); list.deleteAtPos(i); list.display(); } else if(s.contains("REVERSE")) { list.reverse(); list.display(); } else if(s.contains("SWAP")){ i=0;j=0; i=(int)Integer.parseInt(line.substring(5,6).toString().trim()); j=(int)Integer.parseInt(line.substring(7,8).toString().trim()); list.swapNodesP(i,j); list.display(); } else if(s.contains("CLEAR")){ list.clear(); } } // Always close files.
  • 10. br.close(); } catch(FileNotFoundException ex) { System.out.println( "Unable to open file '" + fileName + "'"); } catch(IOException ex) { System.out.println( "Error reading file '" + fileName + "'"); } } }