The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
Java Linked List Error
Posted by: Manu Gupta | February 4, 2010 @ 1:02pm
Java Code
[
Download
]
import java.util.*; import java.io.*; class a1 { static LinkedList l1; private emp_struct input() throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); emp_struct obj = new emp_struct(); obj.emp_id = br.readLine(); obj.name = br.readLine(); obj.salary = Double.parseDouble(br.readLine()); obj.dept = br.readLine(); try{ search(obj); }catch(Exception e){ System.out.println(e); obj = input(); } return obj; } boolean search(emp_struct obj) { int lastIndex = l1.lastIndexOf(l1); int begIndex = 0; for(begIndex =0;begIndex<lastIndex;begIndex++) { Object chkCase = l1.get(begIndex); String chk = chkCase.getEmpID(); if(chk.equals(obj.emp_id)); throw new DuplicateEntryException("Duplicate entry found"); } return true; } public static void main(String args[]) throws IOException { l1 = new LinkedList(); } } class DuplicateEntryException extends Exception { String detail; DuplicateEntryException(String a) { detail = a; } public String toString() { return "User Defined Exception : "+detail; } } class emp_struct { public String emp_id; public String name; public double salary; public String dept; public String getEmpID() { return emp_id; } public String toString() { return emp_id+"\t"+name+"\t"+salary+"\t"+dept; } }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.53 / 8
57 Votes
http://codebin.yi.org/481
page generated in 0.00 seconds